1 (edited by mazilo 2014-02-18 04:52:25)

Topic: How to create/compile helloworld program

The following is the <openwrt root directory>/feeds/packages/utils/helloworld/Makefile for my helloworld package:

include $(TOPDIR)/rules.mk

PKG_NAME:=helloworld
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)    
    SECTION:=utils
    CATEGORY:=Utilities
    TITLE:=$(PKG_NAME)
    MAINTAINER:=Mazilo <myEmail.add>
endef

define Package/$(PKG_NAME)/description
    This is a hello world package that contains a program to only print "hello world".
endef

CONFIGURE_VARS+= \
    CC="$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)"

define Package/$(PKG_NAME)/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(CP) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

My helloword-1.0.0.tar.xz file contains only two files, namely Makefile and helloworld.c as shown below:

[mazilo@Mi:/opt/openwrt-svn-trunk 460%] ~ tar -Jvtf dl/helloworld-1.0.0.tar.xz
drwxr-xr-x mazilo/users      0 2013-04-26 19:01 helloworld-1.0.0/
-rw-r--r-- mazilo/users    158 2013-04-26 19:01 helloworld-1.0.0/Makefile
-rw-r--r-- mazilo/users     75 2013-04-26 18:37 helloworld-1.0.0/helloworld.c
[mazilo@Mi:/opt/openwrt-svn-trunk 461%] ~

The Makefile from the helloworld-1.0.0.tar.xz file is as follows:

helloworld: helloworld.o
        $(CC) $(LDFLAGS) helloworld.o -o helloworld

helloworld.o: helloworld.c
        $(CC) $(CFLAGS) -c helloworld.c

clean:
        rm *.o helloworld

while the helloworld.c is as follows:

#include <stdio.h>
int main(void)
{
        printf("Hello World\n");
        return 0;
}

You can create the helloworld-1.0.0.tar.xz package as follows:

  1. Create a directory called helloword-1.0.0

  2. Inside the helloworld-1.0.0 directory, create both the Makefile and helloworld.c files

  3. Use tar utility to package the helloworld-1.0.0 subdirectory, i.e. tar -Jcf helloworld-1.0.0.tar.xz helloworld-1.0.0

  4. Move the helloworld-1.0.0.tar.xz file to your OpenWRT download directory

To compile the helloworld package, do as follows:

  1. Run scripts/feeds install helloworld (suggested below by salutuj)

  2. Run make menuconfig

  3. Go to Utilities sub menu and enable helloworld package

  4. < Exit > and < Exit .> to save the changes.

  5. Now, just run make package/helloworld/compile to compile helloworld package (thanks jow for the correction)

Mazi

Re: How to create/compile helloworld program

Very nice straightforward example, and useful to refer people to when the question comes up, as it regularly does.

Re: How to create/compile helloworld program

Final step 4. should be "make package/helloworld/compile"

Re: How to create/compile helloworld program

jow wrote:

Final step 4. should be "make package/helloworld/compile"

I edited the post to fix the missing /compile. Thank you Jow.

Mazi

5 (edited by salutuj 2013-07-15 23:44:11)

Re: How to create/compile helloworld program

Could you add the following line in tutorial, before make menuconfig, please?

Run scripts/feeds install helloworld

Re: How to create/compile helloworld program

I'd love to see them include an option for gcc and the associated dev libraries needed to compile on the router itself. Now that systems are getting USB 3.0 and 256-512MB of RAM it is feasible.

Re: How to create/compile helloworld program

You can have them installed when you install optware. Unfortunately entware which is modernised version of optware does not have them.

Re: How to create/compile helloworld program

Very nice tutorial, but unfortunately I have problems to compile the hello-package. 

In short my steps:
I'm using the last Version of backfire (/home/OpenWRT/backfire).
- Copied the Makefile in /home/OpenWRT/backfire/feeds/packages/utils/helloworld/
- Created the helloworld.c,  Makefile and the tarfile. Compiling under Linux (Debian) is successful.
- Copied the file helloworld-1.0.0.tar.xz to /home/OpenWRT/backfire/build_dir

Failure running:    ./scripts/feeds install helloworld:

WARNING: No feed for package 'helloworld' found, maybe it's already part of the standard packages?

In make menuconfig I can't find the helloworld packages (I assume due to the failure above).

I'm not a Linux developer, but like to know how to add some simple code to OpenWRT Maybe someone can give me some support.

Thank you!
Peter

Re: How to create/compile helloworld program

interesting....I wonder further development like clear channel selection.... too many inside tricks in the router.

Re: How to create/compile helloworld program

I also had the same problem - No feed message and it does not show up in the Utilities section of make menuconfig as excpected.

Any assistance would be appreciated.

Steve Donegan
steve@donegan.org

Re: How to create/compile helloworld program

Sorry, I left off that I am using kamikaze, not backfire but the failure mode is the same.

12 (edited by GABIKA6 2014-11-26 12:17:34)

Re: How to create/compile helloworld program

If it is not showing then your feed is might not up to date.

1. check if you dir nd Makefile is at the correct place (usually feeds/packages/helloworld directory)
2. run srcripts/feeds update -a
3. run scripts/feeds install helloworld

What is the output? If something like "Installing package... " then it must come up in the menuconfig.

Re: How to create/compile helloworld program

Hi All

Some small update on this helloworld package

To fix this message :
WARNING: No feed for package 'helloworld' found, maybe it's already part of the standard packages?

You need as well to modify feeds/packages.index file and declare helloword package as part of it with a section like this :

Source-Makefile: feeds/packages/utils/helloworld/Makefile
Package: helloworld
Version: 1.0.0
Depends: +libc +SSP_SUPPORT:libssp +USE_GLIBC:librt +USE_GLIBC:libpthread
Conflicts:
Menu-Depends:
Provides:
Section: utils
Category: Utilities
Title: Hello Program
Maintainer:
Source: helloworld-1.0.0.tar.gz
License: GPL-2.0
LicenseFiles: COPYING
Type: ipkg
Description: Hello world
@@

This has fixed the problem for me.

Hope it helps.

Re: How to create/compile helloworld program

To fix the issue:
WARNING: No feed for package 'helloworld' found, maybe it's already part of the standard packages?

My try:
add scripts/feeds update -i before scripts/feeds install helloworld

and it worked to me.

Re: How to create/compile helloworld program

So lets say i completed all the steps above, what would i need to do to bring the package onto my OpenWRT-Raspberry Pi3?

Re: How to create/compile helloworld program

srmeister wrote:

So lets say i completed all the steps above, what would i need to do to bring the package onto my OpenWRT-Raspberry Pi3?

You only have to copy using scp, for example:

scp yourpacket.ipk root@192.168.1.1:/tmp/

Once you are in your RaspBerry Pi3:

cd /tmp/
opkg install yourpacket.ipk