-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile.apps
More file actions
213 lines (172 loc) · 6.4 KB
/
Makefile.apps
File metadata and controls
213 lines (172 loc) · 6.4 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Makefile for AbstractMachine Kernels and Libraries
### *Get a more readable version of this Makefile* by `make html` (requires python-markdown)
html:
cat Makefile | sed 's/^\([^#]\)/ \1/g' | markdown_py > Makefile.html
.PHONY: html
## 1. Basic Setup and Checks
### Default to create elf
ifeq ($(MAKECMDGOALS),)
MAKECMDGOALS = $(APP)
.DEFAULT_GOAL = $(APP)
endif
### Override checks when `make clean/clean-all/html`
ifeq ($(findstring $(MAKECMDGOALS),clean|clean-all|html),)
### Print build info message
$(info # Building $(NAME)-$(MAKECMDGOALS))
### Check: environment variable `$ARCH` must be in the supported list
ARCHS = $(basename $(notdir $(shell ls ../scripts/*.mk)))
ifeq ($(filter $(ARCHS), $(ARCH)), )
$(error Expected $$ARCH in {$(ARCHS)}, Got "$(ARCH)")
endif
### Checks end here
endif
## 2. General Compilation Targets
### Create the destination directory (`build/`)
WORK_DIR = .
DST_DIR = $(WORK_DIR)/build$(TAG)
$(shell mkdir -p $(DST_DIR))
### Compilation targets
APP_REL = $(DST_DIR)/$(NAME)
APP = $(abspath $(APP_REL))
### Files to be linked: object files (`.o`) and libraries (`.a`)
OBJS := $(patsubst %.F,%.fppized.o,$(SRCS))
OBJS := $(patsubst %.F90,%.fppized.o,$(OBJS))
OBJS := $(patsubst %.f90,%.o,$(OBJS))
OBJS := $(patsubst %.f,%.o,$(OBJS))
OBJS := $(patsubst %.c,%.o,$(OBJS))
OBJS := $(patsubst %.C,%.o,$(OBJS))
OBJS := $(patsubst %.cpp,%.o,$(OBJS))
OBJS := $(patsubst %.cc,%.o,$(OBJS))
OBJS := $(addprefix $(DST_DIR)/, $(OBJS))
ifneq (,$(findstring -g, $(OPTIMIZE)))
.PRECIOUS: %.fppized.f90 %.fppized.f
endif
## 3. General Compilation Flags
-include $(SPEC_LITE)/scripts/$(ARCH).mk
### (Cross) compilers, e.g., mips-linux-gnu-g++
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
FC = $(CROSS_COMPILE)gfortran
ifeq ($(LD_FORTRAN),1)
LD = $(FC)
else ifeq ($(LD_CXX),1)
LD = $(CXX)
else
LD = $(CC)
endif
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
READELF = $(CROSS_COMPILE)readelf
### Compilation flags
OPTIMIZE ?= -O3 -flto
COPTIMIZE := $(OPTIMIZE)
FOPTIMIZE := $(OPTIMIZE)
CFLAGS += $(COPTIMIZE) -MMD -DSPEC_CPU -DNDEBUG -static -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing $(TESTSET_SPECIFIC_FLAG) $(PGO_FLAG)
# GCC/Clang-specific warning flags, not supported by ICC
ifeq ($(findstring icc,$(CC)),)
CFLAGS += -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-implicit-function-declaration
endif
# ICC compatibility header: fix _Float32 and __float128 issues with modern glibc/libstdc++
ifneq ($(findstring icc,$(CC)),)
CFLAGS += -include $(abspath ../scripts/icc_gnuc_compat.h)
endif
CXXFLAGS += $(filter-out -Wno-implicit-int -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-implicit-function-declaration, $(CFLAGS))
FFLAGS += $(FOPTIMIZE) $(FFLAGS_EXTRA) -static $(TESTSET_SPECIFIC_FLAG) $(PGO_FLAG)
ifeq ($(findstring flang,$(FC)),)
ifeq ($(findstring ifort,$(FC)),)
FFLAGS += -fno-strict-aliasing
endif
endif
LDFLAGS += -static $(OPTIMIZE) $(PGO_FLAG)
SPECPPFLAGS += -o
JEMALLOC_LIBS :=
ifeq ($(LD_JEMALLOC),1)
JEMALLOC_LIBS += $(RISCV)/lib/libjemalloc.a -lm -pthread -latomic
endif
## 4. Compilation Rules
### Rule (compile): a single `.c` -> `.o` (gcc)
$(DST_DIR)/%.o: %.c
@mkdir -p $(dir $@) && echo + CC $<
@$(CC) $(CFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.C` -> `.o` (g++)
$(DST_DIR)/%.o: %.C
@mkdir -p $(dir $@) && echo + CXX $<
@$(CXX) $(CXXFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.cc` -> `.o` (g++)
$(DST_DIR)/%.o: %.cc
@mkdir -p $(dir $@) && echo + CXX $<
@$(CXX) $(CXXFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.cpp` -> `.o` (g++)
$(DST_DIR)/%.o: %.cpp
@mkdir -p $(dir $@) && echo + CXX $<
@$(CXX) $(CXXFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.f` -> `.o` (gfortran)
$(DST_DIR)/%.o: %.f
@mkdir -p $(dir $@) && echo + FC $<
@cd $(dir $<) && $(FC) $(FFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.fppized.f90` -> `.fppized.o` (gfortran)
$(DST_DIR)/%.fppized.o: %.fppized.f90
@mkdir -p $(dir $@) && echo + FC $<
@cd $(dir $<) && $(FC) $(FFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.fppized.f` -> `.fppized.o` (gfortran)
$(DST_DIR)/%.fppized.o: %.fppized.f
@mkdir -p $(dir $@) && echo + FC $<
@cd $(dir $<) && $(FC) $(FFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.f90` -> `.o` (gfortran)
$(DST_DIR)/%.o: %.f90
@mkdir -p $(dir $@) && echo + FC $<
@cd $(dir $<) && $(FC) $(FFLAGS) -c -o $(abspath $@) $(abspath $<)
### Rule (compile): a single `.F90` -> `.fppized.o` (gfortran)
%.fppized.f90: %.F90
@echo + PREPARE $<
@cd $(dir $<) && ${SPEC}/bin/specperl ${SPEC}/bin/specpp $(SPECPPFLAGS) $(abspath $@) $(abspath $<)
### Rule (compile): a single `.F` -> `.fppized.o` (gfortran)
%.fppized.f: %.F
@echo + PREPARE $<
@cd $(dir $<) && ${SPEC}/bin/specperl ${SPEC}/bin/specpp $(SPECPPFLAGS) $(abspath $@) $(abspath $<)
### Rule (link): objects (`*.o`) and libraries (`*.a`) -> `IMAGE.elf`, the final ELF binary to be packed into image (ld)
$(APP): $(OBJS)
@echo + LD "->" $(APP_REL)
@$(LD) $(LDFLAGS) -o $(abspath $@) $(abspath $^) $(JEMALLOC_LIBS) $(LIBS)
### Rule (`#include` dependencies): paste in `.d` files generated by gcc on `-MMD`
-include $(addprefix $(DST_DIR)/, $(addsuffix .d, $(basename $(SRCS))))
## 5. Miscellaneous
.PHONY: copy-src
copy-src:
@cp -r $(SPEC)/benchspec/CPU2006/$(NAME)/src ./
@chmod -R +w src
.PHONY: copy-data
copy-data:
@cp -r $(SPEC)/benchspec/CPU2006/$(NAME)/data ./
@if [ -d $(SPEC)/benchspec/CPU2006/$(NAME)/extra-data ]; then cp -r $(SPEC)/benchspec/CPU2006/$(NAME)/extra-data ./ ; chmod -R +w extra-data; fi
@chmod -R +w data
.PHONY: apply-elf
apply-elf:
@cp -r $(abspath $(ELF_PATH))/$(patsubst $(basename $(NAME)).%,%,$(NAME)) $(APP)
.PHONY: collect
collect: $(APP)
@mkdir -p $(ELF_PATH)
@cp $(APP) $(ELF_PATH)/$(patsubst $(basename $(NAME)).%,%,$(NAME))
### Clean a single project (remove `build/`)
.PHONY: clean-src
clean-src:
@rm -rf ./src
.PHONY: clean-data
clean-data:
@rm -rf ./data
.PHONY: clean-logs
clean-logs:
@rm -rf ./logs
.PHONY: clean-build
clean-build:
@rm -rf ./build$(TAG)
@rm -rf src/*.mod
.PHONY: clean-obj
clean-obj:
@rm -rf $(DST_DIR)/src $(DST_DIR)/$(APP)
.PHONY: clean-pgo
clean-pgo:
@rm -rf ./pgo
### Clean all sub-projects within depth 2 (and ignore errors)
.PHONY: clean-all
clean-all: clean-src clean-data clean-build clean-logs clean-pgo