More Makefile cleanup.

Use $(MAKE) -C build_dir ..., not (cd build_dir; make ...)
(ie, see https://blog.flameeyes.eu/2010/10/tell-tale-signs-that-your-makefile-is-broken)

Also talk about 'make targets' where appropriate, instead of 'cmake targets' %-).
This commit is contained in:
Carlo Wood
2016-09-03 00:06:49 +02:00
committed by Beat Küng
parent 77d356d275
commit 6f94f7031b
+10 -9
View File
@@ -100,7 +100,7 @@ ifdef SYSTEMROOT
else else
PX4_CMAKE_GENERATOR ?= "Unix Makefiles" PX4_CMAKE_GENERATOR ?= "Unix Makefiles"
endif endif
PX4_MAKE = make PX4_MAKE = $(MAKE)
PX4_MAKE_ARGS = -j$(j) --no-print-directory PX4_MAKE_ARGS = -j$(j) --no-print-directory
endif endif
@@ -120,18 +120,19 @@ define cmake-build
+@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX)) +@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX))
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi +@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf $(BUILD_DIR)); fi +@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake .. -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf $(BUILD_DIR)); fi
+@(echo "PX4 CONFIG: $(BUILD_DIR)" && cd $(BUILD_DIR) && $(PX4_MAKE) $(PX4_MAKE_ARGS) $(ARGS)) +@echo "PX4 CONFIG: $(BUILD_DIR)"
+@$(PX4_MAKE) -C "$(BUILD_DIR)" $(PX4_MAKE_ARGS) $(ARGS)
endef endef
define cmake-build-other define cmake-build-other
+@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX)) +@$(eval BUILD_DIR = $(SRC_DIR)/build_$@$(BUILD_DIR_SUFFIX))
+@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi +@if [ $(PX4_CMAKE_GENERATOR) = "Ninja" ] && [ -e $(BUILD_DIR)/Makefile ]; then rm -rf $(BUILD_DIR); fi
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake $(2) -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf $(BUILD_DIR)); fi +@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && cmake $(2) -G$(PX4_CMAKE_GENERATOR) -DCONFIG=$(1) || (cd .. && rm -rf $(BUILD_DIR)); fi
+@(cd $(BUILD_DIR) && $(PX4_MAKE) $(PX4_MAKE_ARGS) $(ARGS)) +@$(PX4_MAKE) -C "$(BUILD_DIR)" $(PX4_MAKE_ARGS) $(ARGS)
endef endef
# create empty targets to avoid msgs for targets passed to cmake # create empty targets to avoid msgs for targets passed to PX4_MAKE
define cmake-targ define make-targ
$(1): $(1):
@# @#
.PHONY: $(1) .PHONY: $(1)
@@ -271,7 +272,7 @@ package_firmware:
clean: clean:
@rm -rf build_*/ @rm -rf build_*/
@(cd NuttX/nuttx && make clean) @$(MAKE) -C NuttX/nuttx clean
submodulesclean: submodulesclean:
@git submodule sync --recursive @git submodule sync --recursive
@@ -285,10 +286,10 @@ distclean: submodulesclean
viewers = gazebo jmavsim replay viewers = gazebo jmavsim replay
# A list of make patterns that match the viewer_model_debugger triplet 'targets'. # A list of make patterns that match the viewer_model_debugger triplet 'targets'.
sitl_vmd_triplet_masks = $(foreach viewer,$(viewers),$(viewer) $(viewer)_%) sitl_vmd_triplet_masks = $(foreach viewer,$(viewers),$(viewer) $(viewer)_%)
# targets handled by cmake # targets handled by PX4_MAKE
cmake_targets = install test upload package package_source debug debug_tui debug_ddd debug_io debug_io_tui debug_io_ddd check_weak \ make_targets = install test upload package package_source debug debug_tui debug_ddd debug_io debug_io_tui debug_io_ddd check_weak \
run_cmake_config config $(sitl_vmd_triplet_masks) run_cmake_config config $(sitl_vmd_triplet_masks)
$(foreach targ,$(cmake_targets),$(eval $(call cmake-targ,$(targ)))) $(foreach targ,$(make_targets),$(eval $(call make-targ,$(targ))))
.PHONY: clean .PHONY: clean