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