xref: /libCEED/Makefile (revision 32d74c32bc6dc8a774cc1c5f134fa766dfd60a80)
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
18FC ?= gfortran
19
20NDEBUG ?=
21LDFLAGS ?=
22LOADLIBES ?=
23TARGET_ARCH ?=
24UNDERSCORE ?= 1
25
26# env variable OCCA_DIR should point to OCCA-1.0 branch
27OCCA_DIR ?= ../occa
28
29SANTIZ = -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer
30CFLAGS = -std=c99 -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP -march=native
31FFLAGS = -cpp     -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP -march=native
32
33CFLAGS += $(if $(NDEBUG),-O2,-g)
34ifeq ($(UNDERSCORE), 1)
35  CFLAGS += -DUNDERSCORE
36endif
37
38FFLAGS += $(if $(NDEBUG),-O2,-g)
39
40CFLAGS += $(if $(NDEBUG),,)#$(SANTIZ))
41FFLAGS += $(if $(NDEBUG),,)#$(SANTIZ))
42LDFLAGS += $(if $(NDEBUG),,)#$(SANTIZ))
43CPPFLAGS = -I.
44LDLIBS = -lm
45OBJDIR := build
46LIBDIR := .
47NPROCS := $(shell getconf _NPROCESSORS_ONLN)
48MFLAGS := -j $(NPROCS) --warn-undefined-variables \
49			--no-print-directory --no-keep-going
50
51PROVE ?= prove
52PROVE_OPTS ?= -j $(NPROCS)
53DARWIN := $(filter Darwin,$(shell uname -s))
54SO_EXT := $(if $(DARWIN),dylib,so)
55#libceed
56libceed := $(LIBDIR)/libceed.$(SO_EXT)
57libceed.c := $(wildcard ceed*.c)
58# tests
59tests.c   := $(sort $(wildcard tests/t[0-9][0-9]-*.c))
60tests.f   := $(sort $(wildcard tests/t[0-9][0-9]-*.f))
61tests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
62tests     += $(tests.f:tests/%.f=$(OBJDIR)/%)
63#examples
64examples.c := $(sort $(wildcard examples/*.c))
65examples  := $(examples.c:examples/%.c=$(OBJDIR)/%)
66# backends/[ref & occa]
67ref.c     := $(sort $(wildcard backends/ref/*.c))
68ref.o     := $(ref.c:%.c=$(OBJDIR)/%.o)
69occa.c    := $(sort $(wildcard backends/occa/*.c))
70occa.o    := $(occa.c:%.c=$(OBJDIR)/%.o)
71
72# Output color rules
73COLOR_OFFSET = 3
74COLOR = $(shell echo $(rule_path)|cksum|cut -b1-2)
75rule_path = $(notdir $(patsubst %/,%,$(dir $<)))
76rule_file = $(basename $(notdir $@))
77rule_dumb = @echo -e $(rule_path)/$(rule_file)
78rule_term = @echo -e \\e[38\;5\;$(shell echo $(COLOR)+$(COLOR_OFFSET)|bc -l)\;1m\
79             $(rule_path)\\033[m/\\033[\m$(rule_file)\\033[m
80# if TERM=dumb, use it, otherwise switch to the term one
81output = $(if $(TERM:dumb=),$(rule_term),$(rule_dumb))
82
83V ?= 0
84ifeq ($(V),0)
85  quiet = @printf "  %10s %s\n" "$1" "$@"; $($(1))
86else
87  quiet = $($(1))
88endif
89
90.SUFFIXES:
91.SUFFIXES: .c .o .d
92.SECONDEXPANSION:		# to expand $$(@D)/.DIR
93
94%/.DIR :
95	@mkdir -p $(@D)
96	@touch $@
97
98.PRECIOUS: %/.DIR
99
100all : $(libceed) ceed.pc
101
102$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name $(abspath $(libceed)))
103
104$(libceed) : $(ref.o)
105ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
106  $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
107  $(libceed) : LDLIBS += -locca #-lrt -ldl
108  $(libceed) : $(occa.o)
109  $(occa.o) : CFLAGS += -I$(OCCA_DIR)/include
110endif
111$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o)
112	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
113
114$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
115	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
116
117$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
118	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS)
119
120$(OBJDIR)/% : tests/%.f | $$(@D)/.DIR
121	$(call quiet,FC) $(FFLAGS) $(LDFLAGS) -o $@ $(abspath $<) -lceed $(LDLIBS)
122
123$(OBJDIR)/%.o : examples/%.c | $$(@D)/.DIR
124	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
125
126$(tests) $(examples) : $(libceed)
127$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
128$(OBJDIR)/t% : tests/t%.c tests/t%.f $(libceed)
129$(OBJDIR)/ex% : examples/ex%.c $(libceed)
130
131run-t% : $(OBJDIR)/t%
132	@tests/tap.sh $(<:build/%=%)
133
134test : $(tests:$(OBJDIR)/t%=run-t%)
135tst:;@$(MAKE) $(MFLAGS) test
136
137prove : $(tests)
138	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%)
139
140examples : $(examples)
141
142ceed.pc : ceed.pc.template
143	@sed 's:%prefix%:$(abspath .):' $< > $@
144
145.PHONY: all clean print test examples astyle
146cln clean :
147	$(RM) *.o $(OBJDIR)/*.o *.d $(OBJDIR)/*.d $(libceed) $(tests) ceed.pc
148	$(RM) -r *.dSYM $(OBJDIR)/backends
149	$(MAKE) -C examples/mfem clean
150
151astyle :
152	astyle --style=google --indent=spaces=2 --max-code-length=80 \
153            --keep-one-line-statements --keep-one-line-blocks --lineend=linux \
154            --suffix=none --preserve-date --formatted \
155            *.[ch] tests/*.[ch] backends/*/*.[ch] examples/*.[ch] examples/mfem/*.[ch]pp
156
157print :
158	@echo $(VAR)=$($(VAR))
159
160print-%:
161	$(info [ variable name]: $*)
162	$(info [        origin]: $(origin $*))
163	$(info [         value]: $(value $*))
164	$(info [expanded value]: $($*))
165	$(info )
166	@true
167
168-include $(libceed.c:%.c=build/%.d) $(tests.c:tests/%.c=build/%.d)
169