openwrt下面创建/添加package----Makefile模版

本文介绍了如何在OpenWRT环境中创建并添加自定义package,通过提供一个名为eep的示例,详细说明了package目录结构和两个Makefile的作用。主要涉及交叉编译、依赖管理和编译过程,特别强调了$(CC)、$(LDFLAGS)和$(CFLAGS)在编译过程中的重要性。

openwrt下面创建/添加package----Makefile模版


by:韩大卫@吉林师范大学


**********************

进入 openwrt/package/,


mkdir eep

以eep为示例

cd eep

mkdir src

把代码放在src下面, src 中中的makefile 是用特定的交叉编译器编译自己的代码。

同在 eep 下面还有一个Makefile ,这个makefile  是openwrt 用来查找,添加,编译这个目录(eep)的。编译后的的内容会出现的这个系统中。

编译自己的package, 把下面Makefile 中的 eep  换成自己目录名字即可。

********************************

这个Makefile 是 openwrt/package/eep 下面的。

**********************************

include $(TOPDIR)/rules.mk                                                                                                           

 
PKG_NAME:=eep
PKG_VERSION:=5.0
PKG_RELEASE:=1
 
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)
 
include $(INCLUDE_DIR)/package.mk
 
define Package/$(PKG_NAME)  
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=eep      -- i2c general program
    MAINTAINER:=handawei
endef
 
define Package/$(PKG_NAME)/description
    i2c general program
endef
 
define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef
 
define Package/eep/install
    $(INSTALL_DIR) $(1)/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/eep $(1)/bin/
endef
 
$(eval $(call BuildPackage,eep))

******************************************

下面是src  中的makefile

********************************************


OBJECTS = eep                                                                                                                        
 
all : $(OBJECTS)
 
PKG_NAME=docs
 
eep: main.o i2c.o
    $(CC) $(LDFLAGS) $^ -o $@
 
i2c.o:i2c.c
    $(CC) $(CFLAGS)  -c $<
main.o:main.c
 $(CC) $(CFLAGS)  -c $<
 
.PHONY:clean
clean:
    @-rm *.o  eep
*****************************************

把eep换成自己的目录名字即可。i2c.c 是main.c 的依赖文件。不需要的话删除即可。

另外,$(CC)  是openwrt 的特定交叉编译器,在编译openwrt 时候创建的,在此直接使用即可。

注意:  $(LDFLAGS)  , $(CFLAGS) 是用交叉编译器链接和编译文件时必须要加的标志。很多编译出错的原因都是处在此!!

 


