Problem compiling software

Hi,

I am trying to understand how to compile software for openwrt, but I am having problems…

At the moment I try to compile a trivial hello-world program for which I created an openwrt-Makefile.

My device is an AR-300M.

I cloned GitHub - domino-team/openwrt-cc: openwrt CC with Domino/GL patches and ran make menuconfig.

Then I tried to compile my package (named “mh”) with “make package/mh/compile” but that failed because of missing libraries.

I gathered from some postings that it is neccessary to compile the toolkit first.
So I tried “make tools/install” which compiled some tools just fine but ultimately fails at automake.

This is the error I get:

... make[2]: Leaving directory '/home/mh/test/openwrt/openwrt-cc/tools/xz' make[2]: Entering directory '/home/mh/test/openwrt/openwrt-cc/tools/automake' (cd /home/mh/test/openwrt/openwrt-cc/build_dir/host/automake-1.15; AUTOM4TE=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/autom4te AUTOCONF=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/autoconf AUTOMAKE=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/automake ACLOCAL=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/aclocal AUTOHEADER=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/autoheader LIBTOOLIZE=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/libtoolize LIBTOOL=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/libtool M4=/home/mh/test/openwrt/openwrt-cc/staging_dir/host/bin/m4 AUTOPOINT=true STAGING_DIR="" ./bootstrap.sh) Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at ./bin/automake.tmp line 3938. Makefile:50: recipe for target '/home/mh/test/openwrt/openwrt-cc/build_dir/host/automake-1.15/.configured' failed make[2]: *** [/home/mh/test/openwrt/openwrt-cc/build_dir/host/automake-1.15/.configured] Error 255 make[2]: Leaving directory '/home/mh/test/openwrt/openwrt-cc/tools/automake' tools/Makefile:122: recipe for target 'tools/automake/compile' failed make[1]: *** [tools/automake/compile] Error 2 make[1]: Leaving directory '/home/mh/test/openwrt/openwrt-cc' /home/mh/test/openwrt/openwrt-cc/include/toplevel.mk:181: recipe for target 'tools/install' failed make: *** [tools/install] Error 2
I also tried the same exercise with the chaos-calmer branch from openwrt and get the same error.

What am I doing wrong?

Where can I find an up-to-date tutorial on how to compile a package for openwrt that documents everything and does not assume prior experience with openwrt?

Many thanks!

do you mind share you code?

There is no code really.

I am trying to compile a trivial “hello world” c-program just so that I can understand the build-process.

The problem I ran into is that the whole toolkit simply does not seem to work with newer perl-versions as the attempt to build automake generates a perl-script that newer perl-versions reject.

I am not the only one with this problem: Compiling tools/automake failed · Issue #507 · openwrt/openwrt · GitHub

There seems to be patch, but I have not yet found time to continue my experiments.

So it would be really cool if you could not only make the toolkit available but also dokument how it is supposed to be used and specify the requirements…

Even it is hello world it has code. Otherwise there is no way to try.

Ok.

This is what I’ve tried:

I created a directory package/mh. In that directory I have a Makefile and a src-subdirectory. The src-directory contains a c-program and another Makefile.

This is what the files look like:

package/mh/mh.c:

#include

int main(void) {
printf(“mh\n”);
return 0;
}


package/mh/src/Makefile:

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

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

clean:
rm *.o mh


package/mh/Makefile:

include $(TOPDIR)/rules.mk

PKG_NAME:=mh
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/mh
SECTION:=Utilities (unused)
CATEGORY:=Extra packages
TITLE:=Hello world program
MAINTAINER:=foo <foo@bar.com>
DEPENDS:=@TARGET_ar71xx
endef

define Package/mh/description
This package prints hello world!
endef

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

define Package/mh/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/mh $(1)/usr/bin/
endef

$(eval $(call BuildPackage,mh))


I’ve tried to compile the package with “make mh/compile” but that failes because it seems you need to compile the toolkit first.
So when I try that with “make tools/install” I get the above error.

So it is not compiling my own code where I get the error, but in trying to compile the toolkit which in my understanding is a prerequisite.

And as far as I have looked into it, the problem seems to be the perl-version on my system. I try all this on a debian-testing system with a 5.26.1 version of perl and with perl-versions above 5.22 compilations of automake fails as a perl-script gets generated that contains a regex that is no longer valid in newer perls…

There seems to be a patch out to get around this, but it would already be helpful for me if you could let me know if I am on the right track or doing something fundamentally wrong…

Many thanks

Love it when you simply drop an issue.

Many thanks alzaho…

I know you are frustrated but Alzhao is fantastic!
It’s not his job to write your code for you - go over to the Openwrt site and complain/ask there!

Year end is a busy season.

I read you code and seems it is fine.

To compile the code, you need to compile the whole openwrt toolchain first. Just choose the right target (e.g. if you compile for AR71xx) in menuconfig and type “make”. This has to be successfully.

Then you need to choose mh as M or * in menuconfig. Then use make package/mh/compile V=s

If openwrt is not compiled you cannot compile your code like this. This process takes around 1 hours if everything goes fine.