rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | ### |
| 2 | # @file Makefile.template |
| 3 | # @breif This is the file user has to setup locally for different host environment |
| 4 | # |
| 5 | # @param VOBJ object files applicable for compilation |
| 6 | # @param LOBJ object files included in lib$(NAME).a |
| 7 | # @param COBJ object files applicable to standard-make-targets |
| 8 | # |
| 9 | # @author Howard Chen |
| 10 | ## |
| 11 | GCC ?= $(CROSS)gcc |
| 12 | CC ?= $(GCC) |
| 13 | CXX ?= $(CROSS)g++ |
| 14 | OBJDUMP = $(CROSS)objdump |
| 15 | OBJCOPY = $(CROSS)objcopy |
| 16 | AR = $(CROSS)ar |
| 17 | |
| 18 | SUBLPATH?= $(SUBVPATH) |
| 19 | INCLUDE ?= $(DEF_INCLUDE) |
| 20 | CFLAGS ?= $(DEF_CFLAGS) |
| 21 | ASFLAGS ?= $(DEF_ASFLAGS) |
| 22 | LDFLAGS ?= $(DEF_LDFLAGS) |
| 23 | DOC_GEN ?= $(PREFIX)/APITemp.txt |
| 24 | |
| 25 | VPATH ?= src $(SUBVPATH) |
| 26 | VOBJ ?= $(patsubst %.S,%.o, \ |
| 27 | $(patsubst %.s,%.o, \ |
| 28 | $(patsubst %.c,%.o, \ |
| 29 | $(patsubst %.cpp, %.o, \ |
| 30 | $(notdir $(foreach DIR,$(VPATH),\ |
| 31 | $(wildcard $(DIR)/*.S) \ |
| 32 | $(wildcard $(DIR)/*.s) \ |
| 33 | $(wildcard $(DIR)/*.c) \ |
| 34 | $(wildcard $(DIR)/*.cpp))))))) |
| 35 | |
| 36 | LPATH ?= src $(SUBLPATH) |
| 37 | LOBJ ?= $(patsubst %.S,%.o, \ |
| 38 | $(patsubst %.s,%.o, \ |
| 39 | $(patsubst %.c,%.o, \ |
| 40 | $(patsubst %.cpp, %.o, \ |
| 41 | $(notdir $(foreach DIR,$(LPATH),\ |
| 42 | $(wildcard $(DIR)/*.S) \ |
| 43 | $(wildcard $(DIR)/*.s) \ |
| 44 | $(wildcard $(DIR)/*.c) \ |
| 45 | $(wildcard $(DIR)/*.cpp))))))) |
| 46 | COBJ ?= $(patsubst %.c,%.o, \ |
| 47 | $(patsubst %.cpp, %.o, \ |
| 48 | $(notdir $(foreach DIR,$(VPATH),\ |
| 49 | $(wildcard $(DIR)/*.c) \ |
| 50 | $(wildcard $(DIR)/*.cpp))))) |
| 51 | DEP = $(COBJ:%.o=%.d) |
| 52 | TEST = $(COBJ:%.o=%.x) |
| 53 | RUNS = $(COBJ:%.o=%.x.run) |
| 54 | |
| 55 | MIN ?=1 |
| 56 | |
| 57 | default: all |
| 58 | |
| 59 | %.d: %.cpp |
| 60 | @wimac_conf.pl $(NAME) "$(CONFIG)" |
| 61 | ifeq ($(strip $(STRICT)),1) |
| 62 | @wimac_rul.sh $< |
| 63 | endif |
| 64 | @$(GCC) -M $(INCLUDE) -D _UNIT_ -D _EXE_ $(CONFIG) $< > $@ |
| 65 | |
| 66 | %.d: %.c |
| 67 | @wimac_conf.pl $(NAME) "$(CONFIG)" |
| 68 | ifeq ($(strip $(STRICT)),1) |
| 69 | @wimac_rul.sh $< |
| 70 | endif |
| 71 | #ifeq ($(strip $(MAKE_INDEX)),1) |
| 72 | # @wimac_parse_idx.sh $< |
| 73 | #endif |
| 74 | @$(GCC) -M $(INCLUDE) $(CFLAGS) -D _UNIT_ -D _EXE_ $(CONFIG) $< > $@ |
| 75 | |
| 76 | %.e : %.cpp %.d |
| 77 | $(CXX) $(INCLUDE) $(CONFIG) -E $< > $(notdir $(<:%.cpp=%.e.cpp)) |
| 78 | |
| 79 | %.e : %.c %.d |
| 80 | $(CC) $(CFLAGS) $(INCLUDE) $(CONFIG) -E $< > $(notdir $(<:%.c=%.e.c)) |
| 81 | |
| 82 | %.o : %.cpp %.d |
| 83 | $(CXX) $(CXXFLAGS) $(INCLUDE) $(CONFIG) -c $< |
| 84 | |
| 85 | %.o : %.c %.d |
| 86 | $(CC) $(CFLAGS) $(INCLUDE) $(CONFIG) -c $< |
| 87 | |
| 88 | %.o: %.S |
| 89 | $(GCC) $(ASFLAGS) $(INCLUDE) $(CONFIG) -c $< |
| 90 | |
| 91 | %.o: %.s |
| 92 | $(GCC) $(ASFLAGS) $(INCLUDE) $(CONFIG) -c -x assembler-with-cpp $< |
| 93 | |
| 94 | %.o.text: %.o |
| 95 | $(CROSS)objdump -DS $^ > $@ |
| 96 | |
| 97 | %.exe: %.elf |
| 98 | @cp $^ $@ |
| 99 | |
| 100 | %.elf: %.c $(LIB) |
| 101 | $(CC) $(CFLAGS) $(INCLUDE) $(CONFIG) -D _EXE_ -o $(notdir $(<:%.c=%.e.o)) -c $< |
| 102 | $(GCC) -o $@ $(notdir $(<:%.c=%.e.o)) $(LDFLAGS) |
| 103 | |
| 104 | %.elf: %.cpp $(LIB) |
| 105 | $(CC) $(CXXFLAGS) $(INCLUDE) $(CONFIG) -D _EXE_ -o $(notdir $(<:%.cpp=%.e.o)) -c $< |
| 106 | $(GCC) -o $@ $(notdir $(<:%.cpp=%.e.o)) $(LDFLAGS) |
| 107 | |
| 108 | %.elf.run: |
| 109 | @echo "" |
| 110 | @printf "%s%-8s%s\n" "-----[ " "$(@:%.elf.run=%)" " ]------------------------------------------------------" |
| 111 | @echo "" |
| 112 | $(RUN)$(@:%.x.run=%.x) |
| 113 | |
| 114 | %.elf.debug: %.elf |
| 115 | ddd --debugger $(CROSS)gdb $^ |
| 116 | |
| 117 | %.elf.text: %.elf |
| 118 | $(CROSS)objdump -DS $^ > $@ |
| 119 | |
| 120 | %.elf.srec: %.elf |
| 121 | $(CROSS)objcopy -Osrec $^ $@ |
| 122 | |
| 123 | %.elf.hex8: %.elf.srec |
| 124 | srec2hex.exe $^ -p $(HEXPAD) > $@ |
| 125 | |
| 126 | %.elf.hex16: %.elf.srec |
| 127 | srec2hex.exe $^ -p $(HEXPAD) -2 > $@ |
| 128 | |
| 129 | %.elf.hex32: %.elf.srec |
| 130 | srec2hex.exe $^ -p $(HEXPAD) -4 > $@ |
| 131 | |
| 132 | %.elf.img: %.elf |
| 133 | $(OBJCOPY) --strip-debug $^ $@ |
| 134 | |
| 135 | %.elf.bin: %.elf.img |
| 136 | $(OBJCOPY) -O binary $^ $@ |
| 137 | |
| 138 | %.elf.bin.gz: %.elf.bin |
| 139 | gzip -c $^ > $@ |
| 140 | |
| 141 | %.elf.verilog: |
| 142 | @rm -f $(@:%.elf.verilog=%.elf) |
| 143 | @make $(@:%.elf.verilog=%.elf.text) LD_SCRIPT=-Tverilog.ld |
| 144 | @make $(@:%.elf.verilog=%.elf.hex8) LD_SCRIPT=-Tverilog.ld |
| 145 | @make $(@:%.elf.verilog=%.elf.hex16) LD_SCRIPT=-Tverilog.ld |
| 146 | @make $(@:%.elf.verilog=%.elf.hex32) LD_SCRIPT=-Tverilog.ld |
| 147 | |
| 148 | %.elf.sim %.elf.sim.dual %.elf.sim.app: |
| 149 | @rm -f $*.elf; \ |
| 150 | if [ $(NAME) == "base" ]; then \ |
| 151 | startup=startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \ |
| 152 | else \ |
| 153 | startup=$(ROOT)/${base_libdir}/startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \ |
| 154 | fi; \ |
| 155 | make $*.elf.text DEP_LIBS="$(SIM_LIBS)" STARTUP=$$startup LD_SCRIPT=-Tsim$(filter app,$(subst .,,$(suffix $@))).ld; \ |
| 156 | wimac_gen_sim.sh $*.elf |
| 157 | |
| 158 | %.x: %.c $(LIB) |
| 159 | $(CC) $(CFLAGS) $(INCLUDE) $(CONFIG) -D _UNIT_ -o $(notdir $(<:%.c=%.x.o)) -c $< |
| 160 | ifeq ($(strip $(STRICT)),1) |
| 161 | $(CROSS)nm $(notdir $(<:%.c=%.x.o)) | grep main |
| 162 | endif |
| 163 | $(GCC) -o $@ $(notdir $(<:%.c=%.x.o)) $(LDFLAGS) |
| 164 | |
| 165 | %.x: %.cpp $(LIB) |
| 166 | $(CC) $(CXXFLAGS) $(INCLUDE) $(CONFIG) -D _UNIT_ -o $(notdir $(<:%.cpp=%.x.o)) -c $< |
| 167 | $(CXX) -o $@ $(notdir $(<:%.cpp=%.x.o)) $(LDFLAGS) |
| 168 | |
| 169 | %.x.run: |
| 170 | @echo "" |
| 171 | @printf "%s%-8s%s\n" "-----[ " "$(@:%.x.run=%)" " ]------------------------------------------------------" |
| 172 | @echo "" |
| 173 | $(RUN)$(@:%.x.run=%.x) |
| 174 | |
| 175 | %.x.debug: %.x |
| 176 | ddd --debugger $(CROSS)gdb $^ |
| 177 | |
| 178 | %.x.text: %.x |
| 179 | $(CROSS)objdump -DS $^ > $@ |
| 180 | |
| 181 | %.x.srec: %.x |
| 182 | $(CROSS)objcopy -Osrec $^ $@ |
| 183 | |
| 184 | %.x.hex8: %.x.srec |
| 185 | srec2hex.exe $^ -p $(HEXPAD) > $@ |
| 186 | |
| 187 | %.x.hex16: %.x.srec |
| 188 | srec2hex.exe $^ -p $(HEXPAD) -2 > $@ |
| 189 | |
| 190 | %.x.hex32: %.x.srec |
| 191 | srec2hex.exe $^ -p $(HEXPAD) -4 > $@ |
| 192 | |
| 193 | %.x.img: %.x |
| 194 | $(OBJCOPY) --strip-debug $< $@ |
| 195 | |
| 196 | %.x.bin: %.x.img |
| 197 | $(OBJCOPY) -O binary $< $@ |
| 198 | |
| 199 | %.x.bin.gz: %.x.bin |
| 200 | gzip -c $^ > $@ |
| 201 | |
| 202 | %.x.verilog: |
| 203 | @rm -f $(@:%.x.verilog=%.x) |
| 204 | @make $(@:%.x.verilog=%.x.text) LD_SCRIPT=-Tverilog.ld |
| 205 | @make $(@:%.x.verilog=%.x.hex8) LD_SCRIPT=-Tverilog.ld |
| 206 | @make $(@:%.x.verilog=%.x.hex16) LD_SCRIPT=-Tverilog.ld |
| 207 | @make $(@:%.x.verilog=%.x.hex32) LD_SCRIPT=-Tverilog.ld |
| 208 | |
| 209 | %.x.sim %.x.sim.dual %.x.sim.app: |
| 210 | @rm -f $*.x; \ |
| 211 | if [ $(NAME) == "base" ]; then \ |
| 212 | startup=startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \ |
| 213 | else \ |
| 214 | startup=$(ROOT)/${base_libdir}/startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \ |
| 215 | fi; \ |
| 216 | make $*.x.text DEP_LIBS="$(SIM_LIBS)" STARTUP=$$startup LD_SCRIPT=-Tsim$(filter app,$(subst .,,$(suffix $@))).ld; \ |
| 217 | wimac_gen_sim.sh $*.x |
| 218 | |
| 219 | sinclude $(DEP) |
| 220 | |
| 221 | lib$(NAME).a:$(LOBJ) |
| 222 | $(AR) r $@ $? |
| 223 | |
| 224 | lib$(NAME).so:$(LOBJ) |
| 225 | @rm -f $@ |
| 226 | $(GCC) -shared -o _$@ $^ $(LDFLAGS) |
| 227 | @mv _$@ $@ |
| 228 | |
| 229 | $(NAME).dll:$(LOBJ) |
| 230 | $(CROSS)dlltool $(LOBJ) --export-all-symbols --output-def $(NAME).def |
| 231 | $(CROSS)dllwrap $(LOBJ) -def $(NAME).def -o $@ $(LDFLAGS) |
| 232 | |
| 233 | $(NAME).lib:$(NAME).dll |
| 234 | $(CROSS)dlltool --def $(NAME).def --output-lib $(NAME).lib |
| 235 | |
| 236 | signature.text: |
| 237 | @bash -c 'if [ "$(CROSS)" == "" ] ; then \ |
| 238 | echo "native" > signature.text; \ |
| 239 | else \ |
| 240 | echo $(CROSS) > signature.text; \ |
| 241 | fi' |
| 242 | |
| 243 | .PHONY:_dep_check _signature info.text |
| 244 | _dep_check: |
| 245 | @echo "" |
| 246 | @echo "dependency checking" |
| 247 | @bash -c 'for d in $(DEP_LIBS); do\ |
| 248 | if [ "$$(echo $(LIB) | grep lib$$d.a)" != "" ] || \ |
| 249 | [ "$$(echo $(LIB) | grep $$d.dll)" != "" ] || \ |
| 250 | [ "$$(echo $(LIB) | grep lib$$d.so)" != "" ]; then\ |
| 251 | continue; \ |
| 252 | elif [ ! -f $(ROOT)/${base_libdir}/lib$$d.a ] && \ |
| 253 | [ ! -f $(ROOT)/${base_libdir}/$$d.dll ] && \ |
| 254 | [ ! -f $(ROOT)/${base_libdir}/lib$$d.so ] && \ |
| 255 | [ ! -f $(ROOT)/${libdir}/lib$$d.a ] && \ |
| 256 | [ ! -f $(ROOT)/${libdir}/$$d.dll ] && \ |
| 257 | [ ! -f $(ROOT)/${libdir}/lib$$d.so ] ; then\ |
| 258 | echo "[NO INSTALL]: $$d"; \ |
| 259 | echo " "; \ |
| 260 | exit 1;\ |
| 261 | else \ |
| 262 | echo "[INSTALLED]: $$d "; \ |
| 263 | fi; \ |
| 264 | done' |
| 265 | @bash -c 'for d in $(DEP_MODS); do\ |
| 266 | if [ -e $(ROOT)/usr/include/asm/arch/$(DEP_MODS) ]; then\ |
| 267 | echo "[INSTALLED]: mod-$$d"; \ |
| 268 | else \ |
| 269 | echo "[NO INSTALL]: mod-$$d"; \ |
| 270 | exit 1;\ |
| 271 | fi;\ |
| 272 | done' |
| 273 | |
| 274 | _signature: signature.text |
| 275 | @bash -c 'if [ "$(CROSS)" == "" ] ; then \ |
| 276 | export cross=native; \ |
| 277 | else \ |
| 278 | export cross=$(CROSS) ;\ |
| 279 | fi ; \ |
| 280 | if [ "`cat signature.text | grep $$cross `" == "" ]; then\ |
| 281 | echo "target conflict!!"; \ |
| 282 | echo -n "original: "; \ |
| 283 | cat signature.text; \ |
| 284 | echo "current: $$cross"; \ |
| 285 | exit 1;\ |
| 286 | fi' |
| 287 | |
| 288 | info.text: |
| 289 | ifeq ($(strip $(DEP_LIBS_AUTO)),1) |
| 290 | @echo DEP_LIBS=$(shell wimac_dep.sh $(NAME) "$(DEP_LIBS)" "$(DEP_LIBS_EX)") > $@ |
| 291 | else |
| 292 | @echo DEP_LIBS=$(DEP_LIBS) > $@ |
| 293 | endif |
| 294 | |
| 295 | _config: |
| 296 | @wimac_conf.pl $(NAME) "$(CONFIG)" |
| 297 | |
| 298 | all: _dep_check signature.text _signature _config $(ALL) lib |
| 299 | |
| 300 | gen_dir: |
| 301 | mkdir -p $(ROOT)/bin |
| 302 | mkdir -p $(ROOT)/${base_libdir} |
| 303 | mkdir -p $(ROOT)/include/$(NAME) |
| 304 | ifeq ($(strip $(MIN)),1) |
| 305 | mkdir -p $(ROOT)/doc |
| 306 | else |
| 307 | mkdir -p $(ROOT)/doc/$(NAME) |
| 308 | endif |
| 309 | |
| 310 | mkdir -p $(ROOT)/test/$(NAME) |
| 311 | ifeq ($(strip $(MAKE_INDEX)),1) |
| 312 | mkdir -p $(ROOT)/doc/index/$(NAME) |
| 313 | endif |
| 314 | |
| 315 | ifeq ($(strip $(MLOG_MODULE)),1) |
| 316 | ifneq ($(shell echo $(CROSS) | grep -e "arm-none-linux-"),) |
| 317 | .PHONY:mlog_cksrc |
| 318 | mlog_cksrc: |
| 319 | @$(PREFIX)/bin/mlog.pl -C |
| 320 | .PHONY:mlog_parse |
| 321 | mlog_parse: |
| 322 | @$(PREFIX)/bin/mlog.pl -P |
| 323 | endif |
| 324 | endif |
| 325 | |
| 326 | #install: all doc gen_dir $(INSTALL) |
| 327 | install: doc gen_dir $(INSTALL) |
| 328 | rm -f $(ROOT)/${base_libdir}/lib$(NAME).* $(ROOT)/${base_libdir}/$(NAME).dll |
| 329 | ifneq ($(strip $(LIB)), dummy) |
| 330 | install -p $(LIB) $(ROOT)/${base_libdir}/ |
| 331 | endif |
| 332 | bash -c 'if ls *.x > /dev/null 2>&1 ; then install *.x $(ROOT)/test/$(NAME); fi' |
| 333 | bash -c 'if [ -e include ]; then rm -rf $(ROOT)/include/$(NAME)/*; cp -r include/* $(ROOT)/include/$(NAME)/; fi' |
| 334 | ifeq ($(strip $(MIN)),1) |
| 335 | else |
| 336 | install -p doc/html/* $(ROOT)/doc/$(NAME)/ |
| 337 | endif |
| 338 | cp module.files $(ROOT)/doc/$(NAME).files |
| 339 | cp info.text $(ROOT)/doc/$(NAME).info |
| 340 | ifeq ($(strip $(MAKE_INDEX)),1) |
| 341 | wimac_gen_idx.sh $(ROOT) $(NAME) |
| 342 | endif |
| 343 | ifeq ($(strip $(MLOG_MODULE)),1) |
| 344 | ifneq ($(shell echo $(CROSS) | grep -e "arm-none-linux-"),) |
| 345 | @$(PREFIX)/bin/mlog.pl -P |
| 346 | endif |
| 347 | endif |
| 348 | |
| 349 | lib: $(LIB) |
| 350 | @echo "[lib ] done" |
| 351 | |
| 352 | test.list.text: |
| 353 | @wimac_tst.sh |
| 354 | |
| 355 | test: $(TEST) test.list.text |
| 356 | @echo "[test] done" |
| 357 | |
| 358 | testrun: $(COBJ:%.o=%.x.run) |
| 359 | @echo "[testrun] done" |
| 360 | |
| 361 | run: $(RUNS) |
| 362 | @echo "[run] done" |
| 363 | |
| 364 | clean: $(CLEAN) |
| 365 | rm -f include/conf_$(NAME).h *.o *.so *.files *.a *.x *.lib *.def *.dll *.elf *.d *.text *.img *.srec *.bin *.hex *.short *.hex8 |
| 366 | rm -rf doc index |
| 367 | |
| 368 | ifeq ($(strip $(MIN)),1) |
| 369 | doc: info.text module.files |
| 370 | @touch module.files |
| 371 | # @mkdir -p doc/html && touch doc/html/index.html |
| 372 | else |
| 373 | doc: info.text module.files $(wildcard include/*.h) $(DOC_GEN) $(DOC) |
| 374 | mkdir -p doc include |
| 375 | cat $(DOC_GEN) | sed -e 's/PNAME/lib$(NAME)/' > API.text |
| 376 | doxygen API.text |
| 377 | mkdir -p $(ROOT)/doc |
| 378 | wimac_doc.sh $(ROOT) > $(ROOT)/doc/index.html |
| 379 | endif |
| 380 | |
| 381 | indent: |
| 382 | indent -kr -i8 `find -name "*.[h,c]"` |
| 383 | |
| 384 | module.files: |
| 385 | -find `pwd`/src `pwd`/include -name "*.h" -or -name "*.hxx" -or -name "*.[cCsS]" \ |
| 386 | -or -name "*.cxx" -or -name "*.cpp" -or -name "*.inl" > module.files |
| 387 | |
| 388 | index:module.files |
| 389 | @bash -c 'rm -f cscope.files ; \ |
| 390 | LIST=$$(ls $(ROOT)/doc/*.files 2>/dev/null) ; \ |
| 391 | for T in $$LIST; do \ |
| 392 | if [ $$T != $(ROOT)/doc/$(NAME).files ]; then \ |
| 393 | cat $$T >> cscope.files; \ |
| 394 | fi ; \ |
| 395 | done' |
| 396 | cat module.files >> cscope.files |
| 397 | cscope -b -c -icscope.files |
| 398 | |
| 399 | alltargets: |
| 400 | @bash -c 'for T in $(CROSS_SUP) ; \ |
| 401 | do \ |
| 402 | T=$${T#native}; \ |
| 403 | echo "building CROSS=$$T" ;\ |
| 404 | make clean || exit 1 ;\ |
| 405 | make install CROSS=$$T || exit 1 ;\ |
| 406 | done; \ |
| 407 | make clean || exit 1' |
| 408 | |
| 409 | target: |
| 410 | @bash -c 'select T in $(CROSS_SUP); do \ |
| 411 | if [ $$T ] ; then \ |
| 412 | break; \ |
| 413 | else \ |
| 414 | echo "invalid target"; \ |
| 415 | fi ; \ |
| 416 | done; \ |
| 417 | if [ "$$T" = "native" ] ; then\ |
| 418 | T=; \ |
| 419 | fi; \ |
| 420 | echo "building CROSS=$$T"; \ |
| 421 | make clean || exit 1;\ |
| 422 | make CROSS=$$T || exit 1;\ |
| 423 | make install CROSS=$$T || exit 1;\ |
| 424 | make clean || exit 1' |
| 425 | |
| 426 | auto_dep: |
| 427 | @wimac_auto.sh $(ROOT) "$(DEP_LIBS)" "$(LIB)" $(NAME) $(CROSS) |
| 428 | |
| 429 | auto: auto_dep all |
| 430 | |
| 431 | info: |
| 432 | @echo -n "current : " |
| 433 | @echo DEP_LIBS=$(DEP_LIBS) |
| 434 | @echo -n "calculated : DEP_LIBS=" |
| 435 | @wimac_dep.sh $(NAME) "$(DEP_LIBS)" "$(DEP_LIBS_EX)" |
| 436 | |
| 437 | var: |
| 438 | @echo '$(VAR)' |
| 439 | |
| 440 | nfs_export: |
| 441 | wimac_nfsexport.sh |