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