1 | # |
---|
2 | # $Id: Makefile.Selftest 145 2010-10-13 18:15:51Z rosiere $ |
---|
3 | # |
---|
4 | # [ Description ] |
---|
5 | # |
---|
6 | # Makefile |
---|
7 | # |
---|
8 | |
---|
9 | #-----[ Directory ]---------------------------------------- |
---|
10 | DIR_BIN = $(DIR_TMP)/bin/$(ENTITY) |
---|
11 | DIR_CFG_GEN = $(DIR_TMP)/configuration_generated/$(ENTITY) |
---|
12 | DIR_CFG_USER = configuration |
---|
13 | DIR_LOG = log |
---|
14 | |
---|
15 | #-----[ Variables ]---------------------------------------- |
---|
16 | CFG_FILE_PATH = $(DIR_CFG_USER) |
---|
17 | CFG_FILE_EXTENSION = gen |
---|
18 | CFG_FILE_DEBUG = $(CFG_FILE_PATH)/debug.$(CFG_FILE_EXTENSION) |
---|
19 | |
---|
20 | OBJECTS = $(OBJECTS_COMMON) |
---|
21 | |
---|
22 | LIBS = -lm $(SYSTEMC_LIBNAME_$(SIMULATOR_SYSTEMC)) |
---|
23 | |
---|
24 | MODELTECH_LIBRARY = $(addprefix -lib ,$(addsuffix .a, $(subst -l,$(DIR_LIB)/lib,$(LIBRARY)))) |
---|
25 | #MODELTECH_LIBRARY = $(LIBRARY) |
---|
26 | |
---|
27 | EXEC_PREFIX = |
---|
28 | #$(VALGRIND) |
---|
29 | EXEC_PARAMS = $(SYSTEMC_EXEC_PARAMS_$(SIMULATOR_SYSTEMC)) |
---|
30 | EXEC_LOG = $(patsubst $(DIR_CFG_GEN)/%.cfg,$(DIR_LOG)/%.exec.log,$(wildcard $(DIR_CFG_GEN)/*.cfg)) \ |
---|
31 | $(patsubst $(DIR_CFG_USER)/%.cfg,$(DIR_LOG)/%.exec.log,$(wildcard $(DIR_CFG_GEN)/*.cfg)) |
---|
32 | BIN = Selftest.x |
---|
33 | EXEC = $(DIR_BIN)/$(BIN) |
---|
34 | |
---|
35 | #-----[ Rules ]-------------------------------------------- |
---|
36 | .PRECIOUS : $(DIR_BIN)/%.x $(DIR_LOG)/%.exec.log |
---|
37 | #.NOTPARALLEL : clean clean_all help |
---|
38 | |
---|
39 | vpath %.x $(DIR_BIN) |
---|
40 | |
---|
41 | all_selftest : test_env $(DIR_OBJ) $(DIR_BIN) $(DIR_LOG) |
---|
42 | @\ |
---|
43 | $(MAKE) library;\ |
---|
44 | $(MAKE) $(EXEC); |
---|
45 | |
---|
46 | execute_only : |
---|
47 | @\ |
---|
48 | $(MAKE) $(EXEC_LOG);\ |
---|
49 | declare -i all_ok=1; \ |
---|
50 | for i in $(EXEC_LOG); do \ |
---|
51 | $(GREP) -q "Timing" $$i; \ |
---|
52 | declare -i test_timing=$$?; \ |
---|
53 | $(GREP) -q "Test OK" $$i; \ |
---|
54 | declare -i test_ok=$$?; \ |
---|
55 | $(GREP) -q "Test KO" $$i; \ |
---|
56 | declare -i test_ko=$$?; \ |
---|
57 | if $(TEST) $$test_ko -eq 0 -o $$test_ok -ne 0 -o $$test_timing -ne 0; \ |
---|
58 | then all_ok=0; \ |
---|
59 | fi; \ |
---|
60 | done; \ |
---|
61 | if $(TEST) $$all_ok -eq 1; \ |
---|
62 | then $(ECHO) "-------------------| Test OK"; exit 0; \ |
---|
63 | else $(ECHO) "-------------------| Test KO"; exit 1; \ |
---|
64 | fi; |
---|
65 | |
---|
66 | execute : all_selftest |
---|
67 | @\ |
---|
68 | $(MAKE) execute_only; |
---|
69 | |
---|
70 | reconfig : |
---|
71 | @\ |
---|
72 | $(MAKE) config_clean;\ |
---|
73 | $(MAKE) config; |
---|
74 | |
---|
75 | config_clean : |
---|
76 | @$(RM) $(DIR_CFG_GEN) |
---|
77 | |
---|
78 | config : $(DIR_CFG_GEN) |
---|
79 | @\ |
---|
80 | $(ECHO) "Generate configuration"; \ |
---|
81 | declare -i CPT=0; \ |
---|
82 | declare files; \ |
---|
83 | \ |
---|
84 | if $(TEST) -f $(CFG_FILE_DEBUG); then \ |
---|
85 | files=$(CFG_FILE_DEBUG); \ |
---|
86 | else \ |
---|
87 | files=$$($(LS) $(CFG_FILE_PATH)/*.$(CFG_FILE_EXTENSION) ); \ |
---|
88 | fi; \ |
---|
89 | \ |
---|
90 | declare -i NB_CONFIG=0; \ |
---|
91 | declare -i NB_DIGIT=0; \ |
---|
92 | \ |
---|
93 | for file in $${files}; do \ |
---|
94 | declare -ai PERIOD=(); \ |
---|
95 | declare -i IT=0; \ |
---|
96 | \ |
---|
97 | PERIOD[0]=1; \ |
---|
98 | \ |
---|
99 | while read line; do \ |
---|
100 | declare -a LINE=($${line}); \ |
---|
101 | \ |
---|
102 | if $(TEST) $${IT} -ne 0; then \ |
---|
103 | declare -a RANGE_LOCAL=($$($(DIR_SCRIPT)/range.sh $${LINE[0]} $${LINE[1]} $${LINE[2]})); \ |
---|
104 | declare -i SIZE=$${#RANGE_LOCAL[*]}; \ |
---|
105 | PERIOD[$${IT}]=$$(($${PERIOD[$$(($${IT}-1))]}*$${SIZE})); \ |
---|
106 | fi; \ |
---|
107 | \ |
---|
108 | IT=$$(($${IT}+1)); \ |
---|
109 | done < $${file}; \ |
---|
110 | \ |
---|
111 | NB_CONFIG=$$(($${NB_CONFIG} + $${PERIOD[$$(($${IT}-1))]})); \ |
---|
112 | done; \ |
---|
113 | \ |
---|
114 | $(ECHO) " * They are $${NB_CONFIG} configurations"; \ |
---|
115 | \ |
---|
116 | declare -i x=$${NB_CONFIG}; \ |
---|
117 | \ |
---|
118 | while test $${x} -ne 0; do \ |
---|
119 | NB_DIGIT=$$(($${NB_DIGIT} + 1)); \ |
---|
120 | x=$$(($${x} / 10)); \ |
---|
121 | done; \ |
---|
122 | \ |
---|
123 | for file in $${files}; do \ |
---|
124 | declare NAME; \ |
---|
125 | declare -ai MIN=(); \ |
---|
126 | declare -ai PERIOD=(); \ |
---|
127 | declare -a RANGE_LOCAL=(); \ |
---|
128 | declare -a RANGE=(); \ |
---|
129 | declare -a SIZE=(); \ |
---|
130 | declare -i IT=0; \ |
---|
131 | \ |
---|
132 | PERIOD[0]=1; \ |
---|
133 | \ |
---|
134 | while read line; do \ |
---|
135 | declare -a LINE=($${line}); \ |
---|
136 | \ |
---|
137 | if $(TEST) $${IT} -eq 0; then \ |
---|
138 | NAME=$${LINE[0]}; \ |
---|
139 | else \ |
---|
140 | MIN[$${IT}]=$${LINE[0]}; \ |
---|
141 | RANGE[$${IT}]=$$($(DIR_SCRIPT)/range.sh $${LINE[0]} $${LINE[1]} $${LINE[2]}); \ |
---|
142 | RANGE_LOCAL=($${RANGE[$${IT}]}); \ |
---|
143 | SIZE[$${IT}]=$${#RANGE_LOCAL[*]}; \ |
---|
144 | PERIOD[$${IT}]=$$(($${PERIOD[$$(($${IT}-1))]}*$${SIZE[$${IT}]})); \ |
---|
145 | fi; \ |
---|
146 | \ |
---|
147 | IT=$$(($${IT}+1)); \ |
---|
148 | done < $${file}; \ |
---|
149 | \ |
---|
150 | declare -a DATA=(); \ |
---|
151 | declare -ai ENUM_CONFIG=($$($(DIR_SCRIPT)/range.sh 0 $$(($${PERIOD[$$(($${IT}-1))]}-1)))); \ |
---|
152 | declare -ai ENUM_PARAM=($$($(DIR_SCRIPT)/range.sh 1 $${#MIN[*]})); \ |
---|
153 | declare -i NB_PARAM=$${#MIN[*]}; \ |
---|
154 | \ |
---|
155 | $(ECHO) " * File : $$file"; \ |
---|
156 | $(ECHO) " * They are $${NB_PARAM} parameters"; \ |
---|
157 | $(ECHO) " * Generate $${PERIOD[$$(($${IT}-1))]} configurations"; \ |
---|
158 | \ |
---|
159 | for i in $${ENUM_CONFIG[*]}; do \ |
---|
160 | x=$$i; \ |
---|
161 | for j in $${ENUM_PARAM[*]}; do \ |
---|
162 | declare -a RANGE_LOCAL=($${RANGE[$$j]}); \ |
---|
163 | DATA[$$j]="$${RANGE_LOCAL[$$((($$x % $${SIZE[$$j]})))]} "; \ |
---|
164 | x=$$(($$x/$${SIZE[$$j]})); \ |
---|
165 | done; \ |
---|
166 | declare NUM=$$($(PRINTF) %.$${NB_DIGIT}d $${CPT}); \ |
---|
167 | $(ECHO) $${DATA[*]} > "$(DIR_CFG_GEN)/$${NAME}_$${NUM}.cfg"; \ |
---|
168 | $(ECHO) " - {$${NUM}} $${DATA[*]}"; \ |
---|
169 | CPT=$$(($${CPT}+1)); \ |
---|
170 | done; \ |
---|
171 | done; |
---|
172 | |
---|
173 | $(DIR_LOG)/%.exec.log : $(DIR_CFG_GEN)/%.cfg $(EXEC) |
---|
174 | @\ |
---|
175 | $(ECHO) "Execute : $*";\ |
---|
176 | export SYSTEMC=$(SYSTEMC_$(SIMULATOR_SYSTEMC)); $(EXEC_PREFIX) $(EXEC) $(EXEC_PARAMS) $* `$(CAT) $<` &> $@; \ |
---|
177 | declare timing=`$(GREP) -h "Timing" $@`; \ |
---|
178 | $(GREP) -q "Timing" $@; \ |
---|
179 | declare -i test_timing=$$?; \ |
---|
180 | $(GREP) -q "Test OK" $@; \ |
---|
181 | declare -i test_ok=$$?; \ |
---|
182 | $(GREP) -q "Test KO" $@; \ |
---|
183 | declare -i test_ko=$$?; \ |
---|
184 | declare memory_leak=" "; \ |
---|
185 | $(GREP) -q "Leaked memory at" $@; \ |
---|
186 | if $(TEST) $$? -eq 0; \ |
---|
187 | then memory_leak="*"; \ |
---|
188 | fi; \ |
---|
189 | if $(TEST) $$test_ko -ne 0 -a $$test_ok -eq 0 -a $$test_timing -eq 0; \ |
---|
190 | then echo -e " $* ... OK $$memory_leak\t$$timing";\ |
---|
191 | else echo " $* ... KO"; \ |
---|
192 | fi; |
---|
193 | |
---|
194 | $(DIR_BIN)/%.x : $(SOURCES) $(HEADERS) $(DIR_OBJ) $(DIR_BIN) |
---|
195 | @\ |
---|
196 | $(ECHO) "Linkage : $*";\ |
---|
197 | case "${SIMULATOR_SYSTEMC}" in \ |
---|
198 | "modelsim") \ |
---|
199 | $(MAKE) vhdl_package; \ |
---|
200 | $(MAKE) vhdl_entity; \ |
---|
201 | $(MODELTECH_SCCOM) -work $(DIR_WORK) $(CFLAGS) $(SOURCES); \ |
---|
202 | $(MODELTECH_SCCOM) -work $(DIR_WORK) $(MODELTECH_LIBRARY) $(LFLAGS) $(LIBS) -link;\ |
---|
203 | $(ECHO) "#!$(SHELL)" > $@; \ |
---|
204 | $(ECHO) "cd $${PWD};" >> $@; \ |
---|
205 | $(ECHO) 'declare args;' >> $@; \ |
---|
206 | $(ECHO) 'for i in $${*}; do' >> $@; \ |
---|
207 | $(ECHO) ' args=$${args}" -sc_arg $${i}";' >> $@; \ |
---|
208 | $(ECHO) 'done;' >> $@; \ |
---|
209 | $(ECHO) "$(MODELTECH_VSIM) -novopt "'$${args}'" $(MODELTECH_LIBRARY) $(DIR_WORK).top;" >> $@; \ |
---|
210 | $(ECHO) "cd -;" >> $@; \ |
---|
211 | $(CHMOD) +x $@; \ |
---|
212 | ;; \ |
---|
213 | *) \ |
---|
214 | $(MAKE) $(OBJECTS); \ |
---|
215 | $(SYSTEMC_CXX_$(SIMULATOR_SYSTEMC)) $(LFLAGS) -o $@ $(OBJECTS) $(LIBRARY) $(LIBS);\ |
---|
216 | ;; \ |
---|
217 | esac; |
---|
218 | |
---|
219 | $(DIR_BIN) $(DIR_LOG) : |
---|
220 | @\ |
---|
221 | $(ECHO) "Create directory : $@";\ |
---|
222 | $(MKDIR) $@;\ |
---|
223 | |
---|
224 | $(DIR_CFG_GEN) : |
---|
225 | @\ |
---|
226 | $(ECHO) "Create directory : $@";\ |
---|
227 | $(MKDIR) $@;\ |
---|
228 | $(LS) $(DIR_CFG_USER)/*.cfg &> /dev/null; \ |
---|
229 | if $(TEST) $$? -eq 0; then \ |
---|
230 | $(CP) $(DIR_CFG_USER)/*.cfg $@; \ |
---|
231 | fi; |
---|
232 | |
---|
233 | selftest_clean : local_clean config_clean |
---|
234 | @$(RM) $(DIR_LOG) \ |
---|
235 | $(DIR_CFG_USER)/*~ \ |
---|
236 | $(EXEC) \ |
---|
237 | *.vhdl \ |
---|
238 | *.pos \ |
---|
239 | *.stat \ |
---|
240 | *.log \ |
---|
241 | *.dot \ |
---|
242 | *.txt \ |
---|
243 | generated_by_systemcass \ |
---|
244 | semantic.cache \ |
---|
245 | gmon.out \ |
---|
246 | core*; |
---|
247 | |
---|
248 | selftest_clean_all : library_clean |
---|
249 | @\ |
---|
250 | $(RM) $(DIR_BIN) |
---|
251 | |
---|
252 | selftest_help : |
---|
253 | @\ |
---|
254 | $(ECHO) " -----[ Selftest ]-----------------------------------";\ |
---|
255 | $(ECHO) "";\ |
---|
256 | $(ECHO) " * all_selftest : compile all c++ file and execute";\ |
---|
257 | $(ECHO) " * execute : execute all instance";\ |
---|
258 | $(ECHO) " * execute_only : execute all instance without rebuild all libraries";\ |
---|
259 | $(ECHO) " * config : generate configuration with configuration's file" ;\ |
---|
260 | $(ECHO) " * reconfig : regenerate configuration with configuration's file" ;\ |
---|
261 | $(ECHO) " * clean : Erase all generate files";\ |
---|
262 | $(ECHO) " * clean_all : Clean + Erase all dependant library";\ |
---|
263 | $(ECHO) " * help : print this text";\ |
---|
264 | $(ECHO) ""; |
---|
265 | |
---|
266 | help : |
---|
267 | @\ |
---|
268 | $(MAKE) common_help ; \ |
---|
269 | $(MAKE) synthesis_help;\ |
---|
270 | $(MAKE) selftest_help; |
---|
271 | |
---|
272 | clean : |
---|
273 | @\ |
---|
274 | $(MAKE) common_clean ;\ |
---|
275 | $(MAKE) synthesis_clean ;\ |
---|
276 | $(MAKE) selftest_clean; |
---|
277 | |
---|
278 | clean_all : |
---|
279 | @\ |
---|
280 | $(MAKE) clean ;\ |
---|
281 | $(MAKE) selftest_clean_all; |
---|