-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.rules
119 lines (99 loc) · 3.56 KB
/
Makefile.rules
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
#
# Append extraflags to the commands
#
cmdc += $(EXTRAFLAGS)
cmdx += $(EXTRAFLAGS)
#
# Force a given optimization effort to be used
#
ifneq ($(FORCE_OPT),)
cmdc := $(shell echo $(cmdc) | sed 's/-O[0-9]//g')
cmdx := $(shell echo $(cmdx) | sed 's/-O[0-9]//g')
cmdc += -$(FORCE_OPT)
cmdx += -$(FORCE_OPT)
endif
#
# Find files
#
CFILES += $(wildcard *.c)
CXXFILES += $(wildcard *.cpp)
CXXFILES += $(wildcard *.cc)
cmdc += $(addprefix $(shell pwd)/,$(CFILES))
cmdx += $(addprefix $(shell pwd)/,$(CXXFILES))
#
# Create the command
#
ifneq ($(CFILES),)
cmd := $(cmdc)
else ifneq ($(CXXFILES),)
cmd := $(cmdx)
else
$(error No source files found in $(main_folder))
endif
all: static run
static: $(results_folder)/a.out
@if [ ! -e $< ] ; then \
echo "#### Error #### Binary not generated for $(main_folder)" | tee -a $(error_log); \
echo "#### Error #### Command to reproduce"; \
cat $(compile_cmd) | tee -a $(error_log); \
false; \
fi
@echo " ---> Binary built successfully: $(main_folder)"
ifeq ($(CUSTOM_STATIC_BUILD),)
$(results_folder)/a.out: prepare_folder_to_build
@export LIBRARY_PATH
@export LD_LIBRARY_PATH
@echo "$(cmd) -o $(results_folder)/a.out" >> $(compile_cmd)
@cd $(results_folder) ; $(cmd) -o $(results_folder)/a.out 2> $(compile_log) ; true
endif
dynamic: $(results_folder)/a.so
@if [ ! -e $< ] ; then \
echo "#### Error #### Binary not generated for $(main_folder)" | tee -a $(error_log); \
echo "#### Error #### Command to reproduce"; \
cat $(compile_cmd) | tee -a $(error_log); \
false; \
fi
@echo " ---> Library built successfully: $(main_folder)"
ifeq ($(CUSTOM_DYNAMIC_BUILD),)
$(results_folder)/a.so: prepare_folder_to_build
@export LIBRARY_PATH
@export LD_LIBRARY_PATH
@echo "$(cmd) -o $(results_folder)/a.so -shared -fPIC" >> $(compile_cmd)
@cd $(results_folder) ; $(cmd) -o $(results_folder)/a.so -shared -fPIC 2> $(compile_log) ; true
endif
run: prepare_folder_to_run
@export LIBRARY_PATH
@export LD_LIBRARY_PATH
@echo "$(cmd) -o $(results_folder)/a.out" >> $(compile_cmd)
ifeq ($(DEVICE_TYPE),amd)
@echo " -----> AMD: OpenMP offload target triple: $(DEVICE_TARGET) device arch: $(DEVICE_ARCH)"
ifeq ($(USE_XNACK),1)
@echo " -----> AMD: XNACK is enabled"
else
@echo " -----> AMD: XNACK is disabled"
endif
@HSA_XNACK=$(USE_XNACK) $(results_folder)/a.out 1>$(results_folder)/stdout 2>$(results_folder)/stderr ; true
else
@$(results_folder)/a.out 1>$(results_folder)/stdout 2>$(results_folder)/stderr ; true
endif
@diff $(results_folder)/stdout expected > /dev/null || \
(if [ $$? ] ; then \
echo "#### Error #### Result mismatch for $(main_folder)" | tee -a $(error_log); \
echo "#### Error #### Command to reproduce"; \
cat $(compile_cmd) | tee -a $(error_log); \
false; \
fi)
@echo " ---> Binary runs successfully: $(main_folder)"
prepare_folder_to_build:
@echo " -> Building test $(main_folder)..." ; echo -n " ---> Description: " ; cat desc
@rm -rf $(results_folder)
@mkdir -p $(results_folder)
@echo "export LIBRARY_PATH=\"$(LIBRARY_PATH)\"" > $(compile_cmd)
@echo "export LD_LIBRARY_PATH=\"$(LD_LIBRARY_PATH)\"" >> $(compile_cmd)
@echo "cd $(main_folder)" >> $(compile_cmd)
prepare_folder_to_run:
@echo " -> Running test $(main_folder)..." ; echo -n " ---> Description: " ; cat desc
@mkdir -p $(results_folder)
@echo "export LIBRARY_PATH=\"$(LIBRARY_PATH)\"" > $(compile_cmd)
@echo "export LD_LIBRARY_PATH=\"$(LD_LIBRARY_PATH)\"" >> $(compile_cmd)
@echo "cd $(main_folder)" >> $(compile_cmd)