Chinaunix首页 | 论坛 | 博客
  • 博客访问: 379392
  • 博文数量: 61
  • 博客积分: 4650
  • 博客等级: 上校
  • 技术积分: 786
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-11 21:07
个人简介

少抱怨,多实干;

文章分类

全部博文(61)

文章存档

2017年(1)

2016年(13)

2015年(1)

2013年(2)

2011年(1)

2010年(3)

2009年(23)

2008年(17)

我的朋友

分类: 嵌入式

2016-09-08 21:46:04

#
#   Copyright (c) 2012-2015 PX4 Development Team. All rights reserved.
#
# 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.
#

#
# Top-level Makefile for building PX4 firmware images.
#

#
# Get path and tool configuration
#
export PX4_BASE      := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))/
include $(PX4_BASE)makefiles/setup.mk
#设置变量:PX4_BASE 为顶级makefile所在目录,并装载setup.mk,来设备系统一些环境:
# 下面所有变量都是以源码所在的目录为根目录;
#系统目录变量:
#   PX4_INCLUDE_DIR   = /src/include
#   PX4_MODULE_SRC    = /src
#   PX4_LIB_DIR       = /src/lib
#   PX4_PLATFORMS_DIR = /src/platforms
#   PX4_MK_DIR        = /makefiles
#   NUTTX_SRC         = /Nuttx/nuttx
#   MAVLINK_SRC       = /mavlink/include/mavlink/v1.0
#   NUTTX_APP_SRC     = /Nuttx/apps
#   MAVLINK_SRC       = /mavlink
#   UAVCAN_DIR        = /uavcan
#   ROMFS_SRC         = /ROMFS
#   IMAGE_DIR         = /Imags
#   BUILD_DIR         = /Build
#   ARCHIVE_DIR       = /Archives
#   PX4_VERSIONING_DIR= /versioning
#和头文件路径:
#   INCLUDE_DIRS = "/src /src/modules /src/include /src/lib /src/platforms /versioning"
#还有工具路径:
#   MKFW      = /Tools/px_mkfw.py   
#   UPLOADER  = /Tools/px_uploader.py
#   COPY      = cp
#   COPYDIR   = cp -Rf
#   REMOVE    = rm -f   
#   RMDIR     = rm -rf  
#   GENROMFS  = genrofs
#   TOUCH     = touch
#   MKDIR     = mkdir
#   FIND      = find
#   ECHO      = echo
#   UNZIP_CMD = unzip
#   PYTHON    = python
#   OPENOCD   = openocd
#   GREP      = grep
#系统类型:
#   SYSTPYE   = ...
#系统调试标识:
#         Q



#
# Get a version string provided by git
# This assumes that git command is available and that
# the directory holding this file also contains .git directory
#
GIT_DESC := $(shell git log -1 --pretty=format:%H)
ifneq ($(words $(GIT_DESC)),1)
    GIT_DESC := "unknown_git_version"
endif
#获取GIT版本,正常情况下,GIT_DESC应该是一个连续的字符串,
#而不是多个,所以此处用$(words来判断单词个数;


GIT_DESC_SHORT := $(shell echo $(GIT_DESC) | cut -c1-16)

#
# Canned firmware configurations that we (know how to) build.
#
KNOWN_CONFIGS   := $(subst config_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)config_*.mk))))
CONFIGS         ?= $(KNOWN_CONFIGS)
#将makefiles目录下面所有以"config_"开头和".mk"结尾的非目录文件名去掉"config_"和".mk"后存入KNOWN_CONFIGS
#变量中,正常情况下,KNOWN_CONFIGS的值应该是这些名称间以空格隔开的字串,
#如:"aerocore_default px4fmu-v1_default px4fmu-v2_default px4fmu-v2_multiplatform ..."
#


#
# Boards that we (know how to) build NuttX export kits for.
#
KNOWN_BOARDS    := $(subst board_,,$(basename $(notdir $(wildcard $(PX4_MK_DIR)board_*.mk))))
BOARDS          ?= $(KNOWN_BOARDS)
#将makefiles目录下面所有以"board_"开头和".mk"结尾的非目录文件名去掉"board_"和".mk"后存入KNOWN_BOARDS
#变量中,其值如: "aerocore px4fmu-v1 px4fmu-v2 px4io-v1 px4io-v2 ..."
#

