xref: /libCEED/Makefile (revision 9c477bc0a02808c6542c4937b89842b703f82aa8)
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
17CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
18CFLAGS += $(if $(NDEBUG),-O2,-g)
19CPPFLAGS = -I.
20LDLIBS = -lm
21OBJDIR := build
22LIBDIR := .
23
24PROVE ?= prove
25DARWIN := $(filter Darwin,$(shell uname -s))
26SO_EXT := $(if $(DARWIN),dylib,so)
27
28libceed := $(LIBDIR)/libceed.$(SO_EXT)
29libceed.c := $(wildcard ceed*.c)
30tests.c   := $(sort $(wildcard tests/t[0-9][0-9]-*.c))
31tests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
32examples.c := $(sort $(wildcard examples/*.c))
33examples  := $(examples.c:examples/%.c=$(OBJDIR)/%)
34
35.SUFFIXES:
36.SUFFIXES: .c .o .d
37.SECONDEXPANSION:		# to expand $$(@D)/.DIR
38
39%/.DIR :
40	@mkdir -p $(@D)
41	@touch $@
42
43.PRECIOUS: %/.DIR
44
45$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o)
46	$(CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
47
48$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
49	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
50
51$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
52	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
53
54$(OBJDIR)/%.o : examples/%.c | $$(@D)/.DIR
55	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^
56
57$(tests) $(examples) : $(libceed)
58$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(LIBDIR) -L$(LIBDIR)
59$(OBJDIR)/t% : tests/t%.c $(libceed)
60$(OBJDIR)/ex% : examples/ex%.c $(libceed)
61
62run-t% : $(OBJDIR)/t%
63	@tests/tap.sh $(<:build/%=%)
64
65test : $(tests:$(OBJDIR)/t%=run-t%)
66
67prove : $(tests)
68	$(PROVE) --exec tests/tap.sh $(CEED_PROVE_OPTS) $(tests:$(OBJDIR)/%=%)
69
70examples : $(examples)
71
72.PHONY: clean print test examples astyle
73clean :
74	$(RM) *.o $(OBJDIR)/*.o *.d $(OBJDIR)/*.d $(libceed) $(tests.c:%.c=%)
75	$(RM) -r *.dSYM
76
77astyle :
78	astyle --style=google --indent=spaces=2 --max-code-length=80 \
79            --keep-one-line-statements --keep-one-line-blocks --lineend=linux \
80            --suffix=none --preserve-date --formatted \
81            *.[ch] tests/*.[ch] examples/*.[ch]
82
83
84print :
85	@echo $(VAR)=$($(VAR))
86
87print-%:
88	$(info [ variable name]: $*)
89	$(info [        origin]: $(origin $*))
90	$(info [         value]: $(value $*))
91	$(info [expanded value]: $($*))
92	$(info )
93	@true
94
95-include $(libceed.c:%.c=%.d) $(tests.c:%.c=%.d)
96