完整的错误报告你看一下 mkdir -p /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25 cp -fpR ./src/* /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25 touch /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.prepared_c2d0a16b7871c64b29f76be535b29d9d (cd /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3/; if [ -x ./configure ]; then /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.guess | xargs -r chmod u+w; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.guess | xargs -r -n1 cp /data/red-round3/red-round3/Iplatform/openwrt/scripts/config.guess; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.sub | xargs -r chmod u+w; /usr/bin/find /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/ -name config.sub | xargs -r -n1 cp /data/red-round3/red-round3/Iplatform/openwrt/scripts/config.sub; AR=arm-buildroot-linux-gnueabi-ar AS=“arm-buildroot-linux-gnueabi-gcc -c -DMAX_DEBUG_LEVEL=-1 -D__location__=\"\" -ffunction-sections -fdata-sections” LD=arm-buildroot-linux-gnueabi-ld NM=arm-buildroot-linux-gnueabi-nm CC=“arm-buildroot-linux-gnueabi-gcc” GCC=“arm-buildroot-linux-gnueabi-gcc” CXX=“arm-buildroot-linux-gnueabi-g++” RANLIB=arm-buildroot-linux-gnueabi-ranlib STRIP=arm-buildroot-linux-gnueabi-strip OBJCOPY=arm-buildroot-linux-gnueabi-objcopy OBJDUMP=arm-buildroot-linux-gnueabi-objdump SIZE=arm-buildroot-linux-gnueabi-size CFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\"\" -ffunction-sections -fdata-sections " CXXFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\"\" -ffunction-sections -fdata-sections " CPPFLAGS=“-I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/usr-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/…/…/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/include " LDFLAGS=”-L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/lib -Wl,-rpath-link,/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/…/…/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/…/…/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/lib -Wl,–gc-sections -lubox -lubus -lifaddrs " ac_cv_lib_attr_getxattr=no ac_cv_search_getxattr=no ac_cv_file__proc_sys_kernel_core_pattern=yes libreplace_cv_HAVE_C99_VSNPRINTF=yes libreplace_cv_HAVE_IFACE_IFCONF=yes libreplace_cv_HAVE_GETADDRINFO=yes LINUX_LFS_SUPPORT=yes samba_cv_CC_NEGATIVE_ENUM_VALUES=yes samba_cv_HAVE_GETTIMEOFDAY_TZ=yes samba_cv_HAVE_IFACE_IFCONF=yes samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=yes samba_cv_HAVE_SECURE_MKSTEMP=yes samba_cv_HAVE_WRFILE_KEYTAB=no samba_cv_USE_SETREUID=yes samba_cv_USE_SETRESUID=yes samba_cv_have_setreuid=yes samba_cv_have_setresuid=yes ac_cv_header_zlib_h=no samba_cv_zlib_1_2_3=no ./configure --target=arm-openwrt-linux-uclibc --host=arm-openwrt-linux-uclibc --build=x86_64-linux-gnu --program-prefix=“” --program-suffix=“” --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --exec-prefix=/usr --prefix=/ --disable-avahi --disable-cups --disable-pie --disable-relro --disable-static --disable-swat --enable-shared-libs --with-codepagedir=/etc/samba --with-configdir=/etc/samba --with-included-iniparser --with-included-popt --with-lockdir=/var/lock --with-logfilebase=/var/log --with-nmbdsocketdir=/var/nmbd --with-piddir=/var/run --with-privatedir=/etc/samba --with-sendfile-support --with-shared-modules=pdb_tdbsam,pdb_wbc_sam,idmap_nss,nss_info_template,auth_winbind,auth_wbc,auth_domain ; fi; ) rm -f /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.configured_* touch /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.configured_ CFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\"\" -ffunction-sections -fdata-sections -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/usr-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/…/…/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/include " CXXFLAGS=" -DMAX_DEBUG_LEVEL=-1 -D__location__=\"\" -ffunction-sections -fdata-sections -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/usr-be220v1/include -I/data/red-round3/red-round3/Iplatform/openwrt/…/…/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/include " LDFLAGS="-L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/lib -Wl,-rpath-link,/data/red-round3/red-round3/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-be220v1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/…/…/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/usr/lib -L/data/red-round3/red-round3/Iplatform/openwrt/…/…/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/lib -Wl,–gc-sections -lubox -lubus -lifaddrs " make -j1 -C /data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3 AR=arm-buildroot-linux-gnueabi-ar AS=“arm-buildroot-linux-gnueabi-gcc -c -DMAX_DEBUG_LEVEL=-1 -D__location__=\"\" -ffunction-sections -fdata-sections” LD=arm-buildroot-linux-gnueabi-ld NM=arm-buildroot-linux-gnueabi-nm CC=“arm-buildroot-linux-gnueabi-gcc” GCC=“arm-buildroot-linux-gnueabi-gcc” CXX=“arm-buildroot-linux-gnueabi-g++” RANLIB=arm-buildroot-linux-gnueabi-ranlib STRIP=arm-buildroot-linux-gnueabi-strip OBJCOPY=arm-buildroot-linux-gnueabi-objcopy OBJDUMP=arm-buildroot-linux-gnueabi-objdump SIZE=arm-buildroot-linux-gnueabi-size CROSS=“arm-buildroot-linux-gnueabi-” ARCH=“arm” DYNEXP= PICFLAG= MODULES= ; make[4]: Entering directory ‘/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3’ make[4]: *** No targets specified and no makefile found. Stop. make[4]: Leaving directory ‘/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3’ Makefile:208: recipe for target ‘/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.built’ failed make[3]: *** [/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.built] Error 2 make[3]: Leaving directory ‘/data/red-round3/red-round3/Iplatform/packages/opensource/samba’ package/Makefile:133: recipe for target ‘package/feeds/iplatform/samba/compile’ failed make[2]: *** [package/feeds/iplatform/samba/compile] Error 2 make[2]: Leaving directory ‘/data/red-round3/red-round3/Iplatform/openwrt’ /data/red-round3/red-round3/Iplatform/openwrt/include/toplevel.mk:184: recipe for target ‘package/samba/compile’ failed make[1]: *** [package/samba/compile] Error 2 make[1]: Leaving directory ‘/data/red-round3/red-round3/Iplatform/openwrtMakefile:234: recipe for target ‘iplatform_package/samba/compile’ failed make: *** [iplatform_package/samba/compile] Error 2 感觉应该是配置构建的时候出问题 而不是编译的问题 还没到编译那一步
11-02
make -C /data/test_wifi8_docker/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-bn800v1/bluetopia-profiles-4.2 all "CC=arm-buildroot-linux-gnueabihf-gcc" "GLOBLDFLAGS=-L/data/test_wifi8_docker/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-bn800v1/usr/lib -L/data/test_wifi8_docker/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-bn800v1/lib -Wl,-rpath-link,/data/test_wifi8_docker/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-bn800v1/usr/lib -L/data/test_wifi8_docker/Iplatform/openwrt/../../bcm620L/toolchains/opt/toolchains/crosstools-arm_hf-gcc-13.2-linux-5.15-glibc-2.38-binutils-2.41/usr/lib -L/data/test_wifi8_docker/Iplatform/openwrt/../../bcm620L/toolchains/opt/toolchains/crosstools-arm_hf-gcc-13.2-linux-5.15-glibc-2.38-binutils-2.41/lib -luci -mfloat-abi=softfp" "GLOBINCLDDIRS=" "GLOBCFLAGS=-I/data/test_wifi8_docker/Iplatform/openwrt/staging_dir/target-arm-openwrt-linux-uclibc-bn800v1/usr/include" make[4]: Entering directory '/data/test_wifi8_docker/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-bn800v1/bluetopia-profiles-4.2' Makefile:46: *** recipe commences before first target. Stop. make[4]: Leaving directory '/data/test_wifi8_docker/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-bn800v1/bluetopia-profiles-4.2' make[3]: *** [Makefile:97: /data/test_wifi8_docker/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-bn800v1/bluetopia-profiles-4.2/.built] Error 2 make[3]: Leaving directory '/data/test_wifi8_docker/Iplatform/packages/private/bluetopia-profiles' make[2]: *** [package/Makefile:134: package/feeds/iplatform/bluetopia-profiles/compile] Error 2 make[2]: Leaving directory '/data/test_wifi8_docker/Iplatform/openwrt' make[1]: *** [/data/test_wifi8_docker/Iplatform/openwrt/include/toplevel.mk:186: package/bluetopia-profiles/compile] Error 2 make[1]: Leaving directory '/data/test_wifi8_docker/Iplatform/openwrt' make: *** [Makefile:237: iplatform_package/bluetopia-profiles/compile] Error 2
最新发布
11-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值