The Contiki build system

The Contiki build system

http://contiki.sourceforge.net/docs/2.6/a01796.htmlhtml

先看官方文檔的說明,對contiki的構建系統有個整體的概覽。express

The Contiki build system
========================

The Contiki build system is designed to make it easy to compile Contiki
applications for different hardware platforms or into a simulation platform by
simply supplying different parameters to the make command, without having to
edit makefiles or modify the application code.

The file example project in examples/hello-world/ shows how the Contiki build
system works. The hello-world.c application can be built into a complete
Contiki system by running make in the examples/hello-world/ directory. Running
make without parameters will build a Contiki system using the native target.
The native target is a special Contiki platform that builds an entire Contiki
system as a program that runs on the development system. After compiling the
application for the native target it is possible to run the Contiki system with
the application by running the file hello-world.native. To compile the
application and a Contiki system for the ESB platform the command make
TARGET=esb is used. This produces a hello-world.esb file that can be loaded
into an ESB board.

To compile the hello-world application into a stand-alone executable that can
be loaded into a running Contiki system, the command make hello-world.ce is
used. To build an executable file for the ESB platform, make TARGET=esb
hello-world.ce is run.

To avoid having to type TARGET= every time make is run, it is possible to run
make TARGET=esb savetarget to save the selected target as the default target
platform for subsequent invocations of make. A file called Makefile.target
containing the currently saved target is saved in the project's directory.

Beside TARGET= there's DEFINES= which allows to set arbitrary variables for the
C preprocessor in form of a comma-separated list. Again it is possible to avoid
having to re-type i.e. DEFINES=MYTRACE,MYVALUE=4711 by running make TARGET=esb
DEFINES=MYTRACE,MYVALUE=4711 savedefines. A file called Makefile.esb.defines is
saved in the project's directory containing the currently saved defines for the
ESB platform.

Makefiles used in the Contiki build system The Contiki build system is composed
of a number of Makefiles. These are:

* Makefile: the project's makefile, located in the project directory.

* Makefile.include: the system-wide Contiki makefile, located in the root of
  the Contiki source tree.

* Makefile.$(TARGET) (where $(TARGET) is the name of the platform that is
  currently being built): rules for the specific platform, located in the
  platform's subdirectory in the platform/ directory.

* Makefile.$(CPU) (where $(CPU) is the name of the CPU or microcontroller
  architecture used on the platform for which Contiki is built): rules for the
  CPU architecture, located in the CPU architecture's subdirectory in the cpu/
  directory.

* Makefile.$(APP) (where $(APP) is the name of an application in the apps/
  directory): rules for applications in the apps/ directories. Each application
  has its own makefile.

The Makefile in the project's directory is intentionally simple. It specifies
where the Contiki source code resides in the system and includes the
system-wide Makefile, Makefile.include. The project's makefile can also define
in the APPS variable a list of applications from the apps/ directory that
should be included in the Contiki system. The Makefile used in the hello-world
example project looks like this:

    CONTIKI_PROJECT = hello-world
    all: $(CONTIKI_PROJECT)

    CONTIKI = ../..
    include $(CONTIKI)/Makefile.include

First, the location of the Contiki source code tree is given by defining the
CONTIKI variable. Next, the name of the application is defined. Finally, the
system-wide Makefile.include is included.

The Makefile.include contains definitions of the C files of the core Contiki
system. Makefile.include always reside in the root of the Contiki source tree.
When make is run, Makefile.include includes the Makefile.$(TARGET) as well as
all makefiles for the applications in the APPS list (which is specified by the
project's Makefile).

Makefile.$(TARGET), which is located in the platform/$(TARGET)/ directory,
contains the list of C files that the platform adds to the Contiki system. This
list is defined by the CONTIKI_TARGET_SOURCEFILES variable. The
Makefile.$(TARGET) also includes the Makefile.$(CPU) from the cpu/$(CPU)/
directory.

The Makefile.$(CPU) typically contains definitions for the C compiler used for
the particular CPU. If multiple C compilers are used, the Makefile.$(CPU) can
either contain a conditional expression that allows different C compilers to be
defined, or it can be completely overridden by the platform specific makefile
Makefile.$(TARGET).
The Contiki build system

 

 總結以下: (注:以hello-world爲例子)app

 

1. Contiki 的構建系統使編譯Contiki應用程序很簡單,只須要給make命令提供不一樣的參數,就能夠把Contiki應用程序編譯成不一樣平臺不一樣應用程序的可執行文件,而不用去修改makefiles或者應用程序代碼。ide

 

2. make 默認會編譯成本機(native target)可執行文件,編譯完的文件(如hello-world.native)可運行在咱們的開發環境上。
ui

 

3. 指定平臺,能夠在make命令增長TARGET參數,如指定平臺esb,將會生成hello-world.esb文件this

make TARGET=esb

 

4. 編譯成Contiki運行時可加載的文件,則須要執行如下命令spa

make TARGET=esb hello-world.ce

 

5. 爲了不每次執行make命令都要輸入TARGET變量,可運行以下命令操作系統

make TARGET=esb savetarget

將TARGET= esb 保存在Makefile.target文件中,做爲默認的TARGET..net

 

6. 除了TARGET參數,還有DEFINES參數,可爲c預處理設定任意的變量code

make TARGET=esb DEFINES=MYTRACE,MYVALUE=4711 savedefines

 一樣可將DEFINES保存在Makefile.esb.defines中,做爲默認的DEFINES。其中esb是平臺名稱。

 

7. Makefiles 文件種類

Makefile: 工程Makefile,可理解爲總控Makefile

Makefile.include: 在Contiki根目錄下, the systme-wide Contiki makefile

Makefile.$(TARGET): 在平臺目錄下,及platform/$(TARGET),rules for the specific platform

Makefile.$(CPU): $(CPU)是cpu的名字,在cpu/$(CPU)目錄下,rules for the CPU architecture

Makefile.$(APP): $(APP)是應用名稱,在apps/$(APP)目錄下,rules for applications

 

8. APPS 變量

APPS變量定義apps/目錄下那些應用程序須要被Contiki 操做系統包含。

Makefile.include會根據APPS包含進全部apps/目錄下相關的makefiles。

 

9. 工程Makefile

    CONTIKI_PROJECT = hello-world
    all: $(CONTIKI_PROJECT)

    CONTIKI = ../..
    include $(CONTIKI)/Makefile.include

工程Makefile通常都比較簡單,定義Contiki 源代碼的根目錄位置,用變量CONTIKI存儲。

包含Makefile.include文件。

也還能夠定義APPS變量,包含所需的應用。

 

10. Makefile.include

The Makefile.include contains definitions of the C files of the core Contiki system. Makefile.include always reside in the root of the Contiki source tree.
When make is run, Makefile.include includes the Makefile.$(TARGET) as well as
all makefiles for the applications in the APPS list (which is specified by the
project's Makefile).

 

11. Makefile.$(TARGET)

Makefile.$(TARGET), which is located in the platform/$(TARGET)/ directory,
contains the list of C files that the platform adds to the Contiki system. This
list is defined by the CONTIKI_TARGET_SOURCEFILES variable. The
Makefile.$(TARGET) also includes the Makefile.$(CPU) from the cpu/$(CPU)/
directory.

 

12. Makefile.$(CPU)

The Makefile.$(CPU) typically contains definitions for the C compiler used for
the particular CPU. If multiple C compilers are used, the Makefile.$(CPU) can
either contain a conditional expression that allows different C compilers to be
defined, or it can be completely overridden by the platform specific makefile
Makefile.$(TARGET).
相關文章
相關標籤/搜索