Skip to content

Commit

Permalink
Make: de-duplicate some code
Browse files Browse the repository at this point in the history
  • Loading branch information
tracernz committed Dec 6, 2015
1 parent 8a5fd81 commit 5dab284
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 48 deletions.
54 changes: 11 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -760,34 +760,22 @@ endef
# $(1) = Canonical board name all in lower case (e.g. coptercontrol)
# $(2) = Friendly board name
# $(3) = Short board name
# $(4) = BL for bootloader or NOBL for no bootloader
# $(4) = yes for bootloader, no for no bootloader
define EF_TEMPLATE
.PHONY: ef_$(1)
ef_$(1): ef_$(1)_bin ef_$(1)_hex

ef_$(1)_%: TARGET=ef_$(1)
ef_$(1)_%: OUTDIR=$(BUILD_DIR)/$$(TARGET)
ef_$(1)_%: BOARD_ROOT_DIR=$(ROOT_DIR)/flight/targets/$(1)
$(eval $(call EF_TEMPLATE_$(4),$(1),$(2),$(3)))

.PHONY: ef_$(1)_clean
ef_$(1)_clean: TARGET=ef_$(1)
ef_$(1)_clean: OUTDIR=$(BUILD_DIR)/$$(TARGET)
ef_$(1)_clean:
$(V0) @echo " CLEAN $$@"
$(V1) [ ! -d "$$(OUTDIR)" ] || $(RM) -r "$$(OUTDIR)"
endef

# $(1) = Canonical board name all in lower case (e.g. coptercontrol)
define EF_TEMPLATE_NOBL
ef_$(1)_%: fw_$(1)_tlfw
ef_$(1)_%: $(if filter(no,$(4)),fw_$(1)_tlfw,bl_$(1)_bin fw_$(1)_tlfw)
$(V1) mkdir -p $$(OUTDIR)/dep
$(V1) cd $(ROOT_DIR)/flight/targets/EntireFlash && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BOARD_SHORT_NAME=$(3) \
BUILD_TYPE=ef \
INCLUDE_BOOTLOADER=no \
INCLUDE_BOOTLOADER=$(4) \
TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \
DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \
Expand All @@ -800,30 +788,13 @@ ef_$(1)_%: fw_$(1)_tlfw
OUTDIR=$$(OUTDIR) \
\
$$*
endef

# $(1) = Canonical board name all in lower case (e.g. coptercontrol)
define EF_TEMPLATE_BL
ef_$(1)_%: bl_$(1)_bin fw_$(1)_tlfw
$(V1) mkdir -p $$(OUTDIR)/dep
$(V1) cd $(ROOT_DIR)/flight/targets/EntireFlash && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BOARD_SHORT_NAME=$(3) \
BUILD_TYPE=ef \
INCLUDE_BOOTLOADER=yes \
TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \
DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \
\
MAKE_INC_DIR=$(MAKE_INC_DIR) \
ROOT_DIR=$(ROOT_DIR) \
BOARD_ROOT_DIR=$$(BOARD_ROOT_DIR) \
BOARD_INFO_DIR=$$(BOARD_ROOT_DIR)/board-info \
TARGET=$$(TARGET) \
OUTDIR=$$(OUTDIR) \
\
$$*
.PHONY: ef_$(1)_clean
ef_$(1)_clean: TARGET=ef_$(1)
ef_$(1)_clean: OUTDIR=$(BUILD_DIR)/$$(TARGET)
ef_$(1)_clean:
$(V0) @echo " CLEAN $$@"
$(V1) [ ! -d "$$(OUTDIR)" ] || $(RM) -r "$$(OUTDIR)"
endef

# When building any of the "all_*" targets, tell all sub makefiles to display
Expand Down Expand Up @@ -901,9 +872,7 @@ FW_BOARDS := $(ALL_BOARDS)
NOBL_BOARDS := $(strip $(foreach BOARD, $(ALL_BOARDS),$(if $(filter no,$($(BOARD)_bootloader)),$(BOARD))))
BL_BOARDS := $(filter-out $(NOBL_BOARDS), $(ALL_BOARDS))
BU_BOARDS := $(BL_BOARDS)
EF_BOARDS_NOBL := $(NOBL_BOARDS)
EF_BOARDS_BL := $(BL_BOARDS)
EF_BOARDS := $(EF_BOARDS_BL) $(EF_BOARDS_NOBL)
EF_BOARDS := $(ALL_BOARDS)

# Sim targets are different for each host OS
ifeq ($(UNAME), Linux)
Expand Down Expand Up @@ -959,8 +928,7 @@ $(foreach board, $(FW_BOARDS), $(eval $(call FW_TEMPLATE,$(board),$($(board)_fri
$(foreach board, $(BL_BOARDS), $(eval $(call BL_TEMPLATE,$(board),$($(board)_cpuarch),$($(board)_short))))

# Expand the entire-flash rules
$(foreach board, $(EF_BOARDS_BL), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),BL)))
$(foreach board, $(EF_BOARDS_NOBL), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),NOBL)))
$(foreach board, $(EF_BOARDS), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),$($(board)_bootloader))))

# Expand the available simulator rules
$(eval $(call SIM_TEMPLATE,simulation,Simulation,'sim ',posix,elf))
Expand Down
9 changes: 4 additions & 5 deletions flight/targets/EntireFlash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ FW_BIN := $(ROOT_DIR)/build/fw_$(BOARD_NAME)/fw_$(BOARD_NAME).bin
FWINFO_BIN := $(FW_BIN).firmwareinfo.bin
INCLUDE_BOOTLOADER ?= yes

ifeq ($(INCLUDE_BOOTLOADER),yes)
BL_BIN := $(ROOT_DIR)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin
FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)])
else
# no bootloader for this board
ifeq ($(INCLUDE_BOOTLOADER),no)
BL_BIN :=
FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(EF_BANK_BASE)])
else
BL_BIN := $(ROOT_DIR)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin
FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)])
endif # INCLUDE_BOOTLOADER

# force this target as FW_PRE_PAD could have been changed without us knowing
Expand Down

0 comments on commit 5dab284

Please sign in to comment.