给D1 SDK 添加一个简单的helloworld package
-
目录结构:
/opt/D1/tina_d1_open$ tree package/helloworld/ package/helloworld/ ├── Makefile └── src ├── helloworld.c └── Makefile 1 directory, 3 files
package/helloworld/Makefile 文件内容:
include $(TOPDIR)/rules.mk # Name and release number of this package PKG_NAME:=helloworld PKG_RELEASE:=1 # This specifies the directory where we’re going to build the program. # The root build directory, $(BUILD_DIR), is by default the build_mipsel # directory in your OpenWrt SDK directory PKG_BUILD_DIR := $(COMPILE_DIR)/$(PKG_NAME) HAVE_SOURCE := yes include $(BUILD_DIR)/package.mk # Specify package information for this program. # The variables defined here should be self explanatory. # If you are running Kamikaze, delete the DESCRIPTION # variable below and uncomment the Kamikaze define # directive for the description below define Package/$(PKG_NAME) SECTION:=utils CATEGORY:=Utilities TITLE:=hello world test endef # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above define Package/$(PKG_NAME)/description If you can’t figure out what this program does, you’re probably brain-dead and need immediate medical attention. endef # Specify what needs to be done to prepare for building the package. # In our case, we need to copy the source files to the build directory. # This is NOT the default. The default uses the PKG_SOURCE_URL and the # PKG_SOURCE which is not defined here to download the source from the web. # In order to just build a simple program that we have just written, it is # much easier to do it this way. define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ endef # We do not need to define Build/Configure or Build/Compile directives # The defaults are appropriate for compiling a simple program such as this one # Specify where and how to install the program. Since we only have one file, # the helloworld executable, install it by copying it to the /bin directory on # the router. The $(1) variable represents the root directory on the router running # OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install # directory if it does not already exist. Likewise $(INSTALL_BIN) contains the # command to copy the binary file from its current location (in our case the build # directory) to the install directory. define Package/helloworld/install $(INSTALL_DIR) $(1)/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/ endef # This line executes the necessary commands to compile our program. # The above define directives specify all the information needed, but this # line calls BuildPackage which in turn actually uses this information to # build a package. $(eval $(call BuildPackage,$(PKG_NAME)))
package/helloworld/src/helloworld.c 文件内容:
/**************** * Helloworld.c * The most simplistic C program ever written. * An epileptic monkey on crack could write this code. *****************/ #include <stdio.h> #include <unistd.h> int main(void) { printf("Hell! O’ world, why won’t my code compile?\n\n"); return 0; }
package/helloworld/src/Makefile 文件内容:
# build helloworld executable when user executes “make” helloworld: helloworld.o $(CC) $(LDFLAGS) helloworld.o -o helloworld helloworld.o: helloworld.c $(CC) $(CFLAGS) -c helloworld.c # remove object files and executable when user executes “make clean” clean: rm *.o helloworld
-
-
root@TinaLinux:/# helloworld Hell! O’ world, why won’t my code compile?
烧到板子,执行 helloworld,完全OK
-
实际测试的时候, helloworld 文件夹可以埋多三层,make 还能找到,如果四层/五层以上就扫描不到不到了。
执行: mv package/helloworld package/test1/test2/test3/
重新 lunch
make package/helloworld/compile
或者:
make package/test1/test2/test3/helloworld/compile
均可以成功。
-
@tigger 在 给D1 SDK 添加一个简单的helloworld package 中说:
st1/test2/test3/helloworld/compile
递归多少层都可以,只要你source xxx 正确了
-
ubuntu:/opt/D1/tina_d1_open$ ls package/test1/test2/test3/test4/test5/test6/helloworld/ Makefile src ubuntu:/opt/D1/tina_d1_open$ ubuntu:/opt/D1/tina_d1_open$ make package/test1/test2/test3/test4/test5/test6/helloworld/compile ===This's tina environment.=== special target, skip mboot,marisc make[1]: Entering directory '/opt/D1/tina_d1_open' make[1]: *** No rule to make target 'package/test1/test2/test3/test4/test5/test6/helloworld/compile'. Stop. make[1]: Leaving directory '/opt/D1/tina_d1_open' /opt/D1/tina_d1_open/build/toplevel.mk:304: recipe for target 'package/test1/test2/test3/test4/test5/test6/helloworld/compile' failed make: *** [package/test1/test2/test3/test4/test5/test6/helloworld/compile] Error 2 #### make failed to build some targets (8 seconds) ####
真不行,按理 scan.mk 不可能无限层级遍历Makefile 文件。
-
ubuntu:/opt/D1/tina_d1_open$ mv package/test1/test2/test3/test4/test5/test6/helloworld/ package/test1/test2/test3 ubuntu:/opt/D1/tina_d1_open$ ubuntu:/opt/D1/tina_d1_open$ lunch You're building on Linux Lunch menu... pick a combo: 1. d1_f133evb1_rgb800x480-tina 2. d1_nezha_min2-tina 3. d1_nezha_min3-tina 4. d1_nezha_min-tina 5. d1_nezha-tina Which would you like? [Default d1_nezha]: 5 ============================================ TINA_BUILD_TOP=/opt/D1/tina_d1_open TINA_TARGET_ARCH=riscv TARGET_PRODUCT=d1_nezha TARGET_PLATFORM=d1 TARGET_BOARD=d1-nezha TARGET_PLAN=nezha TARGET_BUILD_VARIANT=tina TARGET_BUILD_TYPE=release TARGET_KERNEL_VERSION=5.4 TARGET_UBOOT=u-boot-2018 TARGET_CHIP=sun20iw1p1 ============================================ ubuntu:/opt/D1/tina_d1_open$ make package/test1/test2/test3/helloworld/compile ===This's tina environment.=== special target, skip mboot,marisc Collecting package info: done Collecting target info: done make[1]: Entering directory '/opt/D1/tina_d1_open' make[2]: Entering directory '/opt/D1/tina_d1_open/package/libs/toolchain' if [ -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean ]; then rm -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean; fi; echo "libc" >> /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install if [ -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean ]; then rm -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean; fi; echo "libgcc" >> /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install if [ -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean ]; then rm -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean; fi; echo "libssp" >> /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install if [ -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean ]; then rm -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean; fi; echo "libstdcpp" >> /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install if [ -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean ]; then rm -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean; fi; echo "libpthread" >> /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install if [ -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean ]; then rm -f /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install.clean; fi; echo "librt" >> /opt/D1/tina_d1_open/out/d1-nezha/staging_dir/target/pkginfo/toolchain.default.install make[2]: Leaving directory '/opt/D1/tina_d1_open/package/libs/toolchain' make[2]: Entering directory '/opt/D1/tina_d1_open/package/test1/test2/test3/helloworld' make[2]: Leaving directory '/opt/D1/tina_d1_open/package/test1/test2/test3/helloworld' make[1]: Leaving directory '/opt/D1/tina_d1_open' #### make completed successfully (29 seconds) #### ubuntu:/opt/D1/tina_d1_open$
为了证实,我再次操作了一遍。
-
-
-
Utilities这个目录怎么创建的?
-
CATEGORY:=Utilities 指的是 make menuconfig 的第一级菜单。
-
此回复已被删除!
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号