#
# Debugging
#
MQUIET           = --no-print-directory
#MQUIET          = --print-directory

################################################################################
# No user-serviceable parts below
################################################################################

#
# If the user has listed a config as a target, strip it out and override CONFIGS.
#
FIRMWARE_GOAL        = firmware
EXPLICIT_CONFIGS    := $(filter $(CONFIGS),$(MAKECMDGOALS))
ifneq ($(EXPLICIT_CONFIGS),)
CONFIGS             := $(EXPLICIT_CONFIGS)
.PHONY:             $(EXPLICIT_CONFIGS)
$(EXPLICIT_CONFIGS) :all
#MAKECMDGOALS为make的内置环境变量,存着make后面要make的目标名称;将$CONFIGS中匹配$MAKECMDGOALS
#的字符串存到EXPLICIT_CONFIGS;然后判断EXPLICIT_CONFIGS是否为空,如果非空则更新CONFIGS 为make
#的目标,如CONFIGS = px4fmu-v2

#
# If the user has asked to upload, they must have also specified exactly one
# config.
#
ifneq ($(filter upload,$(MAKECMDGOALS)),)
ifneq ($(words $(EXPLICIT_CONFIGS)),1)
$(error In order to upload, exactly one board config must be specified)
endif
FIRMWARE_GOAL        = upload
.PHONY: upload
upload:
    @:
endif
endif
#
#如果make的目标为upload,并且仅一个参数,则报错,因为upload 后面必须跟upload的目标对象;否则设置FIRMWARE_GOAL= upload
#


#
# Built products
#
DESIRED_FIRMWARES    = $(foreach config,$(CONFIGS),$(IMAGE_DIR)$(config).px4)
#去Images目录下找以Target为名称.px4为后缀的文件,并赋值给该变量;若没有此类文件,则变量为空
#

STAGED_FIRMWARES     = $(foreach config,$(KNOWN_CONFIGS),$(IMAGE_DIR)$(config).px4)
#在Images目录下找所有已定义的固件,将将其名称记录在该变量中
#

FIRMWARES            = $(foreach config,$(KNOWN_CONFIGS),$(BUILD_DIR)$(config).build/firmware.px4)
#去Build目录下的以Target+.build为名称的目录下面找fimrware.px4文件;

all:    $(DESIRED_FIRMWARES)

#
# Copy FIRMWARES into the image directory.
#
# XXX copying the .bin files is a hack to work around the PX4IO uploader
#     not supporting .px4 files, and it should be deprecated onced that
#     is taken care of.
#
$(STAGED_FIRMWARES): $(IMAGE_DIR)%.px4: $(BUILD_DIR)%.build/firmware.px4
    @$(ECHO) %% Copying $@
    $(Q) $(COPY) $< $@
    $(Q) $(COPY) $(patsubst %.px4,%.bin,$<) $(patsubst %.px4,%.bin,$@)
#将???
    
    
#
# Generate FIRMWARES.
#
.PHONY: $(FIRMWARES)
$(BUILD_DIR)%.build/firmware.px4: config   = $(patsubst $(BUILD_DIR)%.build/firmware.px4,%,$@)
$(BUILD_DIR)%.build/firmware.px4: work_dir = $(BUILD_DIR)$(config).build/
$(FIRMWARES): $(BUILD_DIR)%.build/firmware.px4: checkgitversion generateuorbtopicheaders checksubmodules
    @$(ECHO) %%%%
    @$(ECHO) %%%% Building $(config) in $(work_dir)
    @$(ECHO) %%%%
    $(Q) $(MKDIR) -p $(work_dir)
    $(Q) $(MAKE) -r -C $(work_dir) \
        -f $(PX4_MK_DIR)firmware.mk \
        CONFIG=$(config) \
        WORK_DIR=$(work_dir) \
        $(FIRMWARE_GOAL)
