aos make 配置环境
在一臺(tái) Ubuntu 14.04 LTS 64-bit PC 上
?
sudo apt-get install -y python sudo apt-get install -y gcc-multilib sudo apt-get install -y libssl-dev libssl-dev:i386 sudo apt-get install -y libncurses5-dev libncurses5-dev:i386 sudo apt-get install -y libreadline-dev libreadline-dev:i386 sudo apt-get install -y python-pip sudo apt-get install -y minicom2.2安裝 aos-cube
首先, 用 python 包管理器 pip 來(lái)安裝 aos-cube 和相關(guān)的依賴包在全局環(huán)境,以便于后續(xù)使用 AliOS Things Studio 進(jìn)行開發(fā)。
?
$ pip install setuptools $ pip install wheel $ pip install aos-cube請(qǐng)確認(rèn)pip環(huán)境是基于 Python 2.7 的。如果遇到權(quán)限問(wèn)題,可能需要 sudo 來(lái)執(zhí)行。
如果在線安裝aos-cube失敗,可以下載源碼安裝,方法如下:
- 先下載你要安裝的包,并解壓(aos-cube-0.2.46.tar.gz)
- $ cd aos-cube-0.2.46
- $ python setup.py build
- $ python setup.py install
2.3下載代碼并編譯運(yùn)行
?
git clone https://github.com/alibaba/AliOS-Things.git cd AliOS-Things aos make helloworld@linuxhost ./out/helloworld@linuxhost/binary/helloworld@linuxhost.elf2.4效果
可以看見 app_delayed_action 在1秒時(shí)啟動(dòng),每5秒觸發(fā)一次。
?
[ 0.000]<V> AOS [application_start#15] : application started.[ 1.000]<V> AOS [app_delayed_action#9] : helloworld app_delayed_action:9 app_task[ 6.000]<V> AOS [app_delayed_action#9] : helloworld app_delayed_action:9 app_task[ 11.000]<V> AOS [app_delayed_action#9] : helloworld app_delayed_action:9 app_task[ 16.000]<V> AOS [app_delayed_action#9] : helloworld app_delayed_action:9 app_task[ 21.000]<V> AOS [app_delayed_action#9] : helloworld app_delayed_action:9 app_task3 編譯過(guò)程
3.1 aos
2.2小結(jié)安裝了aos-cube,aos-cube封裝了一系列 AliOS Things使用的 Python包。
官方注解如下:
?
aos command line tool for repositories version control, publishing and updating code from remotely hosted repositories, and invoking aos own build system and export functions, among other operationsaos 用法如下:
?
[naiquanhu@naiquanhu-VirtualBox AliOS-Things]$ aos --help usage: aos [-h] [--version] ...Code management tool for aos - https://code.aliyun.com/aos/aos version 0.2.46Use 'aos <command> -h|--help' for detailed help. Online manual and guide available at https://code.aliyun.com/aos/aos-cubeoptional arguments:-h, --help show this help message and exit--version print version number and exitCommands:new Create new aos program or componentls List cube info, default components infoimport Import program from URLadd Add component from AOS_SDK_PATH or URLrm Remove componentdeploy Find and add missing components and source codescodes Import the optional component from the remote repositorypublish Publish program or componentupdate Update to branch, tag, revision or latestsync Synchronize aos component referencesstatus Show version control statusmake Make aos program/componentscons Make aos program/component by sconsmakelib Compile static libraryconfig Tool configurationupload Upload aos imagemonitor Serial port monitordevices List devices on serial portsupgrade Upgrade aos-cube to latesthelp This help screen看一下aos程序內(nèi)容:
?
which aos/usr/local/bin/aos
vi /usr/local/bin/aos
?
#!/usr/bin/python # EASY-INSTALL-ENTRY-SCRIPT: 'aos-cube==0.2.46','console_scripts','aos' __requires__ = 'aos-cube==0.2.46' import sys from pkg_resources import load_entry_pointif __name__ == '__main__':sys.exit(load_entry_point('aos-cube==0.2.46', 'console_scripts', 'aos')())/usr/local/bin/aos會(huì)調(diào)用aos-cube-0.2.46/aos/aos.py
3.2 aos調(diào)用make過(guò)程
?
aos make helloworld@linuxhost該命令會(huì)首先進(jìn)入aos/aos.py中的main()
?
def _run_make(arg_list):#install dependent toolchains_install_toolchains(sys.argv[2:])# check operating systemhost_os = get_host_os()if host_os == None:error('Unsupported Operating System!')#cd to aos root_dirret, original_dir = cd_aos_root()if ret != 'success':error("not in AliOS-Things source code directory")make_cmds = {'Win32': 'cmd/win32/make.exe','Linux64': 'cmd/linux64/make','Linux32': 'cmd/linux32/make','OSX': 'cmd/osx/make'}tools_dir = os.path.join(os.getcwd(), 'build').replace('\\', '/')make_cmd = os.path.join(tools_dir, make_cmds[host_os])# Run make commandmake_cmd_str = ' '.join([make_cmd, 'HOST_OS=' + host_os, 'TOOLS_ROOT=' + tools_dir] + list(arg_list))popen(make_cmd_str, shell=True, cwd=os.getcwd())if os.path.isdir(original_dir): os.chdir(original_dir)def make_build(make_args):# aos new programif os.path.isfile(os.path.join(os.getcwd(), Cfg.file)):...with cd(os_path):..._run_make(['-e', '-f build/Makefile', make_args, app_dir, build_dir])else:# aos source code_run_make(['-e', '-f build/Makefile', make_args])# Make command @subcommand('make',help='Make aos program/component',description="Make aos program/component.") def make():...args = sys.argv[2:]...make_args = ' '.join(args)for arg in args:if '@' in arg: targets = arg.split('@')...board = targets[1]if board in get_scons_enabled_boards():scons_build(args)else:make_build(make_args)return#aos make clean go heremake_build(make_args)def main():...# Parse/run commandif len(sys.argv) <= 1:help_()sys.exit(1)...pargs, remainder = parser.parse_known_args()status = 1try:...status = pargs.command(pargs)except ProcessException as e:...sys.exit(status or 0)if __name__ == "__main__":main()簡(jiǎn)單來(lái)說(shuō),調(diào)用關(guān)系如下:
?
aos make helloworld@linuxhost|-- make()|-- make_build()|-- _run_make(arg_list)|-- popen(make_cmd_str, shell=True, cwd=os.getcwd())變量的值:
build_dir = 'BUILD_DIR=./out/'
app_dir = 'APPDIR=./'
make_args = helloworld@linuxhost
arg_list = ['-e', '-f build/Makefile', make_args, app_dir, build_dir]
make_cmd = ./build/cmd/linux64/make
make_cmd_str = make_cmd + 'HOST_OS=Linux64' + 'TOOLS_ROOT=./build' + + list(arg_list)
其中,popen是Python的標(biāo)準(zhǔn)庫(kù)中的subprocess包的類,用來(lái)fork一個(gè)子進(jìn)程并運(yùn)行一個(gè)外部程序,進(jìn)入 ./build/Makefile
3.3 make入口
build/Makefile是make的主入口,傳入的參數(shù)有:
HOST_OS=Linux64
TOOLS_ROOT=./build
BUILD_DIR=./out/
APPDIR=./
make_args = helloworld@linuxhost
我們先來(lái)看看build/Makefile中的一些關(guān)鍵內(nèi)容:
?
export SOURCE_ROOT ?= ./ #AliOS-Things 的根目錄 export MAKEFILES_PATH := $(SOURCE_ROOT)/build #MAKEFILES_PATH = ./build export SCRIPTS_PATH := $(SOURCE_ROOT)/build/scripts #SCRIPTS_PATH = ./build/scripts MAKEFILE_TARGETS := clean#define BUILD_STRING, AOS toolchain commands on different hosts include $(MAKEFILES_PATH)/aos_host_cmd.mk #./build/aos_host_cmd.mk接著看一下文件./build/aos_host_cmd.mk:
?
TOOLS_ROOT ?= $(SOURCE_ROOT)build #TOOLS_ROOT = ./build COMPILER_ROOT ?=$(TOOLS_ROOT)/compiler #COMPILER_ROOT = ./build/compiler OPENOCD_PATH := $(TOOLS_ROOT)/OpenOCD/${HOST_OS}/ #OPENOCD_PATH = ./build/OpenOCD/Linux64/ OPENOCD_CFG_PATH := $(MAKEFILES_PATH)/OpenOCD/${HOST_OS}/ #OPENOCD_CFG_PATH = ./build/OpenOCD/Linux64/ JTAG ?= jlink_swd BUILD_DIR ?= out ... COMMON_TOOLS_PATH := $(TOOLS_ROOT)/cmd/linux64/ #COMMON_TOOLS_PATH = ./build/cmd/linux64/ export SHELL = $(COMMON_TOOLS_PATH)dash #SHELL = ./build/cmd/linux64/dash OPENOCD_FULL_NAME := "$(OPENOCD_PATH)bin/openocd" #OPENOCD_FULL_NAME = ./build/OpenOCD/Linux64/bin/openocd ECHO := echo PERL := $(shell which perl) PYTHON := $(shell which python) CLEAN_COMMAND := "$(COMMON_TOOLS_PATH)rm" -rf $(BUILD_DIR) #CLEAN_COMMAND = "./build/cmd/linux64/rm" -rf out MKDIR = "$(COMMON_TOOLS_PATH)mkdir" -p $1 #MKDIR = "./build/cmd/linux64/mkdir" -p $1 RMDIR = "$(COMMON_TOOLS_PATH)rm" -rf $1 #RMDIR = "./build/cmd/linux64/rm" -rf $1 CPDIR = "$(COMMON_TOOLS_PATH)cp" -rf $1 $2 #CPDIR = "./build/cmd/linux64/cp" -rf $1 $2 TRUE_CMD := true FALSE_CMD := false RM := "$(COMMON_TOOLS_PATH)rm$(EXECUTABLE_SUFFIX)" -f #RM = "./build/cmd/linux64/rm" -f CP := "$(COMMON_TOOLS_PATH)cp$(EXECUTABLE_SUFFIX)" -f #CP = "./build/cmd/linux64/cp" -f MAKE := "$(COMMON_TOOLS_PATH)make$(EXECUTABLE_SUFFIX)" #MAKE = "./build/cmd/linux64/make" BIN2C := "$(COMMON_TOOLS_PATH)bin2c$(EXECUTABLE_SUFFIX)" #BIN2C = "./build/cmd/linux64/bin2c" CURRENT_TIME = $(shell $(DATE) +%Y%m%d.%H%M) SHOULD_I_WAIT_FOR_DOWNLOAD := $(filter download, $(MAKECMDGOALS)) #因?yàn)镸AKECMDGOALS = helloworld@linuxhost,所以 SHOULD_I_WAIT_FOR_DOWNLOAD = null BUILD_STRING ?= $(strip $(filter-out $(MAKEFILE_TARGETS) download run total, $(MAKECMDGOALS))) #BUILD_STRING = "helloworld@linuxhost" BUILD_STRING_TO_DIR = $(subst .,/,$(1)) #BUILD_STRING_TO_DIR = null DIR_TO_BUILD_STRING = $(subst /,.,$(1)) #DIR_TO_BUILD_STRING = null CLEANED_BUILD_STRING := $(BUILD_STRING) #CLEANED_BUILD_STRING = "helloworld@linuxhost" OUTPUT_DIR := $(BUILD_DIR)/$(CLEANED_BUILD_STRING)$(MBINS) #OUTPUT_DIR = "out/helloworld@linuxhost" AUTO_COMPONENT_DIR := $(OUTPUT_DIR)/auto_component #AUTO_COMPONENT_DIR = "out/helloworld@linuxhost/auto_component"主要設(shè)置了一些和host os相關(guān)的參數(shù)。
接著build/Makefile文件繼續(xù)看,由于IDE = null,則COMPILER = null
?
include $(MAKEFILES_PATH)/aos_toolchain_gcc.mk AUTO_COMPONENT = $(AUTO_COMPONENT_DIR)/auto_component.mk #AUTO_COMPONENT = "out/helloworld@linuxhost/auto_component/auto_component.mk" TEST_COMPONENT_COLLECTION = $(AUTO_COMPONENT_DIR)/test_collection.default #TEST_COMPONENT_COLLECTION = "out/helloworld@linuxhost/auto_component/test_collection.default"$(AUTO_COMPONENT): $(TEST_COMPONENT_COLLECTION)$(QUIET)$(PYTHON) $(MAKEFILES_PATH)/scripts/auto_component.py $(AUTO_COMPONENT_DIR)$(TEST_COMPONENT_COLLECTION):$(QUIET)$(PYTHON) $(MAKEFILES_PATH)/scripts/gen_test_collection.py $(AUTO_COMPONENT_DIR) $(TEST_COMPONENT_COLLECTION)設(shè)置完一些變量的值后,執(zhí)行2條python指令:
?
python ./build/scripts/gen_test_collection.py ./out/helloworld@linuxhost/auto_component ./out/helloworld@linuxhost/auto_component/test_collection.defaultpython ./build/scripts/auto_component.py ./out/helloworld@linuxhost/auto_component命令:
?
aos make helloworld@linuxhost該命令最先調(diào)用的targe是main_app:
?
main_app: $(OUTPUT_DIR)/config.mk $(YOS_SDK_PRE_APP_BUILDS) $(MAKEFILES_PATH)/aos_target_build.mk$(if $(BINS_ERROR), $(call BINS_EXIT))$(if $(MBINS_ERROR), $(call MBINS_EXIT))$(QUIET)$(ECHO) Build AOS Now$(QUIET)$(ECHO) TOOLCHAIN_PATH=$(TOOLCHAIN_PATH)$(QUIET)$(call MKDIR, $(OUTPUT_DIR)/binary)$(QUIET)$(call MKDIR, $(OUTPUT_DIR)/modules)$(QUIET)$(call MKDIR, $(OUTPUT_DIR)/libraries)$(QUIET)$(call MKDIR, $(OUTPUT_DIR)/resources)$(QUIET)$(PYTHON) $(MAKEFILES_PATH)/scripts/gen_auto_code.py $(OUTPUT_DIR)/config.mk $(AUTO_COMPONENT_DIR)$(QUIET)$(MAKE) -r $(JOBSNO) $(SILENT) -f $(MAKEFILES_PATH)/aos_target_build.mk $(CLEANED_BUILD_STRING) $(PASSDOWN_TARGETS)$(QUIET)$(ECHO) Build completemain_app又依賴$(OUTPUT_DIR)/config.mk,即out/helloworld@linuxhost/config.mk,所以先調(diào)用build/aos_target_config.mk生成out/helloworld@linuxhost/config.mk,完成后,主要做了兩件事:
- /usr/bin/python .//build/scripts/gen_auto_code.py out/helloworld@linuxhost/config.mk out/helloworld@linuxhost/auto_component
根據(jù)out/helloworld@linuxhost/config.mk生成out/helloworld@linuxhost/auto_component下的文件。 - ./build/cmd/linux64/make -r -j4 -f .//build/aos_target_build.mk helloworld@linuxhost
進(jìn)入./build/aos_target_build.mk 繼續(xù)編譯。
作者:蝴蝶泉nq
鏈接:https://www.jianshu.com/p/5388f6754b59
來(lái)源:簡(jiǎn)書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。
總結(jié)
以上是生活随笔為你收集整理的aos make 配置环境的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: E:Unable to locate p
- 下一篇: sourceinsight如何显示完整文