contiki 3.x:关于源码Makefile架构逻辑(1)

认识了源码结构,如今终于能够学习怎么编译了。linux

上一次的帖子说道,源码的目录结构,如今咱们看看makefile的目录:web

[leonard@Archlinux contiki]$ tree -L 5 | grep Makefile 
│   │   └── Makefile.about
│   │   ├── Makefile.antelope
│   │   └── Makefile.at-master
.
.
.
│   │   ├── Makefile.webbrowser
│   │   ├── Makefile.webserver
│       ├── Makefile.webserver-nano
│   │   │       ├── Makefile.tsch
│   │   │   ├── Makefile
│   │   │   ├── Makefile.c128.defines
│   │   │   ├── Makefile.c64.defines
│   │   │   └── Makefile.target
│   │   │   ├── Makefile
│   │   │   ├── Makefile.apple2enh.defines
│   │   │   ├── Makefile.atarixl.defines
│   │   │   ├── Makefile.c128.defines
│   │   │   ├── Makefile.c64.defines
│   │   │   └── Makefile.target
│   │   ├── Makefile.6502
│   │   ├── Makefile.customrules-6502
│   │   │   ├── Makefile.aducrf101
│   │   │   ├── Makefile.aducrf101.gnu
│   │   │   ├── Makefile.aducrf101.iar
│   │   │   ├── Makefile.at91sam7s
│   │   │   │   ├── Makefile.sdcard
│   │   │       ├── Makefile.usb
│   │   │   ├── Makefile.stm32f103
│   │       ├── Makefile.stm32l152
│   │       ├── Makefile.stm32l152.gnu
│   │       ├── Makefile.stm32l152.iar
│   │   ├── Makefile.avr
│   │   │   │   └── Makefile.ieee-manager
│   │   │   │   ├── Makefile.mac
│   │   │   ├── Makefile.radio
│   │   │   │   ├── Makefile.rf230
│   │   │       ├── Makefile.rf230bb
│   │   ├── Makefile.cc2538
│   │   ├── Makefile.cc253x
│   │   ├── Makefile.customrules-cc253x
│   │       ├── Makefile.usb
│   │   ├── Makefile.cc13xx
│   │   ├── Makefile.cc26xx
│   │   ├── Makefile.cc26xx-cc13xx
│   │   │   ├── Makefile.lib
│   │   ├── Makefile.include
│   │   ├── Makefile.mc1322x
│   │   │   ├── Makefile.src
│   │   │   ├── Makefile
│   │   │   │   └── Makefile
│   │   ├── Makefile.msp430
│   │   ├── Makefile.native
│   │   ├── Makefile.nrf52832
│   │   ├── Makefile.pic32
│   │   ├── Makefile.rl78
│   │   │   ├── Makefile
│   │   ├── Makefile.stm32w108
│   │   │   ├── Makefile
│       ├── Makefile.x86_common
│       ├
    .
    .
    .
    .
    .
│   ├── Makefile
│   ├── Makefile.compile-test
│   ├── Makefile.simulation-test
│   │   └── Makefile
│   │   └── Makefile
│   │   ├── Makefile
│   │   ├── Makefile
│   ├── Makefile
│   │   ├── Makefile
│   │       ├── Makefile
│   │   ├── Makefile.powertrace
│   │   │   └── Makefile
│   │   │   ├── Makefile
│   │   │   └── Makefile.platform
│   │   ├── Makefile
│   │   ├── Makefile.raven
│   │   ├── Makefile.sky
│   │   ├── Makefile
│   │   │   ├── Makefile.am
│   │       ├── Makefile
│   │   ├── Makefile
│   │   │   ├── Makefile
│   │       ├── Makefile
│   │   ├── Makefile
│   │   │   ├── Makefile
    ├── Makefile
    ├── Makefile.target

找找规律看,经过打印信息,咱们看一看到Makefile文件是否是颇有特色的,我总结一下,app

Makefile
Makefile.include
Makefile.{APP}
Makgefie.{TARGET}
Makefile.target
Makefile.TARGET.defines

Makefile确定是入口了,那么其余的是干什么用的呢,那咱们一块儿继续往下探究。从简单到复杂,从example的helloword开始找头绪。ide

CONTIKI_PROJECT = hello-world
all: $(CONTIKI_PROJECT)

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

这么简单,。。。。原来主体的Makefile 是Makefile.include,那咱们来本身建立一个helloword试试,回到contiki的主目录,建立一个ts文件夹,Makefile,仿照helloword的源码,写一个hellocontiki.c,以下学习

#include "contiki.h"

#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/
PROCESS(hello_world_process, "Hello Contiki");
AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
  PROCESS_BEGIN();

  printf("Hello, Contiki\n");

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/

Makefilecode

CONTIKI_PROJECT = hellocontiki
all: $(CONTIKI_PROJECT)


include ../Makefile.include

OK。。咱们Make一下,orm

[leonard@Archlinux ts]$ make
../Makefile.include:4: *** CONTIKI not defined! You must specify where Contiki resides。 中止。

出错了... 看看提示,原来那个CONTIKI = ../.. 不单单是赋值的语句这个应该是全局的path,咱们加进去看看server

CONTIKI_PROJECT = hellocontiki
all: $(CONTIKI_PROJECT)

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

继续Make下ci

[leonard@Archlinux ts]$ make
TARGET not defined, using target 'native'
mkdir obj_native
  .....
  CC        ../core/net/mac/nullrdc.c
  CC        ../core/ctk/ctk-textentry-cmdline.c
  CC        ../core/ctk/ctk-filedialog.c
  CC        ../core/ctk/ctk-textentry-checkbox.c
  CC        ../core/ctk/ctk-textentry-multiline.c
  CC        ../core/ctk/ctk.c
  CC        ../core/net/llsec/nullsec.c
  CC        ../core/net/llsec/anti-replay.c
  CC        ../core/net/llsec/ccm-star-packetbuf.c
cp ../tools/empty-symbols.c symbols.c
cp ../tools/empty-symbols.h symbols.h
  CC        symbols.c
  AR        contiki-native.a
  CC        hellocontiki.c
  LD        hellocontiki.native
rm hellocontiki.co
[leonard@Archlinux ts]$

看来咱们猜的没错。。。。。。。。。编译成功了。最后LD文件是 hellocontiki.native,运行下试试。get

[leonard@Archlinux ts]$ ./hellocontiki.native 
Contiki-3.x-2904-g6157dce started with IPV6, RPL
Rime started with address 1.2.3.4.5.6.7.8
MAC nullmac RDC nullrdc NETWORK sicslowpan
Tentative link-local IPv6 address fe80:0000:0000:0000:0302:0304:0506:0708
Hello, Contiki

哈哈哈,竟然能够运行。咱们对比一下编译先后的目录。

contiki-native.a    hellocontiki.c       Makefile    symbols.c
contiki-native.map  hellocontiki.native  obj_native  symbols.h

增长了项目目录和执行的文件还有symbols.c.有个案例结束了,咱们就能够看Makefile.include源码了。。

同时,到这儿咱们也能够开始建立本身最简单的helloword了

由于时间缘由,其余的makefile下次再说。。

相关文章
相关标签/搜索