ArduCopter 3.6.5编译

该版本使用了waf编译器。ArduCopter目录下,找到Makefile.waf文件,打开如图:
在这里插入图片描述
执行“make -help”可知,“-f File”表示读取File为makefile。
因此“make -C …/ -f Makefile.waf copter”表示 读取“ardupilot/Makefile”为makefile,解析Makefile的脚本为"ardupilot/waf.py",编译目标为copter。

ardupilot/Makefile

ROOT = $(dir $(lastword $(MAKEFILE_LIST))) //ROOT = /ardupilot

WAF_BINARY = $(realpath $(ROOT)/modules/waf/waf-light)  //WAF_BINARY=/ardupilot/modules/waf/waf-light
WAF = python $(WAF_BINARY) $(WAF_FLAGS)

EXPLICIT_COMMANDS = check check-all clean list_boards //waf命令

VEHICLES = copter plane rover sub heli  //waf目标

BOARD_LIST := $(shell $(WAF) list_boards | head -1)  // .waf list_boards查询可支持的板子

all: help

$(WAF_BINARY):  // /ardupilot/modules/waf/waf-light更新
	@git submodule init && git submodule update

waf-%: $(WAF_BINARY)
	@$(WAF) $*

%-configure: $(WAF_BINARY) 
	@$(WAF) configure --board $*

$(EXPLICIT_COMMANDS): $(WAF_BINARY)
	@$(WAF) $@

$(VEHICLES): $(WAF_BINARY)
	@echo Build for vehicle $@
	@$(WAF) $@

.DEFAULT: %-configure
	@$(WAF) configure --board $@ build

define target_template
$(1)-$(2) : $(1)-configure $(2)
endef

$(foreach board,$(BOARD_LIST),$(foreach vehicle,$(VEHICLES),$(eval $(call target_template,$(board),$(vehicle)))))

help:
	@echo "Ardupilot Building"
	@echo "=================="
	@echo "This is a make wrapper for Ardupilot's Waf build system. This wrapper is"
	@echo "intended to provide convenience for basic and common build tasks. If you need"
	@echo "more than what this wrapper provides, it's a good idea to use waf directly."
	@echo "The waf executable is at '$(WAF_BINARY)'."
	@echo ""
	@echo "For more detailed instructions see http://ardupilot.org/dev/docs/building-the-code.html"
	@echo ""
	@echo "Boards"
	@echo "------"
	@echo ""
	@echo "In order to trigger the build for a board/platform, the name of the board is"
	@echo "used as the target. Example: make linux"
	@echo "If no target is passed, then the build will be triggered for the last board"
	@echo "used. You can suffix the board/platform with '-configure' in order to just "
	@echo "configure without triggering a build command."
	@echo ""
	@echo "You can get a list of available boards using the command:"
	@echo "    make list_boards"
	@echo ""
	@echo "Vehicles"
	@echo "--------"
	@echo ""
	@echo "It's possible to build for a specific vehicle by defining the target as one of:"
	@echo "    $(VEHICLES)"
	@echo ""
	@echo "Not that if it's your first time building or you want to change the target "
	@echo "board/platform, you'll need to configure the build before (e.g"
	@echo "make linux-configure)"
	@echo ""
	@echo "Combinations"
	@echo "------------"
	@echo ""
	@echo "It's possible to build for a specific vehicle type and board using"
	@echo "    make BOARD-VEHICLE"
	@echo ""
	@echo "For example, to build copter for the Pixracer, use this:"
	@echo "    make Pixracer-copter"
	@echo ""
	@echo "Check"
	@echo "-----"
	@echo ""
	@echo "Check targets are used for running tests. There are two targets available:"
	@echo "    check:	 for running tests that are still failing or that are new or"
	@echo "    		   have been modified"
	@echo "    check-all: to run all tests"
	@echo ""
	@echo "Waf commands"
	@echo "------------"
	@echo ""
	@echo "Waf commands can be explicitly called with targets prefixed by 'waf-'. Example:"
	@echo "    make waf-clean"
	@echo "    make waf-build"
	@echo ""
	@echo "Common commands"
	@echo "---------------"
	@echo ""
	@echo "Some Waf commands can be executed without the need of prefixing the target name"
	@echo "with 'waf-'. They are: $(EXPLICIT_COMMANDS)"
	@echo ""
	@echo "Waf flags"
	@echo "---------"
	@echo ""
	@echo "The variable WAF_FLAGS can be used to set any waf command line options that"
	@echo "come to be necessary. Ex: make linux WAF_FLAGS='-c no'"
	@echo ""

# Don't run in parallel, let waf take care of that.
.NOTPARALLEL:

总结:
指定了ROOT目录为ardupilot,编译解析路径WAF_BINARY为“ardupilot/modules/waf/waf_light.py”

ardupilot/waf.py

#!/usr/bin/env python

from __future__ import print_function
import subprocess
import os.path as p
import sys

d = p.dirname(p.realpath(__file__)) //__file__指ardupilot/Makefile文件,返回路径“ardupilot/”
waf_light = p.join(d, 'modules', 'waf', 'waf-light') "waf_light= ardupilor/modules//waf/waf-light"

python = sys.executable //python作为系统执行语言

try:
    subprocess.check_call([python, waf_light] + sys.argv[1:]) //执行进程 sys.argv[0]为当前路径,sys.argv[1:]为输入的waf命令
    
except subprocess.CalledProcessError as e:
    if e.returncode != 2 or p.isfile(waf_light):
        sys.exit(1)

    print('Missing waf submodule. Trying to get it')

    try:
        subprocess.check_call(['git', 'submodule', 'update', '--init',
                               'modules/waf'])
    except subprocess.CalledProcessError:
        print('Could not update submodule', file=sys.stderr)
        sys.exit(1)

    print('Submodules OK, try running again')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值