#创建xxx.build目录,
#-r :禁止编译器内置的一些规则,-C:切换到指定的目录进行编译
#执行/makefiles/firmware.mk文件,并将CONFIG和WORK_DIR的值传给编译源码
#
#******[CCZY]*********上面这个make才是开始编译PX4的目标固件******************
#********所以,下一步就要去分析makefiles/firmware.mk文件**********************
        
#
# Make FMU firmwares depend on the corresponding IO firmware.
#
# This is a pretty vile hack, since it hard-codes knowledge of the FMU->IO dependency
# and forces the _default config in all cases. There has to be a better way to do this...
#
FMU_VERSION      = $(patsubst px4fmu-%,%,$(word 1, $(subst _, ,$(1))))
define FMU_DEP
$(BUILD_DIR)$(1).build/firmware.px4: $(IMAGE_DIR)px4io-$(call FMU_VERSION,$(1))_default.px4
endef
FMU_CONFIGS     := $(filter px4fmu%,$(CONFIGS))
$(foreach config,$(FMU_CONFIGS),$(eval $(call FMU_DEP,$(config))))

#
# Build the NuttX export archives.
#
# Note that there are no explicit dependencies extended from these
# archives. If NuttX is updated, the user is expected to rebuild the
# archives/build area manually. Likewise, when the 'archives' target is
# invoked, all archives are always rebuilt.
#
# XXX Should support fetching/unpacking from a separate directory to permit
#     downloads of the prebuilt archives as well...
#
NUTTX_ARCHIVES  = $(foreach board,$(BOARDS),$(ARCHIVE_DIR)$(board).export)
.PHONY:         archives
archives:       $(NUTTX_ARCHIVES)
#by CCZY
#archives:      checksubmodules $(NUTTX_ARCHIVES)

# We cannot build these parallel; note that we also force -j1 for the
# sub-make invocations.
ifneq ($(filter archives,$(MAKECMDGOALS)),)
.NOTPARALLEL:
endif

J?=1

$(ARCHIVE_DIR)%.export: board = $(notdir $(basename $@))
$(ARCHIVE_DIR)%.export: configuration = nsh
$(NUTTX_ARCHIVES): $(ARCHIVE_DIR)%.export: $(NUTTX_SRC)
    @$(ECHO) %% Configuring NuttX for $(board)
    $(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
    $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) distclean
    $(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(board) .)
    $(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(board)/$(configuration))
    @$(ECHO) %% Exporting NuttX for $(board)
    $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) CONFIG_ARCH_BOARD=$(board) export
    $(Q) $(MKDIR) -p $(dir $@)
    $(Q) $(COPY) $(NUTTX_SRC)nuttx-export.zip $@
    $(Q) (cd $(NUTTX_SRC)/configs && $(RMDIR) $(board))

#
# The user can run the NuttX 'menuconfig' tool for a single board configuration with
# make BOARDS= menuconfig
#
ifeq ($(MAKECMDGOALS),menuconfig)
ifneq ($(words $(BOARDS)),1)
$(error BOARDS must specify exactly one board for the menuconfig goal)
endif
BOARD            = $(BOARDS)
menuconfig: $(NUTTX_SRC)
    @$(ECHO) %% Configuring NuttX for $(BOARD)
    $(Q) (cd $(NUTTX_SRC) && $(RMDIR) nuttx-export)
    $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) distclean
    $(Q) (cd $(NUTTX_SRC)/configs && $(COPYDIR) $(PX4_BASE)nuttx-configs/$(BOARD) .)
    $(Q) (cd $(NUTTX_SRC)tools && ./configure.sh $(BOARD)/nsh)
    @$(ECHO) %% Running menuconfig for $(BOARD)
    $(Q) $(MAKE) -r -j$(J) -C $(NUTTX_SRC) -r $(MQUIET) menuconfig
    @$(ECHO) %% Saving configuration file
    $(Q)$(COPY) $(NUTTX_SRC).config $(PX4_BASE)nuttx-configs/$(BOARD)/nsh/defconfig
else
menuconfig:
    @$(ECHO) ""
    @$(ECHO) "The menuconfig goal must be invoked without any other goal being specified"
    @$(ECHO) ""
