{"id":467,"date":"2014-05-02T01:07:31","date_gmt":"2014-05-02T10:07:31","guid":{"rendered":"\/blog\/?p=467"},"modified":"2023-09-21T09:38:45","modified_gmt":"2023-09-21T00:38:45","slug":"openwrt-package-%ec%a0%9c%ec%9e%91","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=467","title":{"rendered":"OpenWRT Package \uc81c\uc791"},"content":{"rendered":"\n<span style=\"font-family: Courier New;\">OpenWRT SDK \uacbd\ub85c : \/home\/hasu0707\/ar71xx\/sdk<\/span><br \/><br \/><span style=\"font-family: Courier New;\">\u25a0 \uc900\ube44 \uc791\uc5c5<\/span><br \/><br \/><span style=\"font-family: Courier New;\">$ cd \/home\/hasu0707\/ar71xx\/sdk<\/span><br \/><span style=\"font-family: Courier New;\">$ make prereq<\/span><br \/><br \/><span style=\"font-family: Courier New;\">-----------------------------------------------------------------------------<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;\u25a0 \/home\/hasu0707\/ar71xx\/sdk\/package\/hello\/src\/hello.c<\/span><br \/><span style=\"font-family: Courier New;\">-----------------------------------------------------------------------------<\/span><br \/><br \/><span style=\"font-family: Courier New;\">#include &lt;stdio.h&gt;<\/span><br \/><br \/><span style=\"font-family: Courier New;\">int main(int argc, char *argv[])<\/span><br \/><span style=\"font-family: Courier New;\">{<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp; printf(\"Hello, world\\n\");<\/span><br \/><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp; return 0;<\/span><br \/><span style=\"font-family: Courier New;\">}<\/span><br \/><br \/><span style=\"font-family: Courier New;\">-----------------------------------------------------------------------------<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;\u25a0 \/home\/hasu0707\/ar71xx\/sdk\/package\/hello\/src\/Makefile<\/span><br \/><span style=\"font-family: Courier New;\">-----------------------------------------------------------------------------<\/span><br \/><br \/><span style=\"font-family: Courier New;\">hello : hello.c<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${CC} -o hello hello.c<\/span><br \/><span style=\"font-family: Courier New;\">clean :<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm -f hello<\/span><br \/><br \/><span style=\"font-family: Courier New;\">-----------------------------------------------------------------------------<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;\u25a0 \/home\/hasu0707\/ar71xx\/sdk\/package\/hello\/Makefile<\/span><br \/><span style=\"font-family: Courier New;\">-----------------------------------------------------------------------------<\/span><br \/><br \/><span style=\"font-family: Courier New;\">include $(TOPDIR)\/rules.mk<\/span><br \/><br \/><span style=\"font-family: Courier New;\"># Name and release number of this package<\/span><br \/><span style=\"font-family: Courier New;\">PKG_NAME:=hello<\/span><br \/><span style=\"font-family: Courier New;\">PKG_RELEASE:=1<\/span><br \/><span style=\"font-family: Courier New;\">PKG_VERSION:=0.0.1<\/span><br \/><span style=\"font-family: Courier New;\">PKG_CAT:=zcat<\/span><br \/><br \/><span style=\"font-family: Courier New;\"># This specifies the directory where we're going to build the program.<\/span><br \/><span style=\"font-family: Courier New;\"># The root build directory, $(BUILD_DIR), is by default the build_mipsel<\/span><br \/><span style=\"font-family: Courier New;\"># directory in your OpenWrt SDK directory<\/span><br \/><span style=\"font-family: Courier New;\">PKG_BUILD_DIR := $(BUILD_DIR)\/$(PKG_NAME)<\/span><br \/><br \/><span style=\"font-family: Courier New;\">include $(INCLUDE_DIR)\/package.mk<\/span><br \/><br \/><span style=\"font-family: Courier New;\"># Specify package information for this program.<\/span><br \/><span style=\"font-family: Courier New;\"># The variables defined here should be self explanatory.<\/span><br \/><span style=\"font-family: Courier New;\">define Package\/hello<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SECTION:=utils<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CATEGORY:=Utilities<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TITLE:=Helloworld -- prints a snarky message<\/span><br \/><span style=\"font-family: Courier New;\">endef<\/span><br \/><br \/><span style=\"font-family: Courier New;\"># Specify what needs to be done to prepare for building the package.<\/span><br \/><span style=\"font-family: Courier New;\"># In our case, we need to copy the source files to the build directory.<\/span><br \/><span style=\"font-family: Courier New;\"># This is NOT the default.&nbsp; The default uses the PKG_SOURCE_URL and the<\/span><br \/><span style=\"font-family: Courier New;\"># PKG_SOURCE which is not defined here to download the source from the web.<\/span><br \/><span style=\"font-family: Courier New;\"># In order to just build a simple program that we have just written, it is<\/span><br \/><span style=\"font-family: Courier New;\"># much easier to do it this way.<\/span><br \/><span style=\"font-family: Courier New;\">define Build\/Prepare<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mkdir -p $(PKG_BUILD_DIR)<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(CP) .\/src\/* $(PKG_BUILD_DIR)\/<\/span><br \/><span style=\"font-family: Courier New;\">endef<\/span><br \/><br \/><span style=\"font-family: Courier New;\"># We do not need to define Build\/Configure or Build\/Compile directives<\/span><br \/><span style=\"font-family: Courier New;\"># The defaults are appropriate for compiling a simple program such as this one<\/span><br \/><br \/><span style=\"font-family: Courier New;\"># Specify where and how to install the program. Since we only have one file,<\/span><br \/><span style=\"font-family: Courier New;\"># the hello executable, install it by copying it to the \/bin directory on<\/span><br \/><span style=\"font-family: Courier New;\"># the router. The $(1) variable represents the root directory on the router running<\/span><br \/><span style=\"font-family: Courier New;\"># OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install<\/span><br \/><span style=\"font-family: Courier New;\"># directory if it does not already exist.&nbsp; Likewise $(INSTALL_BIN) contains the<\/span><br \/><span style=\"font-family: Courier New;\"># command to copy the binary file from its current location (in our case the build<\/span><br \/><span style=\"font-family: Courier New;\"># directory) to the install directory.<\/span><br \/><span style=\"font-family: Courier New;\">define Package\/hello\/install<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(INSTALL_DIR) $(1)\/bin<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(INSTALL_BIN) $(PKG_BUILD_DIR)\/hello $(1)\/bin\/<\/span><br \/><span style=\"font-family: Courier New;\">endef<\/span><br \/><br \/><span style=\"font-family: Courier New;\"># This line executes the necessary commands to compile our program.<\/span><br \/><span style=\"font-family: Courier New;\"># The above define directives specify all the information needed, but this<\/span><br \/><span style=\"font-family: Courier New;\"># line calls BuildPackage which in turn actually uses this information to<\/span><br \/><span style=\"font-family: Courier New;\"># build a package.<\/span><br \/><span style=\"font-family: Courier New;\">$(eval $(call BuildPackage,hello))<\/span><br \/><br \/><span style=\"font-family: Courier New;\">-----------------------------------------------------------------------------<\/span><br \/><br \/><span style=\"font-family: Courier New;\">\u25a0 \ud328\ud0a4\uc9c0\ub97c \ub9cc\ub4e0\ub2e4.<\/span><br \/><br \/><span style=\"font-family: Courier New;\">$ cd \/home\/hasu0707\/ar71xx\/sdk<\/span><br \/><span style=\"font-family: Courier New;\">$ make clean &amp;&amp; make world<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;make[1] world<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;make[2] package\/compile<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;make[3] -C package\/hello compile<\/span><br \/><span style=\"font-family: Courier New;\">&nbsp;make[2] package\/index<\/span><br \/><br \/><span style=\"font-family: Courier New;\">\u25a0 \uacb0\uacfc\ub97c \ud655\uc778\ud55c\ub2e4.<\/span><br \/><br \/><span style=\"font-family: Courier New;\">$ cd \/home\/hasu0707\/ar71xx\/sdk\/bin\/ar71xx\/packages<\/span><br \/><span style=\"font-family: Courier New;\">$ ls -l<\/span><br \/><span style=\"font-family: Courier New;\">-rw-r--r-- 1 hasu0707 users&nbsp; 406 2014-05-02 16:00 Packages<\/span><br \/><span style=\"font-family: Courier New;\">-rw-r--r-- 1 hasu0707 users&nbsp; 316 2014-05-02 16:00 Packages.gz<\/span><br \/><span style=\"font-family: Courier New;\">-rw-r--r-- 1 hasu0707 users 1757 2014-05-02 16:00 <b>hello_0.0.1-1_ar71xx.ipk<\/b><\/span><br \/><br \/><p><br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenWRT SDK \uacbd\ub85c : \/home\/hasu0707\/ar71xx\/sdk \u25a0 \uc900\ube44 \uc791\uc5c5 $ cd \/home\/hasu0707\/ar71xx\/sdk$ make prereq &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&nbsp;\u25a0 \/home\/hasu0707\/ar71xx\/sdk\/package\/hello\/src\/hello.c&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; #include &lt;stdio.h&gt; int main(int argc, char *argv[]){&nbsp;&nbsp;&nbsp; printf(&#8220;Hello, world\\n&#8221;); &nbsp;&nbsp;&nbsp; return 0;} &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&nbsp;\u25a0 \/home\/hasu0707\/ar71xx\/sdk\/package\/hello\/src\/Makefile&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; hello : hello.c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${CC} -o hello hello.cclean :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm -f hello &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&nbsp;\u25a0 \/home\/hasu0707\/ar71xx\/sdk\/package\/hello\/Makefile&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; include $(TOPDIR)\/rules.mk # Name and release number of this packagePKG_NAME:=helloPKG_RELEASE:=1PKG_VERSION:=0.0.1PKG_CAT:=zcat # This specifies [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[21],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-development_openwrt"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}