-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.mk
141 lines (105 loc) · 4 KB
/
common.mk
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
## This is the common parts of the Makefile. Define these first, before including:
#TARGET := cholesky # will be post-fixed
#OMP_SRC := nonnested.c # C source files with #pragma omp annotations and/or with main()
#SEQ_SRC := # remaining C source files
#ADDITIONAL_TARGETS := ... # some more targets to be built/installed with all/install phonies
# NB: making object files and having separate --output-dir values per target is important to build in parallel
# even if here is only a single source, because when running `smpcc -o foo bar.c` the files bar.o and smpcc_bar.c
# will be used by all targets.
CC = gcc
CXX = g++
MCC = smpcc --cc=$(CC)
MCXX = smpcxx --cxx=$(CXX)
CFLAGS = -O$(O) -std=gnu11 -Wall -Wextra -rdynamic -g -fno-optimize-sibling-calls
CXXFLAGS = -O$(O) -std=gnu++11 -Wall -Wextra -rdynamic -g -fno-optimize-sibling-calls
OMPSSFLAGS = --ompss --Wn,-Wno-unused-parameter,-Wno-unused-but-set-variable,-Wno-unused-variable,-Wno-unused-function,-Wno-discarded-array-qualifiers
CPPFLAGS = -I$(CATCHROI_HOME)/include
LDFLAGS = -L$(CATCHROI_HOME)/lib -Wl,-rpath,$(CATCHROI_HOME)/lib
LDLIBS = -lcatchroi
ALL_TARGETS := bin/$(TARGET) bin/$(TARGET)_instr bin/$(TARGET)_debug bin/$(TARGET)_seq
CATCHROI_HOME ?= $(dir $(lastword $(MAKEFILE_LIST)))libcatchroi
DESTDIR ?= $(CATCHROI_HOME)
all: $(ALL_TARGETS)
extras:
perf: bin/$(TARGET)
instr: bin/$(TARGET)_instr
debug: bin/$(TARGET)_debug
seq: bin/$(TARGET)_seq
O = 3
%_debug:O = 0
%_seq.o %_seq :MCC := $(CC)
%_seq.o %_seq :MCXX:= $(CXX)
%_seq.o %_seq :OMPSSFLAGS = -Wno-unknown-pragmas -Wno-unused-variable
%_instr.o %_instr:OMPSSFLAGS += --instrument
%_debug.o %_debug:OMPSSFLAGS += --debug
%_perf.o :OMPSSFLAGS += --keep-all-files --output-dir=.build_perf
%_instr.o:OMPSSFLAGS += --keep-all-files --output-dir=.build_instr --instrument
%_debug.o:OMPSSFLAGS += --keep-all-files --output-dir=.build_debug --debug
define C_COMPILATION
$(MCC) $(CFLAGS) $(OMPSSFLAGS) $(CPPFLAGS) $< -c -o $@
endef
define CXX_COMPILATION
$(MCXX) $(CXXFLAGS) $(OMPSSFLAGS) $(CPPFLAGS) $< -c -o $@
endef
define C_LINKING
$(MCC) $(CFLAGS) $(OMPSSFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS)
endef
define CXX_LINKING
$(MCXX) $(CXXFLAGS) $(OMPSSFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS)
endef
# main target is perf and has no suffix
bin/$(TARGET): $(addsuffix _perf.o, $(basename $(OMP_SRC))) $(addsuffix _seq.o, $(basename $(SEQ_SRC))) | bin
ifeq ($(filter-out %.c , $(OMP_SRC) $(SEQ_SRC)),)
$(C_LINKING)
else
$(CXX_LINKING)
endif
# all other targets {main target}_{suffix} have {source file}_{suffix}.o objects
bin/$(TARGET)_%: $(addsuffix _%.o, $(basename $(OMP_SRC))) $(addsuffix _seq.o, $(basename $(SEQ_SRC))) | bin
ifeq ($(filter-out %.c , $(OMP_SRC) $(SEQ_SRC)),)
$(C_LINKING)
else
$(CXX_LINKING)
endif
# build objects
%_seq.o: %.c
$(C_COMPILATION)
%_perf.o: %.c | .build_perf
$(C_COMPILATION)
%_instr.o: %.c | .build_instr
$(C_COMPILATION)
%_debug.o: %.c | .build_debug
$(C_COMPILATION)
%_seq.o: %.cc
$(CXX_COMPILATION)
%_perf.o: %.cc | .build_perf
$(CXX_COMPILATION)
%_instr.o: %.cc | .build_instr
$(CXX_COMPILATION)
%_debug.o: %.cc | .build_debug
$(CXX_COMPILATION)
# make directories.
.build_%:
@mkdir -p $@
bin:
@mkdir -p $@
# some meta rules
clean:
@rm -fv $(ALL_TARGETS)
@rm -rf .build_perf .build_instr .build_debug *.o
@test ! -e bin || rmdir --ignore-fail-on-non-empty bin
install: $(ALL_TARGETS)
@mkdir -p $(DESTDIR)/bin
@cp -v $^ $(DESTDIR)/bin/
uninstall:
@rm -v $(addprefix $(DESTDIR)/bin/,$(notdir $(ALL_TARGETS)))
@test ! -e $(DESTDIR)/bin || rmdir --ignore-fail-on-non-empty $(DESTDIR)/bin
.PRECIOUS: .build_perf .build_instr .build_debug bin
.INTERMEDIATE: $(addsuffix _seq.o, $(basename $(SEQ_SRC)))
.INTERMEDIATE: $(addsuffix _perf.o, $(basename $(OMP_SRC)))
.INTERMEDIATE: $(addsuffix _instr.o, $(basename $(OMP_SRC)))
.INTERMEDIATE: $(addsuffix _debug.o, $(basename $(OMP_SRC)))
.INTERMEDIATE: $(addsuffix _seq.o, $(basename $(OMP_SRC)))
.PHONY: perf instr debug seq clean install uninstall extras
## After including file, adjust variables, e.g.:
#LDLIBS+=-lm