Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1924494
  • 博文数量: 261
  • 博客积分: 8073
  • 博客等级: 中将
  • 技术积分: 2363
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-10 15:23
文章分类

全部博文(261)

文章存档

2013年(1)

2012年(1)

2011年(50)

2010年(34)

2009年(4)

2008年(17)

2007年(55)

2006年(99)

分类:

2006-04-21 17:24:56

前些天移植完uCLinux后想自己写LCD应用程序并编译到uCLinux的romfs中,在网络中搜索了半天,愣是没找到一篇相关的介绍,而关于Makefile的编写的资料倒是很多,看了好长时间也没什么用处。最好经摸索思考,终于成功,特写出方法供大家参考。
    注意:OS_HOME为您的uCLinux/Linux源代码根目录。

一、 编写自己的源程序代码:

uCLinux/Linux应用程序通常存放在OS_HOME/user目录下,我们在该目录下创建一个Hello目录,并创建Hello.c文件,输入以下代码,该程序即大家最常见的Hello world!。

Hello world应用程序

Hello.c
#include
#include
void main()
{
       printf(“Hello world!”);
}

--------------------------------------------------------------------------------------------

二、为Hello world编写Makefile文件。该文件存放在OS_HOME\user\hello\下

Makefile

--------------------------------------------------------------------------------------------

#########################################################

# uclinux project type.

#########################################################

EXEC = Hello

OBJS = Hello.o

CFLAGS += -I.

all: $(EXEC)

$(EXEC): $(OBJS)

       $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)

romfs:

       $(ROMFSINST) /bin/$(EXEC)

clean:

       -rm -f $(EXEC) *.elf *.gdb *.o

-------------------------------------------------------------------------------------------

    上面的代码我就不解释了,大家参考相关文件,注意Hello为可执行文件名,Hello.o为目标文件名,大家可以根据自己的工程来修改。

三、修改uCLinux/Linux的相关配置文件。

这里需要修改的文件有:OS_HOME/user/Makefile,OS_HOME/config/config.in两个文件,下面分别针对uCLinux和Linux讲解

1. uCLinux中修改OS_HOME/user/Makefile文件

打开OS_HOME/user/Makefile:

--------------------------------------------------------------------------------------------

#

#     Makefile -- Build instructions for user level apps

#

.EXPORT_ALL_VARIABLES:

#

# Include architecture specific build rules.

#

ifndef ROOTDIR

ROOTDIR=..

endif

UCLINUX_BUILD_USER=1

include $(LINUX_CONFIG)

include $(CONFIG_CONFIG)

include $(ARCH_CONFIG)

-include $(MODULES_CONFIG)

VEND=$(ROOTDIR)/vendors

#

# must run the vendor build first

#

dir_y = $(VEND)/$(CONFIG_VENDOR)/$(CONFIG_PRODUCT)/.

dir_n =

dir_  =

dir_$(CONFIG_JFFS_FS)                       += mtd-utils

dir_$(CONFIG_JFFS2_FS)                      += mtd-utils

……(中间略去)

dir_$(CONFIG_USER_WLG3)                   += wlg3

dir_$(CONFIG_USER_TEST111)               += test111

dir_$(CONFIG_USER_HELLO)                  += Hello

dir_y +=

all:

       for i in $(dir_y) ; do  make -C $$i || exit $? ; done

romfs:

       for i in $(dir_y) ; do  make -C $$i romfs || exit $? ; done

clean:

       -for i in $(dir_y) $(dir_n) $(dir_) ; do \

              [ ! -d $$i ] || make -C $$i clean; \

       Done

添加代码,上面代码中灰底蓝字部分。该行代码中CONFIG_USER_HELLO定义一个符号,在其他文件中用到,+= Hello为应用程序的相对路径。

2. uCLinux中修改OS_HOME/config/config.in

打开OS_HOME/config/config.in文件

--------------------------------------------------------------------------------------------
##################################################################

#

# NOTE : it is fairly important that changes to this file consider their

#        effect on other platforms and default setups.  If you can, only

#        add to the file,  changing the name of a variable will break

#        many configurations.

#

#################################################################

mainmenu_name "uClinux Application Configuration"

#################################################################

mainmenu_option next_comment

comment 'Core Applications'

bool 'init'                      CONFIG_USER_INIT_INIT

……(中间略去)

endmenu

#################################################################

mainmenu_option next_comment

comment 'Jian hua test project'

bool 'bulud ucLinux project'                 CONFIG_USER_UCLINUXPRO

endmenu

#################################################################

mainmenu_option next_comment

comment 'Build my project:Hello'

bool 'build project that named Hello'                    CONFIG_USER_HELLO

endmenu

#################################################################

--------------------------------------------------------------------------------------------

在该文件末尾添加代码如上中的灰底蓝字部分。comment 'Build my project:Hello' 用于添加一个名为“Build my project:Hello”的主菜单项,bool 'build project that named Hello'                    CONFIG_USER_HELLO用于在刚才建立的主菜单项下建立名为build project that named Hello的子菜单项,CONFIG_USER_HELLO必须和您添加在OS_HOME/user/Makefile文件中的符号相同。

这样所有的文件就修改好了

执行Make config 或make xconfig就可以重新配置uCLinux。

阅读(2164) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~