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