$ mkdir hello-1.0
$ cd hello-1.0
$ vi hello.c
#include <stdio.h> int main() { int i; printf("hello world\n"); for ( i = 0; i < 10 ; i++ ) { printf("loop count = %d\n", i); } printf("hello this is the end\n"); return 0; }
$ vi Makefile
EXEC = hello
OBJS = hello.o
all: $(EXEC)
$(EXEC): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS$(LDLIBS_$@))
romfs:
$(ROMFSINST) /bin/$(EXEC)
clean:
rm -f $(EXEC) *.elf *.gdb *.o
$ make clean
$ cd ..
$ tar czvf hello-1.0.tar.gz hello-1.0
$ mv hello-1.0.tar.gz /opt/freescale/pkgs/
$ cd ~/ltib/
$ mkdir dist/lfs-5.1/hello
$ cp dist/lfs-5.1/template/template.spec dist/lfs-5.1/hello/hello.spec
$ vi dist/lfs-5.1/hello/hello.spec
%define pfx /opt/freescale/rootfs/%{_target_cpu} Summary : hello print demo Name : hello Version : 1.0 Release : 1 License : BSD Vendor : lht Packager : xxxx Group : Applications/Communications URL : http://www.test.com Source : %{name}-%{version}.tar.gz BuildRoot : %{_tmppath}/%{name} Prefix : %{pfx} %Description %{summary} %Prep %setup %Build make %Install rm -rf $RPM_BUILD_ROOT mkdir -p $RPM_BUILD_ROOT/%{pfx}/usr/bin cp hello $RPM_BUILD_ROOT/%{pfx}/usr/bin/ %Clean rm -rf $RPM_BUILD_ROOT %Files %defattr(-,root,root) %{pfx}/*
$ ./ltib -m prep -p hello.spec
$ ./ltib -m scbuild -p hello.spec
$ ./ltib -m scinstall -p hello.spec
$ ./ltib -m scdeploy -p hello.spec
如果一切正常,则hello可执行程序就在rootfs/usr/bin目录了。
$ vi ~/ltib/config/userspace/packages.lkc #添加下面内容
config PKG_HELLO bool "hello"
$ vi ~/ltib/config/userspace/pkg_map #添加下面的内容
PKG_HELLO = hello
$ ./ltib -c
根据提示进入package list选项,选择[X] hello (NEW)
然后重新编译即可
注意!如果提示rpm/BUILD/hello-1.0目录已经存在,就手动删除该目录重新执行./ltib就可以编译了。