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