官網本身有詳細教程,這里只是簡單說一下。
0. 源碼 hello.c和Makefile一起放在了 ~/buildroot-2020.08.1/dl/helloworld 文件夾
hello.c
#include <stdio.h> int main() { printf("buildroot helloworld\n"); return 0; }
Makefile:
OPT = -O2 DEBUG = -g OTHER = -Wall -Wno-deprecated CFLAGS = $(OPT) $(OTHER) INCDIR = -I LIBDIR = -L LIBS = APP=helloworld SRCS=hello.c all: $(CC) -o $(APP) $(SRCS) $(CFLAGS) $(LIBDIR) $(INCDIR) $(LIBS) clean: rm $(APP)
1. 加menuconfig項目
改這個文件:
~/buildroot-2020.08.1/package/Config.in
…… menu "Text editors and viewers" source "package/ed/Config.in" source "package/joe/Config.in" source "package/less/Config.in" source "package/mc/Config.in" source "package/most/Config.in" source "package/nano/Config.in" source "package/uemacs/Config.in" source "package/vim/Config.in" endmenu menu "myown helloworld" source "package/helloworld/Config.in" endmenu endmenu
注意要在最后這個 endmenu 前插入。
2. 新建 ~/buildroot-2020.08.1/package/helloworld/Config.in
config BR2_PACKAGE_HELLOWORLD bool "helloworld" help This is a demo to add myown helloworld.
此時menuconfig就有了。
3. 新建 ~/buildroot-2020.08.1/package/helloworld/helloworld.mk
################################################################################ # # helloworld # ################################################################################ HELLOWORLD_VERSION:= 1.0.0 HELLOWORLD_SITE:= $(CURDIR)/dl/helloworld HELLOWORLD_SITE_METHOD:=local HELLOWORLD_INSTALL_TARGET:=YES define HELLOWORLD_BUILD_CMDS $(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all endef define HELLOWORLD_INSTALL_TARGET_CMDS $(INSTALL) -D -m 0755 $(@D)/helloworld $(TARGET_DIR)/bin endef define HELLOWORLD_PERMISSIONS /bin/helloworld f 4755 0 0 - - - - - endef $(eval $(generic-package))
我把工程代碼放到 ~/buildroot-2020.08.1/dl/helloworld 里了
完成,直接在~/buildroot-2020.08.1 下 make menuconfig 使能helloworld包,然后make。helloworld會自動安裝到根文件系統的/bin目錄下。