-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmakefile
87 lines (69 loc) · 2.32 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# --- Source directories ---
vpath %.f90 external/ConfigLoader
vpath %.f90 src
vpath %.cl src
# --- Source names ---
# Headers - built first, contain subroutine interface definitions
# Modules - built second, contain subroutine collections
# Programs - built and linked last, contain main program(s)
# Kernels - contain OpenCL kernel code, linked into executable as binary resource
HEADERMODULES = ConfigLoader_h
MODULES = TecplotOutput UserInput TestCases ConfigLoader
PROGS = lbmocl
KERNELS = kernels.cl
# --- Output Directories ---
FOCAL_DIR ?= ./external/focal
OPENCL_DIR ?= /usr/lib/
BINDIR = ./bin/
OBJDIR = ./obj/
MODDIR = ./mod/
# --- Targets ---
PROGOBJS =$(addprefix $(OBJDIR), $(addsuffix .o, $(PROGS)))
MODOBJS = $(addprefix $(OBJDIR), $(addsuffix .o, $(MODULES)))
HEADEROBJS = $(addprefix $(OBJDIR), $(addsuffix .o, $(HEADERMODULES)))
EXEC = $(addprefix $(BINDIR), $(PROGS))
DIRS = $(MODDIR) $(BINDIR) $(OBJDIR)
# --- Compiler Flags ---
include make.compiler
# --- Link Flags ---
ifeq ($(BUILD), release)
FOCAL_LFLAGS ?= -L$(FOCAL_DIR)/lib -lFocal
else ifeq ($(BUILD), debug)
FOCAL_LFLAGS ?= -L$(FOCAL_DIR)/lib -lFocaldbg
else
$(error unrecognized build.)
endif
OPENCL_LFLAGS ?= -g -L$(OPENCL_DIR) -lOpenCL
LFLAGS = $(FOCAL_LFLAGS) $(OPENCL_LFLAGS)
# --- Main build target ---
all: $(DIRS) $(EXEC)
include $(FOCAL_DIR)/make.include
FFLAGS+=-I$(FOCAL_MODDIR)
# --- Cleanup (reset) ---
clean:
rm -f $(OBJDIR)*.o
rm -f $(MODDIR)*.mod
rm -f $(MODDIR)*.smod
rm -f $(BINDIR)*
# Programs depend on modules
$(PROGOBJS): $(MODOBJS) $(FOCAL_LIB_OBJS)
$(EXEC): $(FOCAL_LIB_OBJS)
# Modules depend on any header modules
$(MODOBJS): $(HEADEROBJS)
# Recipe to link executables
$(BINDIR)%: $(addprefix $(OBJDIR), %.o fclKernels.o) $(MODOBJS) $(HEADEROBJS) $(FOCAL_LIB_OBJS)
$(FC) $(addprefix $(OBJDIR), $*.o fclKernels.o) $(MODOBJS) $(HEADEROBJS) $(LFLAGS) -o $@
# Recipe to compile fortran objects
$(OBJDIR)%.o: %.f90
$(FC) $(FFLAGS) -c $< -o $@
# Recipe to 'compile' kernel source into a binary object
$(OBJDIR)%.o: %.cl
ld -r -b binary fclKernels.cl -o $@
nm $@
# Recipe to concatenate kernel files
fclKernels.cl: $(KERNELS)
cat $^ > fclKernels.cl
# Recipe to create output directories
$(DIRS):
mkdir $@
.SECONDARY: $(addprefix $(OBJDIR), fclKernels.o)