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

认识了源码结构,现在终于可以学习怎么编译了。

上一次的帖子说道,源码的目录结构,现在我们看看makefile的目录:

[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文件是不是很有特点的,我总结一下,

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

Makefile肯定是入口了,那么其他的是干什么用的呢,那我们一起继续往下探究。从简单到复杂,从example的helloword开始找头绪。

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();
}
/*---------------------------------------------------------------------------*/

Makefile

CONTIKI_PROJECT = hellocontiki
all: $(CONTIKI_PROJECT)


include ../Makefile.include

OK。。我们Make一下,

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

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

CONTIKI_PROJECT = hellocontiki
all: $(CONTIKI_PROJECT)

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

继续Make下

[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,运行下试试。

[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下次再说。。

转载于:https://my.oschina.net/wangluxunteng/blog/768405

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值