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 := -j $(NPROCS) --warn-undefined-variables \ 39 --no-print-directory --quiet --no-keep-going 40 41PROVE ?= prove 42DARWIN := $(filter Darwin,$(shell uname -s)) 43SO_EXT := $(if $(DARWIN),dylib,so) 44 45libceed := $(LIBDIR)/libceed.$(SO_EXT) 46libceed.c := $(wildcard ceed*.c) 47occa.c := $(sort $(wildcard occa/*.c)) 48occa := $(occa.c:occa/%.c=$(OBJDIR)/%) 49tests.c := $(sort $(wildcard tests/t[0-9][0-9]-*.c)) 50tests := $(tests.c:tests/%.c=$(OBJDIR)/%) 51examples.c := $(sort $(wildcard examples/*.c)) 52examples := $(examples.c:examples/%.c=$(OBJDIR)/%) 53 54 55# OUTPUT rules # 56COLOR_OFFSET = 3 57COLOR = $(shell echo $(rule_path)|cksum|cut -b1-2) 58rule_path = $(notdir $(patsubst %/,%,$(dir $<))) 59rule_file = $(basename $(notdir $@)) 60rule_dumb = @echo -e $(rule_path)/$(rule_file) 61rule_xterm = @echo -e \\e[38\;5\;$(shell echo $(COLOR)+$(COLOR_OFFSET)|bc -l)\;1m\ 62 $(rule_path)\\033[m/\\033[\m$(rule_file)\\033[m 63output = $(rule_${TERM}) 64 65.SUFFIXES: 66.SUFFIXES: .c .o .d 67.SECONDEXPANSION: # to expand $$(@D)/.DIR 68 69%/.DIR : 70 @mkdir -p $(@D) 71 @touch $@ 72 73.PRECIOUS: %/.DIR 74 75all dbg:;$(MAKE) $(MFLAGS) $(libceed) $(tests) 76opt:;NDEBUG=1 $(MAKE) $(MFLAGS) $(libceed) $(tests) 77 78$(libceed) : $(libceed.c:%.c=$(OBJDIR)/%.o) $(occa.c:%.c=$(OBJDIR)/%.o);$(output) 79 $(CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS) 80 81$(OBJDIR)/%.o : $(pwd)/%.c | $$(@D)/.DIR;$(output) 82 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ 83 84$(OBJDIR)/%.o : $(pwd)/occa/%.c $(pwd)/occa/ceed-occa.h | $$(@D)/.DIR;$(output) 85 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ 86 87#$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR 88# $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS) 89 90$(OBJDIR)/%.o : $(pwd)/tests/%.c | $$(@D)/.DIR;$(output) 91 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< 92 93$(OBJDIR)/%.o : $(pwd)/examples/%.c | $$(@D)/.DIR;$(output) 94 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $^ 95 96$(tests) $(examples) : $(libceed) 97$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(LIBDIR) -L$(LIBDIR) 98$(OBJDIR)/t% : tests/t%.c $(libceed) 99$(OBJDIR)/ex% : examples/ex%.c $(libceed) 100 101run-t% : $(OBJDIR)/t% 102 tests/tap.sh $(<:build/%=%) 103 104test : $(tests:$(OBJDIR)/t%=run-t%) 105tst:;@$(MAKE) $(MFLAGS) test 106 107prove : $(tests) 108 $(PROVE) --exec tests/tap.sh $(CEED_PROVE_OPTS) $(tests:$(OBJDIR)/%=%) 109 110examples : $(examples) 111 112.PHONY: clean print test examples astyle 113cln clean : 114 $(RM) *.o $(OBJDIR)/*.o *.d $(OBJDIR)/*.d $(libceed) $(tests.c:%.c=%) 115 $(RM) -r *.dSYM $(OBJDIR)/occa 116 117astyle : 118 astyle --style=google --indent=spaces=2 --max-code-length=80 \ 119 --keep-one-line-statements --keep-one-line-blocks --lineend=linux \ 120 --suffix=none --preserve-date --formatted \ 121 *.[ch] tests/*.[ch] examples/*.[ch] 122 123 124print : 125 @echo $(VAR)=$($(VAR)) 126 127print-%: 128 $(info [ variable name]: $*) 129 $(info [ origin]: $(origin $*)) 130 $(info [ value]: $(value $*)) 131 $(info [expanded value]: $($*)) 132 $(info ) 133 @true 134 135-include $(libceed.c:%.c=%.d) $(tests.c:%.c=%.d) 136