From 73250efc01460d08045d4cd773604b4807ced505 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 4 May 2013 15:10:20 +1000 Subject: [PATCH] build: added support for the new PX4 build system --- mk/PX4/config_px4fmu_APM.mk | 70 ++++++++ mk/board_avr.mk | 6 - mk/board_avr_sitl.mk | 6 - mk/board_px4.mk | 7 +- mk/find_tools.mk | 2 +- mk/px4_core.mk | 309 ------------------------------------ mk/px4_targets.mk | 31 ++-- mk/sketch_sources.mk | 12 ++ 8 files changed, 104 insertions(+), 339 deletions(-) create mode 100644 mk/PX4/config_px4fmu_APM.mk delete mode 100644 mk/px4_core.mk diff --git a/mk/PX4/config_px4fmu_APM.mk b/mk/PX4/config_px4fmu_APM.mk new file mode 100644 index 0000000000..ff4643ef0a --- /dev/null +++ b/mk/PX4/config_px4fmu_APM.mk @@ -0,0 +1,70 @@ +# +# Makefile for the px4fmu_Hello configuration +# + +# +# Use the configuration's ROMFS. +# +ROMFS_ROOT = $(SKETCHBOOK)/mk/PX4/ROMFS + +MODULES += $(APM_MODULE_DIR) + +# +# Board support modules +# +MODULES += drivers/device +MODULES += drivers/stm32 +MODULES += drivers/stm32/adc +MODULES += drivers/stm32/tone_alarm +MODULES += drivers/px4io +MODULES += drivers/px4fmu +MODULES += drivers/boards/px4fmu +MODULES += drivers/l3gd20 +MODULES += drivers/bma180 +MODULES += drivers/mpu6000 +MODULES += drivers/hmc5883 +MODULES += drivers/ms5611 +MODULES += drivers/mb12xx +MODULES += drivers/gps +MODULES += drivers/hil +MODULES += drivers/hott_telemetry +MODULES += drivers/blinkm +MODULES += modules/sensors + +# +# System commands +# +MODULES += systemcmds/eeprom +MODULES += systemcmds/bl_update +MODULES += systemcmds/boardinfo +MODULES += systemcmds/i2c +MODULES += systemcmds/mixer +MODULES += systemcmds/perf +MODULES += systemcmds/pwm +MODULES += systemcmds/reboot +MODULES += systemcmds/top +MODULES += systemcmds/tests + +# +# Libraries +# +MODULES += modules/systemlib +MODULES += modules/systemlib/mixer +MODULES += modules/uORB + +# +# Transitional support - add commands from the NuttX export archive. +# +# In general, these should move to modules over time. +# +# Each entry here is ... but we use a helper macro +# to make the table a bit more readable. +# +define _B + $(strip $1).$(or $(strip $2),SCHED_PRIORITY_DEFAULT).$(or $(strip $3),CONFIG_PTHREAD_STACK_DEFAULT).$(strip $4) +endef + +# command priority stack entrypoint +BUILTIN_COMMANDS := \ + $(call _B, sercon, , 2048, sercon_main ) \ + $(call _B, serdis, , 2048, serdis_main ) diff --git a/mk/board_avr.mk b/mk/board_avr.mk index 22c6a3567a..ffb248004c 100644 --- a/mk/board_avr.mk +++ b/mk/board_avr.mk @@ -166,12 +166,6 @@ jtag-program: # fetch dependency info from a previous build if any of it exists -include $(ALLDEPS) -# common header for rules, prints what is being built -define RULEHDR - @echo %% $(subst $(BUILDROOT)/,,$@) - @mkdir -p $(dir $@) -endef - # Link the final object $(SKETCHELF): $(SKETCHOBJS) $(LIBOBJS) $(RULEHDR) diff --git a/mk/board_avr_sitl.mk b/mk/board_avr_sitl.mk index 1483747caa..c5074e7e67 100644 --- a/mk/board_avr_sitl.mk +++ b/mk/board_avr_sitl.mk @@ -83,12 +83,6 @@ print-%: # fetch dependency info from a previous build if any of it exists -include $(ALLDEPS) -# common header for rules, prints what is being built -define RULEHDR - @echo %% $(subst $(BUILDROOT)/,,$@) - @mkdir -p $(dir $@) -endef - # Link the final object $(SKETCHELF): $(SKETCHOBJS) $(LIBOBJS) @echo "Building $(SKETCHELF)" diff --git a/mk/board_px4.mk b/mk/board_px4.mk index 70e298bc79..4a38c0fc17 100644 --- a/mk/board_px4.mk +++ b/mk/board_px4.mk @@ -1,6 +1,3 @@ -# PX4 specific build support -ifeq ($(APPDIR),) +TOOLCHAIN = NATIVE +include $(MK_DIR)/find_tools.mk include $(MK_DIR)/px4_targets.mk -else -include $(MK_DIR)/px4_core.mk -endif diff --git a/mk/find_tools.mk b/mk/find_tools.mk index b8957dd0fb..206f1b2f35 100644 --- a/mk/find_tools.mk +++ b/mk/find_tools.mk @@ -54,7 +54,7 @@ GDB = $($(TOOLCHAIN)_GDB) OBJCOPY = $($(TOOLCHAIN)_OBJCOPY) ifeq ($(CXX),) -$(error ERROR: cannot find the compiler tools anywhere on the path $(TOOLPATH)) +$(error ERROR: cannot find the compiler tools for $(TOOLCHAIN) anywhere on the path $(TOOLPATH)) endif # Find awk diff --git a/mk/px4_core.mk b/mk/px4_core.mk deleted file mode 100644 index d8ee353d83..0000000000 --- a/mk/px4_core.mk +++ /dev/null @@ -1,309 +0,0 @@ -# this makefile is partly based on the PX4 core makefile -# which is Copyright (C) 2012 PX4 Development Team. - -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name PX4 nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# -# Common Makefile for nsh command modules and utility libraries; should be -# included by the module-specific Makefile. -# -# To build an app that appears as an nsh external command, the caller -# must define: -# -# LIBNAME - the name of the library, defaults to the name of the -# directory -# -# The calling makefile may also set: -# -# ASRCS - list of assembly source files, defaults to all .S -# files in the directory -# -# CSRCS - list of C source files, defaults to all .c files -# in the directory -# -# CXXSRCS - list of C++ source files, defaults to all .cpp -# files in the directory -# -# INCLUDES - list of directories to be added to the include -# search path -# -# PRIORITY - thread priority for the command (defaults to -# SCHED_PRIORITY_DEFAULT) -# -# STACKSIZE - stack size for the command (defaults to 4096) -# -# Symbols in the module are private to the module unless deliberately exported -# using the __EXPORT tag. -# - -############################################################################ -# No user-serviceable parts below -############################################################################ - - - -# build the variables to emulate Arduino.mk build system -SRCROOT := $(realpath $(dir $(firstword $(MAKEFILE_LIST)))) -SKETCH := $(lastword $(subst /, ,$(SRCROOT))) - -# this is where we put the generated cpp file, created from the *.pde/*.ino -TMPDIR ?= /tmp -BUILDROOT := $(abspath $(TMPDIR)/$(SKETCH).build) - -HARDWARE ?= px4 -AWK ?= gawk - -SRCSUFFIXES = *.cpp *.c *.S - -SKETCHPDESRCS := $(wildcard $(SRCROOT)/*.pde $(SRCROOT)/*.ino) -SKETCHSRCS := $(wildcard $(addprefix $(SRCROOT)/,$(SRCSUFFIXES))) -SKETCHPDE := $(wildcard $(SRCROOT)/$(SKETCH).pde $(SRCROOT)/$(SKETCH).ino) -SKETCHCPP := $(BUILDROOT)/$(SKETCH).cpp -ifneq ($(words $(SKETCHPDE)),1) -$(error ERROR: sketch $(SKETCH) must contain exactly one of $(SKETCH).pde or $(SKETCH).ino) -endif - -# Sketch object files -SKETCHOBJS := $(subst $(SRCROOT),$(BUILDROOT),$(SKETCHSRCS)) $(SKETCHCPP) -SKETCHOBJS := $(addsuffix .o,$(basename $(SKETCHOBJS))) - -# List of input files to the sketch.cpp file in the order they should -# be appended to create it -SKETCHCPP_SRC := $(SKETCHPDE) $(sort $(filter-out $(SKETCHPDE),$(SKETCHPDESRCS))) - - -################################################################################ -# Libraries -# -# Pick libraries to add to the include path and to link with based on -# #include directives in the sketchfiles. -# -# For example: -# -# #include -# -# implies that there might be a Foo library. -# -# Note that the # and $ require special treatment to avoid upsetting -# make. -# -SYSTYPE := $(shell uname) -SEXPR = 's/^[[:space:]]*\#include[[:space:]][<\"]([^>\"./]+).*$$/\1/p' -ifeq ($(SYSTYPE),Darwin) - LIBTOKENS := $(sort $(shell cat $(SKETCHPDESRCS) $(SKETCHSRCS) | sed -nEe $(SEXPR))) -else - LIBTOKENS := $(sort $(shell cat $(SKETCHPDESRCS) $(SKETCHSRCS) | sed -nre $(SEXPR))) -endif - -ifeq ($(SYSTYPE),Darwin) - # use BWK awk - AWK = awk -endif - -# -# Find sketchbook libraries referenced by the sketch. -# -# Include paths for sketch libraries -# -SKETCHBOOK=$(MK_DIR)/.. -SKETCHLIBS := $(wildcard $(addprefix $(SKETCHBOOK)/libraries/,$(LIBTOKENS))) -SKETCHLIBNAMES := $(notdir $(SKETCHLIBS)) -SKETCHLIBSRCDIRS := $(SKETCHLIBS) $(addsuffix /utility,$(SKETCHLIBS)) -SKETCHLIBSRCS := $(wildcard $(foreach suffix,$(SRCSUFFIXES),$(addsuffix /$(suffix),$(SKETCHLIBSRCDIRS)))) -SKETCHLIBOBJS := $(addsuffix .o,$(basename $(subst $(SKETCHBOOK),$(BUILDROOT),$(SKETCHLIBSRCS)))) -SKETCHLIBINCLUDES := $(addprefix -I,$(SKETCHLIBS)) - -# add sketch libs to includes -INCLUDES += $(SKETCHLIBS) - -# Library object files -LIBOBJS := $(SKETCHLIBOBJS) - -# common header for rules, prints what is being built -define RULEHDR - @echo %% $(subst $(BUILDROOT)/,,$@) - @mkdir -p $(dir $@) -endef - -############################################################################ -# Work out who included us so we can report decent errors -# -THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) -PARENT_MAKEFILE := $(lastword $(filter-out $(THIS_MAKEFILE),$(MAKEFILE_LIST))) - -############################################################################ -# Get configuration -# --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# this allows us to generate the main function -SKETCHFLAGS = -DCONFIG_HAL_BOARD=HAL_BOARD_PX4 -DSKETCHNAME=\"$(SKETCH)\" -DSKETCH_MAIN=$(SKETCH)_main $(EXTRAFLAGS) -CFLAGS += $(SKETCHFLAGS) -DCONFIG_C99_BOOL8 -CXXFLAGS += $(SKETCHFLAGS) -DCONFIG_C99_BOOL8 - -############################################################################ -# Sanity-check the information we've been given and set any defaults -# -SRCDIR ?= $(dir $(PARENT_MAKEFILE)) -PRIORITY ?= SCHED_PRIORITY_DEFAULT -STACKSIZE ?= 4096 - -INCLUDES += $(APPDIR) - -ASRCS ?= $(wildcard $(SRCDIR)/*.S) -CSRCS ?= $(wildcard $(SRCDIR)/*.c) -CXXSRCS ?= $(wildcard $(SRCDIR)/*.cpp) $(SKETCHCPP) -PDESRCS ?= $(wildcard $(SRCDIR)/*.pde) - -APPNAME = $(SKETCH) - -# there has to be a source file -ifeq ($(ASRCS)$(CSRCS)$(CXXSRCS)$(PDESRCS),) -$(error $(realpath $(PARENT_MAKEFILE)): at least one of ASRCS, CSRCS, CXXSRCS or PDESRCS must be set) -endif - -# check that C++ is configured if we have C++ source files and we are building -ifneq ($(CXXSRCS),) -ifneq ($(CONFIG_HAVE_CXX),y) -ifeq ($(MAKECMDGOALS),build) -$(error $(realpath $(PARENT_MAKEFILE)): cannot set CXXSRCS if CONFIG_HAVE_CXX not set in configuration) -endif -endif -endif - -############################################################################ -# Adjust compilation flags to implement EXPORT -# -CFLAGS += -fsigned-char -fvisibility=hidden -include $(APPDIR)/systemlib/visibility.h -CXXFLAGS += -fsigned-char -fvisibility=hidden -include $(APPDIR)/systemlib/visibility.h - -############################################################################ -# Add extra include directories -# -CFLAGS += $(addprefix -I,$(INCLUDES)) -CXXFLAGS += $(addprefix -I,$(INCLUDES)) - -############################################################################ -# Things we are going to build -# - -SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) -AOBJS = $(patsubst %.S,%.o,$(ASRCS)) -COBJS = $(patsubst %.c,%.o,$(CSRCS)) -CXXOBJS = $(patsubst %.cpp,%.o,$(CXXSRCS)) -OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) $(SKETCHLIBOBJS) - -# The prelinked object that we are ultimately going to build -ifneq ($(APPNAME),) -PRELINKOBJ = $(APPNAME).pre.o -else -PRELINKOBJ = $(LIBNAME).pre.o -endif - -# The archive that the object file will be placed in -# XXX does WINTOOL ever get set? -ifeq ($(WINTOOL),y) - INCDIROPT = -w - BIN = "$(shell cygpath -w $(APPDIR)/libapps$(LIBEXT))" -else - BIN = "$(APPDIR)/libapps$(LIBEXT)" -endif - -############################################################################ -# Rules for building things -# - -all: .built -.PHONY: clean depend distclean - -# -# Top-level build; add prelinked object to the apps archive -# -.built: $(PRELINKOBJ) - $(RULEHDR) - @$(call ARCHIVE, $(BIN), $(PRELINKOBJ)) - @touch $@ - -# -# Source dependencies -# -depend: .depend -.depend: $(MAKEFILE_LIST) $(SRCS) - @$(CXX) -M -MT $(BUILDROOT)/$(SKETCH).o $(CXXFLAGS) $(CXXSRCS) > Make.dep - @for f in $(SKETCHLIBSRCS); do \ - src=$${f##$(SKETCHBOOK)/}; \ - obj=$(BUILDROOT)/$${src%.*}.o; \ - $(CXX) -M -MT $$obj $(CXXFLAGS) $$f; done >> Make.dep - @touch $@ - -ifneq ($(APPNAME),) -# -# App registration -# -context: .context -.context: $(MAKEFILE_LIST) - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - @touch $@ -else -context: -endif - -# -# Object files -# -$(PRELINKOBJ): $(OBJS) - $(call PRELINK, $@, $(OBJS)) - -$(AOBJS): %.o : %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %.o : %.c - $(call COMPILE, $<, $@) - -$(CXXOBJS): %.o : %.cpp - $(call COMPILEXX, $<, $@) - - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.cpp - $(RULEHDR) - $(call COMPILEXX, $<, $@) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.c - $(RULEHDR) - $(call COMPILE, $<, $@) - -$(BUILDROOT)/libraries/%.o: $(SKETCHBOOK)/libraries/%.S - $(RULEHDR) - $(call ASSEMBLE, $<, $@) - --include Make.dep diff --git a/mk/px4_targets.mk b/mk/px4_targets.mk index 7d9a7e284e..5a576481b9 100644 --- a/mk/px4_targets.mk +++ b/mk/px4_targets.mk @@ -2,24 +2,31 @@ ifneq ($(PX4_ROOT),) -# install rc.APM from the AP_HAL_PX4/scripts directory as /etc/init.d/rc.APM -HAL_PX4_DIR = $(realpath $(MK_DIR)/../libraries/AP_HAL_PX4) -PX4_EXTERNAL_SCRIPTS = $(HAL_PX4_DIR)/scripts/rc.APM~init.d/rc.APM +PX4_MAKE = make -C $(BUILDROOT) -f $(PX4_ROOT)/makefiles/firmware.mk CONFIG_FILE=$(PWD)/$(PX4_CONFIG_FILE) EXTRAFLAGS="$(EXTRAFLAGS)" APM_MODULE_DIR=$(BUILDROOT) SKETCHBOOK=$(SKETCHBOOK) PX4_ROOT=$(PX4_ROOT) -# we use CURDIR instead of PWD to avoid a problem with MINGW32 on Windows -PX4_EXTERNAL = EXTERNAL_APPS=$(CURDIR) EXTERNAL_SCRIPTS=$(PX4_EXTERNAL_SCRIPTS) -PX4_MAKE = make -C $(PX4_ROOT) $(PX4_EXTERNAL) CONFIG_APM=y EXTRAFLAGS=$(EXTRAFLAGS) +PX4_CONFIG_FILE=$(MK_DIR)/PX4/config_px4fmu_APM.mk +PX4SRCS = $(SKETCHCPP) $(SKETCHLIBSRCS) +EXTRAFLAGS=$(SKETCHLIBINCLUDES) -I$(PWD) -DCONFIG_HAL_BOARD=HAL_BOARD_PX4 -DSKETCHNAME="\\\"$(SKETCH)\\\"" -DSKETCH_MAIN=ArduPilot_main -px4: - $(PX4_MAKE) +$(BUILDROOT)/module.mk: + echo "# Auto-generated file - do not edit" > $@ + echo "MODULE_COMMAND = ArduPilot" >> $@ + echo "SRCS = $(SKETCH).cpp $(SKETCHLIBSRCS)" >> $@ + echo "MODULE_STACKSIZE = 4096" >> $@ + echo "MAXOPTIMIZATION = -Os" >> $@ + +px4: $(SKETCHCPP) $(BUILDROOT)/module.mk + $(PX4_MAKE) firmware px4-clean: clean - $(PX4_MAKE) clean - $(PX4_MAKE) configure_px4fmu + /bin/rm -rf $(PX4_ROOT)/makefiles/build + +px4-upload: $(SKETCHCPP) $(BUILDROOT)/module.mk + $(PX4_MAKE) firmware upload -px4-upload: - $(PX4_MAKE) upload +px4-archives: + $(PX4_MAKE) archives else diff --git a/mk/sketch_sources.mk b/mk/sketch_sources.mk index dc86e135e4..807dca4e9f 100644 --- a/mk/sketch_sources.mk +++ b/mk/sketch_sources.mk @@ -55,10 +55,16 @@ SKETCHLIBSRCS := $(wildcard $(foreach suffix,$(SRCSUFFIXES),$(addsuffix /$(suff SKETCHLIBOBJS := $(addsuffix .o,$(basename $(subst $(SKETCHBOOK),$(BUILDROOT),$(SKETCHLIBSRCS)))) SKETCHLIBINCLUDES := $(addprefix -I,$(SKETCHLIBS)) +ifeq ($(VERBOSE),) +v = @ +else +v = +endif # # Build the sketch.cpp file $(SKETCHCPP): $(SKETCHCPP_SRC) + @echo "building $(SKETCHCPP)" $(RULEHDR) $(v)$(AWK) -v mode=header '$(SKETCH_SPLITTER)' $(SKETCHCPP_SRC) > $@ $(v)echo "#line 1 \"autogenerated\"" >> $@ @@ -137,3 +143,9 @@ define SKETCH_PROTOTYPER printf "%s;\n", proto; \ } endef + +# common header for rules, prints what is being built +define RULEHDR + @echo %% $(subst $(BUILDROOT)/,,$@) + @mkdir -p $(dir $@) +endef