fw/layer1: Add common TPU win setup/cleanup code
[osmocom-bb.git] / src / target / firmware / Makefile.inc
index b3b64a6..11c63ec 100644 (file)
@@ -15,18 +15,14 @@ CFLAGS=-mcpu=arm7tdmi $(INCLUDES)
 CFLAGS += -Wall -Wextra -Wcast-align -Wimplicit -Wunused
 CFLAGS += -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wnested-externs
 CFLAGS += -Wbad-function-cast -Wsign-compare -Waggregate-return
-CFLAGS += -Wa,-adhlns=$(subst $(suffix $<),.lst,$<)
 CFLAGS += -Os -ffunction-sections
 CFLAGS += -g$(DEBUGF)
 
-# Uncomment this line if you want to enable Tx (Transmit) Support.
-#CFLAGS += -DCONFIG_TX_ENABLE
-
 # some older toolchains don't support this, ignore it for now
-#ASFLAGS=-Wa,-adhlns=$(<:.S=.lst),--g$(DEBUGF) $(INCLUDES) -D__ASSEMBLY__
-ASFLAGS=-Wa,-adhlns=$(<:.S=.lst) $(INCLUDES) -D__ASSEMBLY__
+#ASFLAGS=--g$(DEBUGF) $(INCLUDES) -D__ASSEMBLY__
+ASFLAGS=$(INCLUDES) -D__ASSEMBLY__
 
-LDFLAGS = -nostartfiles -nostdlib -nodefaultlibs --gc-sections #-Wl,-Map=$(TARGET).map,--cref
+LDFLAGS = -nostartfiles -nostdlib -nodefaultlibs --gc-sections --cref
 
 #### GIT VERSION ####
 
@@ -41,15 +37,15 @@ CFLAGS += -DGIT_REVISION=\"$(GIT_REVISION)\"
 #### GLOBAL DATA ####
 
 ALL_OBJS=
-ALL_DEPS=
 
 ALL_LSTS=$(ALL_OBJS:.o=.lst)
+ALL_DEPS=$(ALL_OBJS:.o=.p)
 
 #### APPLICATION DATA ####
 
 ALL_APPS=
 
-ALL_APP_TARGETS=$(ALL_APPS) $(ALL_APPS:.elf=.bin) $(ALL_APPS:.elf=.map) $(ALL_APPS:.elf=.size)
+ALL_APP_TARGETS=$(ALL_APPS:.elf=.bin) $(ALL_APPS:.elf=.size) $(ALL_APPS) $(ALL_APPS:.elf=.map)
 
 #### LIBRARY DATA ####
 
@@ -66,48 +62,53 @@ default: all
 
 #### APPLICATION RULES ####
 
-ALL_OBJS+=$(ANY_APP_OBJS)
-ALL_DEPS+=$(ANY_APP_OBJS:.o=.p)
-
 # template for application rules
 define APPLICATION_BOARD_ENVIRONMENT_template
 
 # define set of objects for this binary
-$(1)_$(2)_$(3)_OBJS := apps/$(1)/main.o $(ANY_APP_OBJS) $(ANY_APP_LIBS) $$($(2)_OBJS)
+$(1)_$(2)_$(3)_OBJS := apps/$(1)/main.o $(ANY_APP_OBJS) $$($(2)_OBJS)
+$(1)_$(2)_$(3)_LIBS := $(ANY_APP_LIBS)
 
 # define manifest compilation
 board/$(2)/$(1).$(3).manifest.o: board/manifest.c
-       $(CROSS_COMPILE)$(CC) $(CFLAGS) -DAPPLICATION=\"$(3)\" -DBOARD=\"$(2)\" -DENVIRONMENT=\"$(3)\" -c -o $$@ $$<
+       $(CROSS_COMPILE)$(CC) $(CFLAGS) -DAPPLICATION=\"$(1)\" -DBOARD=\"$(2)\" -DENVIRONMENT=\"$(3)\" -c -o $$@ $$<
+
+# generate dummy dependencies for manifest
+board/$(2)/$(1).$(3).manifest.p: board/manifest.c
+       @touch board/$(2)/$(1).$(3).manifest.p
 
 # add manifest object to object list
-$(1)_$(2)_$(3)_OBJS+=board/$(2)/$(1).$(3).manifest.o
+$(1)_$(2)_$(3)_OBJS+=board/$(2)/$(1).$(3).manifest.o $$($(3)_OBJS)
 
