Contiki OS中build system


build-system帮助文档

Contiki build system被设计用来简单化Contiki应用的编译,不管是硬件平台还是仿真平台。这是通过给make命令提供不同的参数来实现的,而不用编辑编译文件(makefile)。

Makefile
一个工程中的源文件不计其数,其按类型、功能、模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 makefile就像一个Shell脚本一样,其中也可以执行操作系统的命令。

Contiki OS中的Makefile文件
Contiki编译系统(build system)是由大量的Makefiles(编译文件、配置文件)组成。这些Makefile文件如下所列:

Makefile :工程的编译文件,位于工程目录下

Makefile.include :系统范围的Contiki编译文件,位于Contiki源文件的根目录下

Makefile.TARGET :TARGET代表当前编译的平台名称,位于platform目录的子目录下

Makefile.CPU :CPU表示Contiki系统所编译平台的CPU或微控制器架构的名字,位于CPU目录下的CPU架构的子目录下

Makefile.APP :APP代表apps目录的应用的名字,是该目录下应用的规则,每个应用有自己的编译文件

工程目录下的Makefile文件很容易理解,它说明了Contiki源文件在系统中的驻留位置,也包括系统编译文件Makefile.include的位置。工程的编译文件也指明了apps目录下应当被包括在Contiki系统中的应用。在hello-world例程的Makefile文件内容如下:
\code
CONTIKI = ../..
all: hello-world
include $(CONTIKI)/Makefile.include
\endcode

(有关contiki makefile的详细编写原则可参考系统自带的帮助文档)


摘自USC anrg:


与上面的论述一直,这里用sky平台做了示例:


Overview

Contiki has a useful and complex build system that consists of multiple Makefiles. These multiple Makefiles make it simple to compile code for different platforms and with different parameters. We do not need to worry about editing the Makefile; instead we can just reuse the files available in the distribution. A complete documentation of the build system can be found here and here

The base Makefile file is located in the root directory: contiki/Makefile.include. It must be included in the user's Makefile. Depending on the target platform, which must be specified by the user, other Makefiles are merged before compilation. The other Makefile may be platform or cpu-dependent, and they can be found in folders: contiki/platform/*/Makefile.platform' and contiki/cpu/*/Makefile.cpu.


Changing the Platform

The default target is native, which compiles code to be executed on the host machine (x86). Other available targets are: "z1, wismote, stk500, sky, etc.". The Sky Motes used in ANRG lab should be burned using target sky.
To compile a code for sky platform we should simply type make TARGET=sky. To compile for default (native) platform, we should simply type make. It is possible to change the default platform typing make TARGET=sky savetarget. This creates a file Makefile.target with the definition of the new default platform. The process of defining the default platform affects only the application being developed inside the current directory. If you change your path to another directory where Makefile.target does not exist, the default target will be native again.

Build system can also be used to upload the compiled firmware into the platforms. We just need to append ".upload" to the end of the firmware file name. In order to upload hello-world application, for instance, we should type make hello-world.upload.


Serial Interface

Make can also be used to invoke serial-dump-linux application and open the serial port with target platform. Typing make login, for example, opens up a serial connection with the first device connected to the development machine (usually at /dev/ttyS0). Once in the serial interface, type help to get a list of commands.

你可能感兴趣的:(OS,makefile,编译系统,contiki,build-system)