endif

#by CCZY
#$(NUTTX_SRC): checkgitversion checksubmodules
$(NUTTX_SRC):

$(UAVCAN_DIR):
#by CCZY
#   $(Q) (./Tools/check_submodules.sh)


ifeq ($(PX4_TARGET_OS),nuttx)
# TODO
# Move the above nuttx specific rules into $(PX4_BASE)makefiles/firmware_nuttx.mk
endif
ifeq ($(PX4_TARGET_OS),posix)
include $(PX4_BASE)makefiles/firmware_posix.mk
endif
ifeq ($(PX4_TARGET_OS),posix-arm)
include $(PX4_BASE)makefiles/firmware_posix.mk
endif
ifeq ($(PX4_TARGET_OS),qurt)
include $(PX4_BASE)makefiles/firmware_qurt.mk
endif

#
# Versioning
#

GIT_VER_FILE = $(PX4_VERSIONING_DIR).build_git_ver
GIT_HEADER_FILE = $(PX4_VERSIONING_DIR)build_git_version.h

$(GIT_VER_FILE) :
    $(Q) if [ ! -f $(GIT_VER_FILE) ]; then \
        $(MKDIR) -p $(PX4_VERSIONING_DIR); \
        $(ECHO) "" > $(GIT_VER_FILE); \
    fi

.PHONY: checkgitversion
checkgitversion: $(GIT_VER_FILE)
    $(Q) if [ "$(GIT_DESC)" != "$(shell cat $(GIT_VER_FILE))" ]; then \
        $(ECHO) "/* Auto Magically Generated file */" > $(GIT_HEADER_FILE); \
        $(ECHO) "/* Do not edit! */" >> $(GIT_HEADER_FILE); \
        $(ECHO) "#define PX4_GIT_VERSION_STR  \"$(GIT_DESC)\"" >> $(GIT_HEADER_FILE); \
        $(ECHO) "#define PX4_GIT_VERSION_BINARY 0x$(GIT_DESC_SHORT)" >> $(GIT_HEADER_FILE); \
        $(ECHO) $(GIT_DESC) > $(GIT_VER_FILE); \
    fi

#
# Submodule Checks
#

.PHONY: checksubmodules
checksubmodules:
    $(Q) ($(PX4_BASE)/Tools/check_submodules.sh)

.PHONY: updatesubmodules
updatesubmodules:
    $(Q) (git submodule init)
    $(Q) (git submodule update)

MSG_DIR = $(PX4_BASE)msg
UORB_TEMPLATE_DIR = $(PX4_BASE)msg/templates/uorb
MULTIPLATFORM_TEMPLATE_DIR = $(PX4_BASE)msg/templates/px4/uorb
TOPICS_DIR = $(PX4_BASE)src/modules/uORB/topics
MULTIPLATFORM_HEADER_DIR = $(PX4_BASE)src/platforms/nuttx/px4_messages
MULTIPLATFORM_PREFIX = px4_
TOPICHEADER_TEMP_DIR = $(BUILD_DIR)topics_temporary
MULTI_TOPICHEADER_TEMP_DIR = $(BUILD_DIR)multi_topics_temporary
GENMSG_PYTHONPATH = $(PX4_BASE)Tools/genmsg/src
GENCPP_PYTHONPATH = $(PX4_BASE)Tools/gencpp/src

.PHONY: generateuorbtopicheaders
generateuorbtopicheaders: checksubmodules
    @$(ECHO) "Generating uORB topic headers"
    $(Q) (PYTHONPATH=$(GENMSG_PYTHONPATH):$(GENCPP_PYTHONPATH):$(PYTHONPATH) $(PYTHON) \
        $(PX4_BASE)Tools/px_generate_uorb_topic_headers.py \
        -d $(MSG_DIR) -o $(TOPICS_DIR) -e $(UORB_TEMPLATE_DIR) -t $(TOPICHEADER_TEMP_DIR))
    @$(ECHO) "Generating multiplatform uORB topic wrapper headers"
    $(Q) (PYTHONPATH=$(GENMSG_PYTHONPATH):$(GENCPP_PYTHONPATH):$(PYTHONPATH) $(PYTHON) \
        $(PX4_BASE)Tools/px_generate_uorb_topic_headers.py \
        -d $(MSG_DIR) -o $(MULTIPLATFORM_HEADER_DIR) -e $(MULTIPLATFORM_TEMPLATE_DIR) -t $(MULTI_TOPICHEADER_TEMP_DIR) -p $(MULTIPLATFORM_PREFIX))

