xref: /libCEED/Makefile (revision e86995fed66f2b28b1d61a81ea00b8a2fbe3d034)
1# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3# 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
17CC = gcc
18
19NDEBUG ?=
20LDFLAGS ?=
21
22SANTIZ = -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
23CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
24CFLAGS += $(if $(NDEBUG),,$(SANTIZ))
25CFLAGS += $(if $(NDEBUG),-O2,-g)
26LDFLAGS += $(if $(NDEBUG),,$(SANTIZ))
27CPPFLAGS = -I.
28LDLIBS = -lm
29OBJDIR := build
30LIBDIR := .
31NPROCS := $(shell getconf _NPROCESSORS_ONLN)
32MFLAGS := --no-print-directory -j $(NPROCS) --warn-undefined-variables
33
34PROVE ?= prove
35DARWIN := $(filter Darwin,$(shell uname -s))
36SO_EXT := $(if $(DARWIN),dylib,so)
37
38libceed := $(LIBDIR)/libceed.$(SO_EXT)
39libceed.c := $(wildcard ceed*.c)
40tests.c   := $(sort $(wildcard tests/t[0-9][0-9]-*.c))
41tests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
42examples.c := $(sort $(wildcard examples/*.c))
43examples  := $(examples.c:examples/%.c=$(OBJDIR)/%)
44
45.SUFFIXES:
46.SUFFIXES: .c .o .d
47.SECONDEXPANSION:		# to expand $$(@D)/.DIR
48
49%/.DIR :
50	@mkdir -p $(@D)
51	@touch $@
52
53.PRECIOUS: %/.DIR
54
55all dbg:;$(MAKE) $(MFLAGS) $(libceed)
56opt:;NDEBUG=1 $(MAKE) $(MFLAGS) $(libceed)
57
58$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o)
59	$(CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
60
61$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
62	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
63
64$(OBJDIR)/%.o : tests/%.c | $$(@D)/.DIR
65	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
66
67$(OBJDIR)/%.o : examples/%.c | $$(@D)/.DIR
68	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
69
70$(tests) $(examples) : $(libceed)
71$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(LIBDIR) -L$(LIBDIR)
72$(OBJDIR)/t% : tests/t%.c $(libceed)
73$(OBJDIR)/ex% : examples/ex%.c $(libceed)
74
75run-t% : $(OBJDIR)/t%
76	tests/tap.sh $(<:build/%=%)
77
78test : $(tests:$(OBJDIR)/t%=run-t%)
79tst:;@$(MAKE) $(MFLAGS) test
80
81prove : $(tests)
82	$(PROVE) --exec tests/tap.sh $(CEED_PROVE_OPTS) $(tests:$(OBJDIR)/%=%)
83
84examples : $(examples)
85
86.PHONY: clean print test examples astyle
87cln clean :
88	$(RM) *.o $(OBJDIR)/*.o *.d $(OBJDIR)/*.d $(libceed) $(tests.c:%.c=%)
89	$(RM) -r *.dSYM
90
91astyle :
92	astyle --style=google --indent=spaces=2 --max-code-length=80 \
93            --keep-one-line-statements --keep-one-line-blocks --lineend=linux \
94            --suffix=none --preserve-date --formatted \
95            *.[ch] tests/*.[ch] examples/*.[ch]
96
97
98print :
99	@echo $(VAR)=$($(VAR))
100
101print-%:
102	$(info [ variable name]: $*)
103	$(info [        origin]: $(origin $*))
104	$(info [         value]: $(value $*))
105	$(info [expanded value]: $($*))
106	$(info )
107	@true
108
109-include $(libceed.c:%.c=%.d) $(tests.c:%.c=%.d)
110