OpenWrt Forum Archive

Topic: Compiling single package in openwrt

The content of this topic has been archived on 30 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I am using openWRT (trunk) and added my own package to it (example package hello world)

To compile the package, I tried the following link and got like below: http://wiki.openwrt.org/doc/howtobuild/single.package

madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk$ make package/helloworld/compile
Collecting package info: done
make[1] package/helloworld/compile
make[2] -C package/toolchain compile
make[2] -C package/helloworld compile
madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk$ make package/helloworld/install
make[1] package/helloworld/install
make[2] -C package/helloworld install


However I couldn't see any .ipk file in /bin

Posted my .c and Makefiles here for reference:
--------------------------------------------------------

madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk/package/helloworld/src$ cat helloworld.c
#include<stdio.h>   
 
int
main()   
{   
    printf(“hello world\n”);     
    return  0; 
}

madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk/package/helloworld$ cat Makefile
#
# Copyright (C) 2006-2012 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

# Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1

#This specifies the directory where we are going to build the program
#The root build directory, $(BUILD_DIR), is by default the fuild_mpsel
#directory in your OpenWRT SDK directory
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

#Specify package information for this program.
define Package/helloworld
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=Helloworld Program
endef

define Package/helloworld/description
    a sample openwrt helloworld program
endef

#define Build/Prepare
#    mkdir -p $(PKG_BUILD_DIR)
#    $(CP) ./src/* $(PKG_BUILD_DIR)
#endef

HELLO_FLAGS = -Wall

define Build/Compile
    $(call Build/Compile/Default)
    $(TARGET_CC) $(HELLO_FLAGS) -o $(PKG_BUILD_DIR)/helloworld src/helloworld.c
endef

define Package/bridge/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/sbin
endef

$(eval $(call BuildPackage,helloworld))

Can anyone please help me why it is not generating .ipk in /bin like other packages?

-Thanks,
Madhu.

At least the wrong package name there...

madhu542 wrote:

define Package/bridge/install

I am also not sure if you need the compile section all, or should you remove it and let the defaults to work there. (Additionally, your own compile line forgets to provide e.g. the target processor architecture etc.)
Like the Wiki says in http://wiki.openwrt.org/doc/devel/packages  :

Build/Compile (optional)
How to compile the source; in most cases you should leave this undefined.

(Last edited by hnyman on 18 Sep 2012, 12:10)

Hi,

Do we want me to remove below line:
    $(call Build/Compile/Default)

Should I give only this below line in install:
    $(TARGET_CC) $(HELLO_FLAGS) -o $(PKG_BUILD_DIR)/helloworld src/helloworld.c

-Madhu.

At least the wrong package name there...
define Package/bridge/install

->Changed this to Package/helloworld/install and executed again but still I couldn't find .ipk file in /bin

madhu542 wrote:

Do we want me to remove below line:
    $(call Build/Compile/Default)

Should I give only this below line in install:
    $(TARGET_CC) $(HELLO_FLAGS) -o $(PKG_BUILD_DIR)/helloworld src/helloworld.c

-Madhu.

The Install section has wrong package name like I said in my previous message. Replace  /bridge/ with /helloworld/

Why do you want to have the compile section at all?
Wiki suggests (in my previous quote) that if you have not defined the compile section, the build process automatically generates one (actually matching the   $(call Build/Compile/Default) )
I suggest that you remove the whole "define Build/Compile" section. 

(At least the line $(TARGET_CC) $(HELLO_FLAGS) -o $(PKG_BUILD_DIR)/helloworld src/helloworld.c is wrong, as your HELLO_FLAGS is not sensible. It should provide processor architecture etc. like the normal compiler options for your platform do)

EDIT: ok. you already corrected the install package name. Now fix the compilation part. Either remove the whole compile section, or alternatively you might try removing your own compile line.

(Last edited by hnyman on 18 Sep 2012, 12:36)

Thanks for your reply!

I commented "define Build/Compile" section and did make menuconfig and make again but couldn't see helloworld.ipk file in /bin... any other modifications I missed

My current Makefile:
----------------------

madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk/package/helloworld$ cat Makefile
#
# Copyright (C) 2006-2012 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

# Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1

#This specifies the directory where we are going to build the program
#The root build directory, $(BUILD_DIR), is by default the fuild_mpsel
#directory in your OpenWRT SDK directory
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

#Specify package information for this program.
define Package/helloworld
  SECTION:=utils
  CATEGORY:=Utilities
  TITLE:=Helloworld Program
endef

define Package/helloworld/description
    a sample openwrt helloworld program
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)
endef

#HELLO_FLAGS = -Wall

#define Build/Compile
#    $(call Build/Compile/Default)
#    $(TARGET_CC) $(HELLO_FLAGS) -o $(PKG_BUILD_DIR)/helloworld src/helloworld.c
#endef

define Package/helloworld/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/sbin
endef

$(eval $(call BuildPackage,helloworld))

Openwrt makefile is highly abstractized, mainly targeted for compiling opensource package downloaded from somewhere. Typically there is then an inner makefile, which provides the basic compilation rules for the package. My earlier advice was lacking in that regard :-(

Your own source in src should probably contain a simple makefile.

Examples of src/Makefile :
https://forum.openwrt.org/viewtopic.php … 68#p136468
http://www.gargoyle-router.com/wiki/dok … _8_23_2007

Thanks for your reply!

I cross checked with V=99 option and found like below:


madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk$ make package/helloworld/compile V=99
WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!
make[1]: Entering directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk'
make[2]: Entering directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk/package/toolchain'
WARNING: skipping libssp -- package not selected
WARNING: skipping libstdcpp -- package not selected
WARNING: skipping libpthread -- package not selected
WARNING: skipping librt -- package not selected
WARNING: skipping libgfortran -- package not selected
WARNING: skipping ldd -- package not selected
WARNING: skipping ldconfig -- package not selected
make[2]: Leaving directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk/package/toolchain'
make[2]: Entering directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk/package/helloworld'
WARNING: skipping helloworld -- package not selected
make[2]: Leaving directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk/package/helloworld'
make[1]: Leaving directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk'
madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk$

please help me why my package is getting skipped while compiling?

Not sure if it helps, but go to "make menuconfig" and make sure that you have selected the correct router target and then also select the new helloworld package. Then try the make package again.

'Target System' is set to 'Atheros 231x/5312

I checked the option "select all packages by default" in build settings -->

how to select new helloworld package?

Sample package (helloworld) is getting compiled but install is failing

madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk$ make package/helloworld/install V=99
make[1]: Entering directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk'
make[2]: Entering directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk/package/helloworld'
make[2]: Nothing to be done for `install'.
make[2]: Leaving directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk/package/helloworld'
make[1]: Leaving directory `/home/madhu/Desktop/802.1x/openwrt_example/trunk'
madhu@Ideapad:~/Desktop/802.1x/openwrt_example/trunk$

You probably copied&pasted the Makefile and by this your editor replaced the "TABs" with "SPACES".

Your Makefile must have TABS!

define Build/Compile
<TAB>$(call Build/Compile/Default)
<TAB>$(TARGET_CC) $(HELLO_FLAGS) -o $(PKG_BUILD_DIR)/helloworld src/helloworld.c
endef

define Package/helloworld/install
<TAB>$(INSTALL_DIR) $(1)/usr/sbin
<TAB>$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/sbin
endef

<TAB> = Tabulator, not 5 spaces.

HTH!

Cedrix

The discussion might have continued from here.