#
# Testing targets
#
testbuild:
    $(Q) (cd $(PX4_BASE) && $(MAKE) distclean && $(MAKE) archives && $(MAKE) -j8)
    $(Q) (zip -r Firmware.zip $(PX4_BASE)/Images)

#
# Unittest targets. Builds and runs the host-level
# unit tests.
.PHONY: tests
tests:  generateuorbtopicheaders
    $(Q) (mkdir -p $(PX4_BASE)/unittests/build && cd $(PX4_BASE)/unittests/build && cmake .. && $(MAKE) unittests)

.PHONY: format check_format
check_format:
    $(Q) (./Tools/check_code_style.sh | sort -n)

#
# Cleanup targets.  'clean' should remove all built products and force
# a complete re-compilation, 'distclean' should remove everything
# that's generated leaving only files that are in source control.
#
.PHONY: clean
clean:
    @echo > /dev/null
    $(Q) $(RMDIR) $(BUILD_DIR)*.build
    $(Q) $(RMDIR) $(PX4_VERSIONING_DIR)
    $(Q) $(REMOVE) $(IMAGE_DIR)*.px4
    $(Q) $(RMDIR) $(TOPICHEADER_TEMP_DIR)
    $(Q) $(RMDIR) $(MULTI_TOPICHEADER_TEMP_DIR)

.PHONY: distclean
distclean: clean
    @echo > /dev/null
    $(Q) $(REMOVE) $(ARCHIVE_DIR)*.export
    $(Q) $(MAKE) -C $(NUTTX_SRC) -r $(MQUIET) distclean
    $(Q) (cd $(NUTTX_SRC)/configs && $(FIND) . -maxdepth 1 -type l -delete)

#
# Print some help text
#
.PHONY: help
help:
    @$(ECHO) ""
    @$(ECHO) " PX4 firmware builder"
    @$(ECHO) " ===================="
    @$(ECHO) ""
    @$(ECHO) "  Available targets:"
    @$(ECHO) "  ------------------"
    @$(ECHO) ""
    @$(ECHO) "  archives"
    @$(ECHO) "    Build the NuttX RTOS archives that are used by the firmware build."
    @$(ECHO) ""
    @$(ECHO) "  all"
    @$(ECHO) "    Build all firmware configs: $(CONFIGS)"
    @$(ECHO) "    A limited set of configs can be built with CONFIGS="
    @$(ECHO) ""
    @for config in $(CONFIGS); do \
        $(ECHO) "  $$config"; \
        $(ECHO) "    Build just the $$config firmware configuration."; \
        $(ECHO) ""; \
    done
    @$(ECHO) "  clean"
    @$(ECHO) "    Remove all firmware build pieces."
    @$(ECHO) ""
    @$(ECHO) "  distclean"
    @$(ECHO) "    Remove all compilation products, including NuttX RTOS archives."
    @$(ECHO) ""
    @$(ECHO) "  upload"
    @$(ECHO) "    When exactly one config is being built, add this target to upload the"
    @$(ECHO) "    firmware to the board when the build is complete. Not supported for"
    @$(ECHO) "    all configurations."
    @$(ECHO) ""
    @$(ECHO) "  testbuild"
    @$(ECHO) "    Perform a complete clean build of the entire tree."
    @$(ECHO) ""
    @$(ECHO) "  Common options:"
    @$(ECHO) "  ---------------"
    @$(ECHO) ""
    @$(ECHO) "  V=1"
    @$(ECHO) "    If V is set, more verbose output is printed during the build. This can"
    @$(ECHO) "    help when diagnosing issues with the build or toolchain."
    @$(ECHO) ""







PX4_Makefile.zip
阅读(1948) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~