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 50all: navierstokes 51 52navierstokes: $(src.o) | $(PETSc.pc) $(ceed.pc) 53 $(call quiet,LINK.o) $(CEED_LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ 54 55.SECONDEXPANSION: # to expand $$(@D)/.DIR 56%/.DIR : 57 @mkdir -p $(@D) 58 @touch $@ 59 60# Quiet, color output 61quiet ?= $($(1)) 62 63$(OBJDIR)/%.o : %.c | $$(@D)/.DIR 64 $(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<) 65 66# Rules for building the examples 67#%: %.c 68 69print: $(PETSc.pc) $(ceed.pc) 70 $(info CC : $(CC)) 71 $(info CFLAGS : $(CFLAGS)) 72 $(info CPPFLAGS: $(CPPFLAGS)) 73 $(info LDFLAGS : $(LDFLAGS)) 74 $(info LDLIBS : $(LDLIBS)) 75 $(info OPT : $(OPT)) 76 @true 77 78print-% : 79 $(info [ variable name]: $*) 80 $(info [ origin]: $(origin $*)) 81 $(info [ flavor]: $(flavor $*)) 82 $(info [ value]: $(value $*)) 83 $(info [expanded value]: $($*)) 84 $(info ) 85 @true 86 87clean: 88 $(RM) -r $(OBJDIR) navierstokes *.vtu *.bin* *.csv *.png 89 90$(PETSc.pc): 91 $(if $(wildcard $@),,$(error \ 92 PETSc config not found. Please set PETSC_DIR and PETSC_ARCH)) 93 94.PHONY: all print clean 95 96pkgconf = $(shell pkg-config $(if $(STATIC),--static) $1 | sed -e 's/^"//g' -e 's/"$$//g') 97 98-include $(src.o:%.o=%.d) 99