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 17COMMON ?= ../../common.mk 18-include $(COMMON) 19 20PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc 21CEED_DIR ?= ../.. 22ceed.pc := $(CEED_DIR)/lib/pkgconfig/ceed.pc 23 24# ASAN must be left empty if you don't want to use it 25ASAN ?= 26 27CC = $(call pkgconf, --variable=ccompiler $(PETSc.pc) $(ceed.pc)) 28CFLAGS = -std=c99 \ 29 $(call pkgconf, --variable=cflags_extra $(PETSc.pc)) \ 30 $(call pkgconf, --cflags-only-other $(PETSc.pc)) \ 31 $(OPT) $(OPT_EXAMPLES) 32CPPFLAGS = $(call pkgconf, --cflags-only-I $(PETSc.pc) $(ceed.pc)) \ 33 $(call pkgconf, --variable=cflags_dep $(PETSc.pc)) 34LDFLAGS = $(call pkgconf, --libs-only-L --libs-only-other $(PETSc.pc) $(ceed.pc)) 35LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(PETSc.pc) $(ceed.pc))) 36LDLIBS = $(call pkgconf, --libs-only-l $(PETSc.pc) $(ceed.pc)) -lm 37 38AFLAGS ?= -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer 39CFLAGS += $(if $(ASAN),$(AFLAGS)) 40FFLAGS += $(if $(ASAN),$(AFLAGS)) 41LDFLAGS += $(if $(ASAN),$(AFLAGS)) 42 43OBJDIR := build 44SRCDIR := src 45PROBLEMDIR := problems 46 47src.c := navierstokes.c $(sort $(wildcard $(PROBLEMDIR)/*.c)) $(sort $(wildcard $(SRCDIR)/*.c)) 48src.o = $(src.c:%.c=$(OBJDIR)/%.o) 49 50# Path to install directory for SmartRedis. Example: /software/smartredis/install 51SMARTREDIS_DIR ?= 52ifdef SMARTREDIS_DIR 53 hiredis.pc := $(SMARTREDIS_DIR)/lib/pkgconfig/hiredis.pc 54 lsmartredis:= -lsmartredis 55 redis++.pc = $(wildcard $(SMARTREDIS_DIR)/lib/pkgconfig/redis++.pc $(SMARTREDIS_DIR)/lib64/pkgconfig/redis++.pc) 56 57 CPPFLAGS += $(call pkgconf, --cflags-only-I $(hiredis.pc) $(redis++.pc)) 58 LDFLAGS += $(call pkgconf, --libs-only-L --libs-only-other $(hiredis.pc) $(redis++.pc)) 59 LDFLAGS += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(PETSc.pc))%, $(call pkgconf, --libs-only-L $(hiredis.pc) $(redis++.pc))) 60 LDLIBS += $(call pkgconf, --libs-only-l $(hiredis.pc) $(redis++.pc)) $(lsmartredis) 61 src.c += $(sort $(wildcard $(SRCDIR)/smartsim/*.c)) 62endif 63 64all: navierstokes 65 66navierstokes: $(src.o) | $(PETSc.pc) $(ceed.pc) 67 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 68 69.SECONDEXPANSION: # to expand $$(@D)/.DIR 70%/.DIR : 71 @mkdir -p $(@D) 72 @touch $@ 73 74# Quiet, color output 75quiet ?= $($(1)) 76 77$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 78 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 79 80print: $(PETSc.pc) $(ceed.pc) 81 $(info CC : $(CC)) 82 $(info CFLAGS : $(CFLAGS)) 83 $(info CPPFLAGS: $(CPPFLAGS)) 84 $(info LDFLAGS : $(LDFLAGS)) 85 $(info LDLIBS : $(LDLIBS)) 86 $(info OPT : $(OPT)) 87 @true 88 89print-% : 90 $(info [ variable name]: $*) 91 $(info [ origin]: $(origin $*)) 92 $(info [ flavor]: $(flavor $*)) 93 $(info [ value]: $(value $*)) 94 $(info [expanded value]: $($*)) 95 $(info ) 96 @true 97 98clean: 99 $(RM) -r $(OBJDIR) navierstokes *.vtu *.bin* *.csv *.png 100 101$(PETSc.pc): 102 $(if $(wildcard $@),,$(error \ 103 PETSc config not found. Please set PETSC_DIR and PETSC_ARCH)) 104 105.PHONY: all print clean 106 107pkgconf = $(shell pkg-config $(if $(STATIC),--static) $1 | sed -e 's/^"//g' -e 's/"$$//g') 108 109-include $(src.o:%.o=%.d) 110