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