xref: /libCEED/examples/solids/Makefile (revision ccaff0309dc399f656ea11018b919b30feb8b0fa)
1*ccaff030SJeremy L Thompson# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2*ccaff030SJeremy L Thompson# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3*ccaff030SJeremy L Thompson# All Rights reserved. See files LICENSE and NOTICE for details.
4*ccaff030SJeremy L Thompson#
5*ccaff030SJeremy L Thompson# This file is part of CEED, a collection of benchmarks, miniapps, software
6*ccaff030SJeremy L Thompson# libraries and APIs for efficient high-order finite element and spectral
7*ccaff030SJeremy L Thompson# element discretizations for exascale applications. For more information and
8*ccaff030SJeremy L Thompson# source code availability see http://github.com/ceed.
9*ccaff030SJeremy L Thompson#
10*ccaff030SJeremy L Thompson# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11*ccaff030SJeremy L Thompson# a collaborative effort of two U.S. Department of Energy organizations (Office
12*ccaff030SJeremy L Thompson# of Science and the National Nuclear Security Administration) responsible for
13*ccaff030SJeremy L Thompson# the planning and preparation of a capable exascale ecosystem, including
14*ccaff030SJeremy L Thompson# software, applications, hardware, advanced system engineering and early
15*ccaff030SJeremy L Thompson# testbed platforms, in support of the nation's exascale computing imperative.
16*ccaff030SJeremy L Thompson
17*ccaff030SJeremy L Thompson# Note: PETSC_ARCH can be undefined or empty for installations which do not use
18*ccaff030SJeremy L Thompson#       PETSC_ARCH - for example when using PETSc installed through Spack.
19*ccaff030SJeremy L ThompsonPETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc
20*ccaff030SJeremy L ThompsonCEED_DIR ?= ../..
21*ccaff030SJeremy L Thompsonceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc
22*ccaff030SJeremy L Thompson
23*ccaff030SJeremy L ThompsonCC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc))
24*ccaff030SJeremy L ThompsonCFLAGS = -std=c99 \
25*ccaff030SJeremy L Thompson  $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \
26*ccaff030SJeremy L Thompson  $(call pkgconf, --variable=cflags_dep $(PETSc.pc)) \
27*ccaff030SJeremy L Thompson  $(call pkgconf, --cflags-only-other $(PETSc.pc)) \
28*ccaff030SJeremy L Thompson  $(OPT) -D__DIR__=\"$(dir $(abspath $(lastword $<)))\"
29*ccaff030SJeremy L ThompsonCPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc))
30*ccaff030SJeremy L ThompsonLDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc))
31*ccaff030SJeremy L ThompsonLDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc)))
32*ccaff030SJeremy L ThompsonLDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm
33*ccaff030SJeremy L Thompson
34*ccaff030SJeremy L ThompsonOBJDIR := build
35*ccaff030SJeremy L ThompsonSRCDIR := src
36*ccaff030SJeremy L Thompson
37*ccaff030SJeremy L Thompsonsrc.c := elasticity.c $(sort $(wildcard $(SRCDIR)/*.c))
38*ccaff030SJeremy L Thompsonsrc.o = $(src.c:%.c=$(OBJDIR)/%.o)
39*ccaff030SJeremy L Thompson
40*ccaff030SJeremy L Thompsonall: elasticity
41*ccaff030SJeremy L Thompson
42*ccaff030SJeremy L Thompsonelasticity: $(src.o) | $(PETSc.pc) $(ceed.pc)
43*ccaff030SJeremy L Thompson	$(call quiet,LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
44*ccaff030SJeremy L Thompson
45*ccaff030SJeremy L Thompson.SECONDEXPANSION: # to expand $$(@D)/.DIR
46*ccaff030SJeremy L Thompson%/.DIR :
47*ccaff030SJeremy L Thompson	@mkdir -p $(@D)
48*ccaff030SJeremy L Thompson	@touch $@
49*ccaff030SJeremy L Thompson
50*ccaff030SJeremy L Thompson# Output using the 216-color rules mode
51*ccaff030SJeremy L Thompsonrule_file = $(notdir $(1))
52*ccaff030SJeremy L Thompsonrule_path = $(patsubst %/,%,$(dir $(1)))
53*ccaff030SJeremy L Thompsonlast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
54*ccaff030SJeremy L Thompsonansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
55*ccaff030SJeremy L Thompsonemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
56*ccaff030SJeremy L Thompsoncolor_out = @if [ -t 1 ]; then \
57*ccaff030SJeremy L Thompson				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
58*ccaff030SJeremy L Thompson					$(1) $(call ansicolor,$(2)) \
59*ccaff030SJeremy L Thompson					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
60*ccaff030SJeremy L Thompson				printf "  %10s %s\n" $(1) $(2); fi
61*ccaff030SJeremy L Thompson# if TERM=dumb, use it, otherwise switch to the term one
62*ccaff030SJeremy L Thompsonoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
63*ccaff030SJeremy L Thompson
64*ccaff030SJeremy L Thompson# if V is set to non-nil, turn the verbose mode
65*ccaff030SJeremy L Thompsonquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
66*ccaff030SJeremy L Thompson
67*ccaff030SJeremy L Thompson$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
68*ccaff030SJeremy L Thompson	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
69*ccaff030SJeremy L Thompson
70*ccaff030SJeremy L Thompson# Rules for building the examples
71*ccaff030SJeremy L Thompson#%: %.c
72*ccaff030SJeremy L Thompson
73*ccaff030SJeremy L Thompsonprint: $(PETSc.pc) $(ceed.pc)
74*ccaff030SJeremy L Thompson	$(info CC      : $(CC))
75*ccaff030SJeremy L Thompson	$(info CFLAGS  : $(CFLAGS))
76*ccaff030SJeremy L Thompson	$(info CPPFLAGS: $(CPPFLAGS))
77*ccaff030SJeremy L Thompson	$(info LDFLAGS : $(LDFLAGS))
78*ccaff030SJeremy L Thompson	$(info LDLIBS  : $(LDLIBS))
79*ccaff030SJeremy L Thompson	@true
80*ccaff030SJeremy L Thompson
81*ccaff030SJeremy L Thompsonclean:
82*ccaff030SJeremy L Thompson	$(RM) -r $(OBJDIR) elasticity
83*ccaff030SJeremy L Thompson
84*ccaff030SJeremy L Thompson$(PETSc.pc):
85*ccaff030SJeremy L Thompson	$(if $(wildcard $@),,$(error \
86*ccaff030SJeremy L Thompson	  PETSc config not found at $@. Please set PETSC_DIR and PETSC_ARCH))
87*ccaff030SJeremy L Thompson
88*ccaff030SJeremy L Thompson.PHONY: all print clean
89*ccaff030SJeremy L Thompson
90*ccaff030SJeremy L Thompsonpkgconf = $(shell pkg-config $1 | sed -e 's/^"//g' -e 's/"$$//g')
91*ccaff030SJeremy L Thompson
92*ccaff030SJeremy L Thompson-include $(src.o:%.o=%.d)
93