blob: 3b51a2a1206d199f8dde96fef0746325c023ec93 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001###
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##
11GCC ?= $(CROSS)gcc
12CC ?= $(GCC)
13CXX ?= $(CROSS)g++
14OBJDUMP = $(CROSS)objdump
15OBJCOPY = $(CROSS)objcopy
16AR = $(CROSS)ar
17
18SUBLPATH?= $(SUBVPATH)
19INCLUDE ?= $(DEF_INCLUDE)
20CFLAGS ?= $(DEF_CFLAGS)
21ASFLAGS ?= $(DEF_ASFLAGS)
22LDFLAGS ?= $(DEF_LDFLAGS)
23DOC_GEN ?= $(PREFIX)/APITemp.txt
24
25VPATH ?= src $(SUBVPATH)
26VOBJ ?= $(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
36LPATH ?= src $(SUBLPATH)
37LOBJ ?= $(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)))))))
46COBJ ?= $(patsubst %.c,%.o, \
47 $(patsubst %.cpp, %.o, \
48 $(notdir $(foreach DIR,$(VPATH),\
49 $(wildcard $(DIR)/*.c) \
50 $(wildcard $(DIR)/*.cpp)))))
51DEP = $(COBJ:%.o=%.d)
52TEST = $(COBJ:%.o=%.x)
53RUNS = $(COBJ:%.o=%.x.run)
54
55MIN ?=1
56
57default: all
58
59%.d: %.cpp
60 @wimac_conf.pl $(NAME) "$(CONFIG)"
61ifeq ($(strip $(STRICT)),1)
62 @wimac_rul.sh $<
63endif
64 @$(GCC) -M $(INCLUDE) -D _UNIT_ -D _EXE_ $(CONFIG) $< > $@
65
66%.d: %.c
67 @wimac_conf.pl $(NAME) "$(CONFIG)"
68ifeq ($(strip $(STRICT)),1)
69 @wimac_rul.sh $<
70endif
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; \
150if [ $(NAME) == "base" ]; then \
151 startup=startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \
152else \
153 startup=$(ROOT)/${base_libdir}/startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \
154fi; \
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 $<
160ifeq ($(strip $(STRICT)),1)
161 $(CROSS)nm $(notdir $(<:%.c=%.x.o)) | grep main
162endif
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; \
211if [ $(NAME) == "base" ]; then \
212 startup=startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \
213else \
214 startup=$(ROOT)/${base_libdir}/startupsim$(subst .,_,$(subst .sim,,$(suffix $@))).o; \
215fi; \
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
219sinclude $(DEP)
220
221lib$(NAME).a:$(LOBJ)
222 $(AR) r $@ $?
223
224lib$(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
236signature.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
288info.text:
289ifeq ($(strip $(DEP_LIBS_AUTO)),1)
290 @echo DEP_LIBS=$(shell wimac_dep.sh $(NAME) "$(DEP_LIBS)" "$(DEP_LIBS_EX)") > $@
291else
292 @echo DEP_LIBS=$(DEP_LIBS) > $@
293endif
294
295_config:
296 @wimac_conf.pl $(NAME) "$(CONFIG)"
297
298all: _dep_check signature.text _signature _config $(ALL) lib
299
300gen_dir:
301 mkdir -p $(ROOT)/bin
302 mkdir -p $(ROOT)/${base_libdir}
303 mkdir -p $(ROOT)/include/$(NAME)
304ifeq ($(strip $(MIN)),1)
305 mkdir -p $(ROOT)/doc
306else
307 mkdir -p $(ROOT)/doc/$(NAME)
308endif
309
310 mkdir -p $(ROOT)/test/$(NAME)
311ifeq ($(strip $(MAKE_INDEX)),1)
312 mkdir -p $(ROOT)/doc/index/$(NAME)
313endif
314
315ifeq ($(strip $(MLOG_MODULE)),1)
316ifneq ($(shell echo $(CROSS) | grep -e "arm-none-linux-"),)
317.PHONY:mlog_cksrc
318mlog_cksrc:
319 @$(PREFIX)/bin/mlog.pl -C
320.PHONY:mlog_parse
321mlog_parse:
322 @$(PREFIX)/bin/mlog.pl -P
323endif
324endif
325
326#install: all doc gen_dir $(INSTALL)
327install: doc gen_dir $(INSTALL)
328 rm -f $(ROOT)/${base_libdir}/lib$(NAME).* $(ROOT)/${base_libdir}/$(NAME).dll
329ifneq ($(strip $(LIB)), dummy)
330 install -p $(LIB) $(ROOT)/${base_libdir}/
331endif
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'
334ifeq ($(strip $(MIN)),1)
335else
336 install -p doc/html/* $(ROOT)/doc/$(NAME)/
337endif
338 cp module.files $(ROOT)/doc/$(NAME).files
339 cp info.text $(ROOT)/doc/$(NAME).info
340ifeq ($(strip $(MAKE_INDEX)),1)
341 wimac_gen_idx.sh $(ROOT) $(NAME)
342endif
343ifeq ($(strip $(MLOG_MODULE)),1)
344ifneq ($(shell echo $(CROSS) | grep -e "arm-none-linux-"),)
345 @$(PREFIX)/bin/mlog.pl -P
346endif
347endif
348
349lib: $(LIB)
350 @echo "[lib ] done"
351
352test.list.text:
353 @wimac_tst.sh
354
355test: $(TEST) test.list.text
356 @echo "[test] done"
357
358testrun: $(COBJ:%.o=%.x.run)
359 @echo "[testrun] done"
360
361run: $(RUNS)
362 @echo "[run] done"
363
364clean: $(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
368ifeq ($(strip $(MIN)),1)
369doc: info.text module.files
370 @touch module.files
371# @mkdir -p doc/html && touch doc/html/index.html
372else
373doc: 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
379endif
380
381indent:
382 indent -kr -i8 `find -name "*.[h,c]"`
383
384module.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
388index: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
399alltargets:
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
409target:
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
426auto_dep:
427 @wimac_auto.sh $(ROOT) "$(DEP_LIBS)" "$(LIB)" $(NAME) $(CROSS)
428
429auto: auto_dep all
430
431info:
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
437var:
438 @echo '$(VAR)'
439
440nfs_export:
441 wimac_nfsexport.sh