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