-# define compilation, generating various extra files on the way
-board/$(2)/$(1).$(3).elf board/$(2)/$(1).$(3).map board/$(2)/$(1).$(3).size: $$($(1)_$(2)_$(3)_OBJS) $$($(3)_LDS)
+# define compilation rule, also generates map file
+board/$(2)/$(1).$(3).elf board/$(2)/$(1).$(3).map: $$($(1)_$(2)_$(3)_OBJS) $$($(1)_$(2)_$(3)_LIBS) $$($(3)_LDS)
        $(CROSS_COMPILE)$(LD) $(LDFLAGS) -T $$($(3)_LDS) -Bstatic \
                -Map board/$(2)/$(1).$(3).map -o board/$(2)/$(1).$(3).elf \
-               --start-group $$($(1)_$(2)_$(3)_OBJS) --end-group
+               --start-group $$($(1)_$(2)_$(3)_OBJS) $$($(1)_$(2)_$(3)_LIBS) --end-group
+
+# define size rule
+board/$(2)/$(1).$(3).size: board/$(2)/$(1).$(3).elf
        $(CROSS_COMPILE)$(SIZE) board/$(2)/$(1).$(3).elf | tee board/$(2)/$(1).$(3).size
 
 ALL_APPS+=board/$(2)/$(1).$(3).elf
+ALL_OBJS+=board/$(2)/$(1).$(3).manifest.o
 
 endef
 
 define BOARD_template
-
 ALL_OBJS+=$$($(1)_OBJS)
+endef
 
+define BOARD_ENVIRONMENT_template
+ALL_OBJS+=$$($(1)_OBJS)
 endef
 
 define APPLICATION_template
-
 $(1)_SRCS_REL=$$(patsubst %,$$($(1)_DIR)/%,$$($(1)_SRCS))
 $(1)_OBJS:=$$($(1)_SRCS_REL:.c=.o)
 $(1)_OBJS:=$$($(1)_OBJS:.S=.o)
 
 ALL_OBJS+=$$($(1)_OBJS) apps/$(1)/main.o
-ALL_DEPS+=$$($(1)_OBJS:.o=.p) apps/$(1)/main.p
-
 endef
 
 # define rules for all defined applications
@@ -117,12 +118,17 @@ $(foreach app,$(APPLICATIONS),                \
                        $(eval $(call APPLICATION_BOARD_ENVIRONMENT_template,$(app),$(brd),$(env))))))
 
 $(foreach brd,$(BOARDS), \
-       $(eval $(call BOARD_template,$(brd))))
+       $(eval $(call BOARD_template,$(brd)) \
+    $(foreach env,$($(brd)_ENVIRONMENTS), \
+           $(eval $(call BOARD_ENVIRONMENT_template,$(env))))))
 
 $(foreach app,$(APPLICATIONS), \
        $(eval $(call APPLICATION_template,$(app))))
 
 
+# add common things to global lists
+ALL_OBJS+=$(ANY_APP_OBJS)
+
 #### LIBRARY RULES ####
 
 # template for library rules
@@ -138,7 +144,6 @@ $$($(1)_DIR)/lib$(1).a: $$($(1)_OBJS)
 ALL_LIBS+=$$($(1)_DIR)/lib$(1).a
 
 ALL_OBJS+=$$($(1)_OBJS)
-ALL_DEPS+=$$($(1)_OBJS:.o=.p)
 
 endef
 
@@ -149,7 +154,7 @@ $(foreach lbr,$(LIBRARIES),$(eval $(call LIBRARY_template,$(lbr))))
 #### TOPLEVEL RULES ####
 
 .PHONY: all
-all: $(ALL_DEPS) $(ALL_APP_TARGETS) $(ALL_LIB_TARGETS)
+all: $(ALL_DEPS) $(ALL_APPS:.elf=.bin) $(ALL_APPS:.elf=.size)
 
 .PHONY: depend
 depend: $(ALL_DEPS)
@@ -166,10 +171,10 @@ depend: $(ALL_DEPS)
        @sed 's|.*\.o:|$(@:.p=.o): |g' < $*.d > $@; rm -f $*.d; [ -s $@ ] || rm -f $@
 
 %.o: %.c
-       $(CROSS_COMPILE)$(CC) $(CFLAGS) -c -o $@ $<
+       $(CROSS_COMPILE)$(CC) $(CFLAGS) -Wa,-adhlns=$(@:.o=.lst) -c -o $@ $<
 
 %.o: %.S
-       $(CROSS_COMPILE)$(CC) $(ASFLAGS) -c -o $@ $<
+       $(CROSS_COMPILE)$(CC) $(ASFLAGS) -Wa,-adhlns=$(@:.o=.lst) -c -o $@ $<
 
 
 %.bin: %.elf