OpenWrt Forum Archive

Topic: Howto: Compiling source in buildroot

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

I need

- zebra
- iptables-p2p
- iproute2 (tc + htb3.6 patch)

to compile.

I'm an absolut linux developer newbiew. Don't expect from me, that I understand a Makefile or the ipkg-build script very well.
So for the moment, even reading thru all informations I have, I get no clue, how to achieve what I want.
I'm sure you can point me out some principles I can follow.

1.0 Common
What would I have to change in source's Makefile (maybe there is not only one Makefile, but more Makefiles in different directories when multiple binaries and also multiple .so files have to be created).

How can I point the progs Makefile to uclibc-gcc (crosscompile for WRT) ?
Do I have to change anything ?
If they refer already ${GCC}, will it work without any change ?

1. Zebra
I want to compile that in buildroot, so my thought was, just to copy some already existing .mk file and creating a zebra.mk.

I changed the names, path's, binary targets, etc.

How can I pass the zebra configure script some options like --enable-multipath and also disabling RIP, OSPFv3, etc. ?
Do I have to create my own .config file and also how can I pass this to zebra configure script ?

2. Iproute2
There is a tc in ./build_mipsel/WRT54GS/release/src/linux/linux/drivers/tc
. How to exlude this from openwrt-code.bin ?

How to include iproute2 (htb3.6 patched) tc ?
I would have to change the Makefiles in iproute2 , that only tc get's compiled ?
I finally have sources for iproute2 and htb3.6 patch.

3. iptables-p2p
There is no binary for IPTABLES-P2P_BINARY, IPTABLES-P2P_BINARY_TARGET which I could change buildroot/make/iptables-p2p.mk to, because there are only created some .so files.
One libipt_p2p.so for /usr/lib/iptables and one ipt_p2p.o for /lib/kernel/2.4.20.
They get created by make process from different directories with multiple Makefiles.

Do I have to care for my iptables-p2p.mk to these or is this just straightforward like compiling normal programs ?

Thanx for your tips.
There is really a lack (also for that ipkg-build script which I don't understand also) on informations how to go on, once you have openwrt running smile

Feel free just to quote my text and add very short help.

I really hope you can help me  sad  sad  sad  sad  sad  sad  sad

Blackvel

So far a compile for latest quagga and also iproute2 worked after problems 4 days long.
I still have some problems getting them fully to run, but hey, I'm one step further.
It's very surprisingly for me, that really noone did give me any feedback on this too advanced topics for me(I guess basic topics for a linux guru).

These are the real problems for people, so they probably don't think ever on using OpenWRT.
If you as a group can not write simple enough Compiling Howto's or even reply on such basic questions, then please don't expect that there will be many people focusing on such products.
What helps a running OpenWRT on WRT (my congratulations to the very simple buildroot make process btw), when you can't get programs compiled for it/on it.

The feature of package installations help here not much, when most packages are not available yet smile
The slogan "Newbies do not have to apply" seems to come here very true even when you (not really a newbie) got openWRT running very fine.

Why do you people make that lots of work for coding that wonderful firmware when people probably have to refuse working with it, just because of problems like I had ? smile

Anyway I have to say, the support which I got on IRC channel #wrt54g on irc.freenode.net so far is really overwhelming, also mostly short questions is the key.
I want to thank you all (you know who you are!) for the support and help and ideas. Also for your patience.
I know, it's all the complicated stuff that I have to get working all time smile

Comming back to my own solutions....

1.0 Common
What would I have to change in source's Makefile (maybe there is not only one Makefile, but more Makefiles in different directories when multiple binaries and also multiple .so files have to be created).

How can I point the progs Makefile to uclibc-gcc (crosscompile for WRT) ?
Do I have to change anything ?
If they refer already ${GCC}, will it work without any change ?

One way which works quite good, is to call make <target> in buildroot directly. So make in fact make calls normal Makefile, which also sets some stuff for crosscompile (e.g TARGET_CC, TARGET_CROSS, STRIP, TARGET_CONFIGURE_OPTS for PATH to AR, AS, LD, NM, CC, GCC, RANLIB).
The Makefile does include make/*.mk, so if you have created a quagga.mk, it will be included.

1. Zebra
I want to compile that in buildroot, so my thought was, just to copy some already existing .mk file and creating a zebra.mk.

I changed the names, path's, binary targets, etc.

How can I pass the zebra configure script some options like --enable-multipath and also disabling RIP, OSPFv3, etc. ?
Do I have to create my own .config file and also how can I pass this to zebra configure script ?

I left out zebra 0.94 and instead of switched to quagga zebra fork now.
If there is any bugfix, then it is in quagga instead of zebra.
Configuration (configure, make, also zebra.conf, ospfd.conf) is the same as in zebra.

Normally calling from buildroot directory make quagga probably works.
Just make sure, you have set in quagga.mk all GCC, LD, RANLIB, STRIP stuff. If you haven't, compile will probably abort with very weird errors,
e.g wrong index on xxx.a (which is wrong ranlib used) or any other stuff
which is an indicator that Makefiles from quagga (there is more than one in each directory!) is directly refering CC=gcc, LD=ld, STRIP=strip etc.

For quagga this was no problem. If you are compiling iproute2 you would have to deleted from iproute2/Makefile line CC=gcc and edit iproute2/lib/Makefile and change some line with ar xxxxx .... to $(AR).

Here is my quagga.mk from buildroot/make:

#############################################################
#
# Quagga 0.96.4
#
#############################################################

QUAGGA_SOURCE=quagga-0.96.4.tar.gz
QUAGGA_SITE=ftp://ftp.quagga.net/download
QUAGGA_DIR=$(BUILD_DIR)/packages/quagga-0.96.4
QUAGGA_BINARY=zebra
QUAGGA_BINARY2=ospfd
QUAGGA_TARGET_BINARY=usr/sbin/zebra
QUAGGA_TARGET_BINARY2=usr/sbin/ospfd

$(DL_DIR)/$(QUAGGA_SOURCE):
    $(WGET) -P $(DL_DIR) $(QUAGGA_SITE)/$(QUAGGA_SOURCE)

$(QUAGGA_DIR)/.source: $(DL_DIR)/$(QUAGGA_SOURCE)
    zcat $(DL_DIR)/$(QUAGGA_SOURCE) | tar -C $(BUILD_DIR)/packages -xvf -
    $(SOURCE_DIR)/patch-kernel.sh $(QUAGGA_DIR) $(SOURCE_DIR) quagga-*.patch
    touch $(QUAGGA_DIR)/.source

$(QUAGGA_DIR)/.configured: $(QUAGGA_DIR)/.source
    (cd $(QUAGGA_DIR); rm -rf config.cache; 
        $(TARGET_CONFIGURE_OPTS) 
        ./configure 
        --host=mipsel-unknown-linux-gnu 
        --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib 
        --datadir=/usr/share --sysconfdir=/etc --libdir=/usr/lib 
        --disable-ipv6 --disable-bgpd --disable-ripd 
        --disable-ripngd --disable-ospf6d --disable-bgp-announce 
        --disable-ospfapi --disable-ospfclient --disable-ospf-te 
        --disable-rtadv --disable-vtysh --disable-snmp --disable-nssa 
        --disable-opaque-lsa 
        --enable-multipath=0 
        --enable-user=root --enable-group=root 
    );
    touch $(QUAGGA_DIR)/.configured

$(QUAGGA_DIR)/$(QUAGGA_BINARY): $(QUAGGA_DIR)/.configured
    $(MAKE) CC=$(TARGET_CC) CFLAGS="$(TARGET_CFLAGS)" 
        AR=$(TARGET_CROSS)ar AS=$(TARGET_CROSS)as LD=$(TARGET_CROSS)ld 
        NM=$(TARGET_CROSS)nm RANLIB=$(TARGET_CROSS)ranlib 
        CPP=$(TARGET_CROSS)cpp STRIP=$(TARGET_CROSS)strip 
        BINDIR=/usr/sbin MANDIR=/usr/man -C $(QUAGGA_DIR)

$(TARGET_DIR)/$(QUAGGA_TARGET_BINARY): $(QUAGGA_DIR)/$(QUAGGA_BINARY)
    $(MAKE) BINDIR=/usr/sbin MANDIR=/usr/man 
        DESTDIR=$(TARGET_DIR) -C $(QUAGGA_DIR) install
    $(STRIP) $(TARGET_DIR)/$(QUAGGA_TARGET_BINARY)
    $(STRIP) $(TARGET_DIR)/$(QUAGGA_TARGET_BINARY2)
    rm -Rf $(TARGET_DIR)/usr/man

quagga: uclibc $(TARGET_DIR)/$(QUAGGA_TARGET_BINARY)

quagga-source: $(DL_DIR)/$(QUAGGA_SOURCE)

quagga-clean:
    #$(MAKE) prefix=$(TARGET_DIR)/usr -C $(QUAGGA_DIR) uninstall
    -$(MAKE) -C $(QUAGGA_DIR) clean

quagga-dirclean:
    rm -rf $(QUAGGA_DIR)

Important notes:
1. You have to call configure for quagga. As you can see I already call configure will all crosscompiler references like GCC, LD.
This is very sweet, since all quagga Makefiles have then the right references.
2. Note, there exists a problem cd $(QUAGGA_DIR) and configure.
To get calling configure from quagga.mk working, you have exactly to follow this:
(cd $(QUAGGA_DIR); $(TARGET_CONFIGURE_OPTS) ./configure --options );
If you don't use (cd; configure ); the configure command won't be found.
If you choose to use instead of $(QUAGGA_DIR)/configure all Makefiles won't be created in $(QUAGGA_DIR) but instead of in buildroot !!!!
3. Don't forget to strip the compiled binaries zebra and ospfd in my case.
I forgot to add $(STRIP) $(TARGET_DIR)/usr/sbin/ospfd and so the file was 2,3MB! Thanx to coder for this tip!

4. Don't forget that also zebra.conf.sample and ospfd.conf.sample will be copied to buildroot/build_mipsel/root/etc smile

5. It took me more than 1 day to find out, how to get configure working with crosscompile.
You really have to set --host for crosscompile, otherwise quagga/zebra won't let you pass GCC, LD, RANLIB crosscompiler stuff.
It actively complains about this then!

On my redhat 9 system I had quite big problems, passing not all crosscompiler options to configure, so configure was actually trying to compile one file on my system, and this wasn't working.

Also it took me about 1-2 days to find out, what host type I have to pass in.
I tried with --host=mipsel.
Wonder if this had worked in any kind! NO!

The damn configure script then thought I was compile for a FreeBSD system so it included rt_socket.c instead of linux netlink, so it was complaining all the time for unknown constants like RTM_ADD, RTM_DELETE which just are not in zebra, but seem to be in kernel header files for FreeBSD.

As I found out, that there is in zebra directory a config.sub which can find you the right hostname according to INSTALL (first of course I just looked in the file directly , but I had no chance to find out the logic; yes, damn newbies, they think complex even it can be done easily!).

[root@agelinux quagga-0.96.4]# ./config.sub mipsel
mipsel-unknown-elf
[root@agelinux quagga-0.96.4]# ./config.sub mipsel-linux
mipsel-unknown-linux-gnu
[root@agelinux quagga-0.96.4]#

So mipsel-linux found me the right mipsel-unknown-linux-gnu crosscompiler.

2. Iproute2
There is a tc in ./build_mipsel/WRT54GS/release/src/linux/linux/drivers/tc
. How to exlude this from openwrt-code.bin ?

I have not done this yet.
iproute2.mk creates tc in buildroot/build_mipsel/root/usr/sbin. Just copy tc from that directory to your WRT.

How to include iproute2 (htb3.6 patched) tc ?
I would have to change the Makefiles in iproute2 , that only tc get's compiled ?
I finally have sources for iproute2 and htb3.6 patch.

Probably by adding the target in buildroot/Makefile or was it buildroot/Makefile-OpenWRT ? smile
Just comment out this line :
#TARGETS+=iproute2
Then at least iproute2 will be compiled when a normal make for openwrt is running.
I guess this does not already include it into openwrt-code.bin.

Don't forget for iproute2 to change the Makefiles (especially lib/Makefile) to poing to all crosscompiler stuff, e.g ar.
So it should be not ar, but instead of $(AR).

Here is my iproute2.mk, there where several bugs in.

################################################
# iproute2
#
###############################################

IPROUTE2_DIR=$(BUILD_DIR)/packages/iproute2
LINUX_DIR=/home/blackvel/buildroot/build_mipsel/linux

IPROUTE2_SOURCE_URL=ftp://ftp.inr.ac.ru/ip-routing/
IPROUTE2_SOURCE=iproute2-2.4.7-now-ss010824.tar.gz

#Use the debian source for now, as the .ru site has availability problems
#IPROUTE2_SOURCE_URL=http://ftp.debian.org/debian/pool/main/i/iproute/
#IPROUTE2_SOURCE=iproute_20010824.orig.tar.gz
#IPROUTE2_PATCH=iproute_20010824-13.diff.gz
IPROUTE2_PATCH=htb3.6_tc.patch

$(DL_DIR)/$(IPROUTE2_SOURCE):
     $(WGET) -P $(DL_DIR) $(IPROUTE2_SOURCE_URL)$(IPROUTE2_SOURCE)

iproute2-source: $(DL_DIR)/$(IPROUTE2_SOURCE) #$(DL_DIR)/$(IPROUTE2_PATCH)

$(IPROUTE2_DIR)/.unpacked: $(DL_DIR)/$(IPROUTE2_SOURCE) #$(DL_DIR)/$(IPROUTE2_PATCH)
    rm -rf $(IPROUTE2_DIR).orig $(IPROUTE2_DIR)
    zcat $(DL_DIR)/$(IPROUTE2_SOURCE) | tar -C $(BUILD_DIR)/packages -xvf -
    #zcat $(DL_DIR)/$(IPROUTE2_PATCH) | patch -p1 -d $(IPROUTE2_DIR)
    touch $(IPROUTE2_DIR)/.unpacked

$(IPROUTE2_DIR)/.patched : $(IPROUTE2_DIR)/.unpacked
    $(SOURCE_DIR)/patch-kernel.sh $(IPROUTE2_DIR) $(SOURCE_DIR) $(IPROUTE2_PATCH)
    touch $(IPROUTE2_DIR)/.patched

$(IPROUTE2_DIR)/.configured: $(IPROUTE2_DIR)/.patched
    $(SED) "s,-I/usr/include/db3,," $(IPROUTE2_DIR)/Makefile
    $(SED) "s,^KERNEL_INCLUDE.*,KERNEL_INCLUDE=$(LINUX_DIR)/include," 
        $(IPROUTE2_DIR)/Makefile
    $(SED) "s,^LIBC_INCLUDE.*,LIBC_INCLUDE=$(STAGING_DIR)/include," 
        $(IPROUTE2_DIR)/Makefile
    # For now disable compiling of the misc directory because it seems to fail
    rm -rf $(IPROUTE2_DIR)/misc 
    $(SED) "s, misc,," $(IPROUTE2_DIR)/Makefile

    # set configured mode
    touch $(IPROUTE2_DIR)/.configured
    # end of configured mode

$(IPROUTE2_DIR)/tc/tc: $(IPROUTE2_DIR)/.configured
    # Entering make of tc
    $(MAKE) CC=$(TARGET_CC) 
        AR=$(TARGET_CROSS)ar AS=$(TARGET_CROSS)as LD=$(TARGET_CROSS)ld 
        NM=$(TARGET_CROSS)nm RANLIB=$(TARGET_CROSS)ranlib 
        CPP=$(TARGET_CROSS)cpp STRIP=$(TARGET_CROSS)strip 
        KERNEL_INCLUDE=$(LINUX_DIR)/include -C $(IPROUTE2_DIR)

$(TARGET_DIR)/usr/sbin/tc: $(IPROUTE2_DIR)/tc/tc
        # Copy The tc binary
    cp -af $(IPROUTE2_DIR)/tc/tc $(TARGET_DIR)/usr/sbin/
    $(STRIP) $(TARGET_DIR)/usr/sbin/tc

iproute2: $(TARGET_DIR)/usr/sbin/tc 

iproute2-clean:
    $(MAKE) -C $(IPROUTE2_DIR) clean

iproute2-dirclean:
    rm -rf $(IPROUTE2_DIR)

Note: for iproute2-clean there is no uninstall target in iproute2 package, only clean!
This Makefile does not only build tc, but also all other iproute2 stuff.
in buildroot/build_mipsel/iproute2/Makefile there is no special tc target yet!

Be sure to have a clean iproute2.mk, this means, do not use normal spaces in vi before commands like $(MAKE) in target $(IPROUTE2_DIR)/tc/tc: .
I had this problem (tab use is very okay!) and my make just didn't run.

3. iptables-p2p
There is no binary for IPTABLES-P2P_BINARY, IPTABLES-P2P_BINARY_TARGET which I could change buildroot/make/iptables-p2p.mk to, because there are only created some .so files.
One libipt_p2p.so for /usr/lib/iptables and one ipt_p2p.o for /lib/kernel/2.4.20.
They get created by make process from different directories with multiple Makefiles.

Do I have to care for my iptables-p2p.mk to these or is this just straightforward like compiling normal programs ?

Haven't compiled iptables-p2p yet.

But from my 4 days experience now, the TARGET and BINARY_TARGET are just an identifier for the makefile with what target part should be started or what part has to come before that special part.

So I would suggest to point the TARGET1 and TARGET2 binaries to libipt_p2p.so and ipt_p2p.o with the correct path directions to buildroot/build_mipsel/packages/iptables-p2p/xxxxx.

Then you can modify the TARGET_BINARY target to copy the files to $(TARGET_DIR) and the appropriate directories which are /usr/lib/iptables and /lib/kernel/2.4.20.

Before this make sure, Makefiles are not using any ar, strip, ranlib stuff directly. Replace in Makefiles by $(AR), $(STRIP), $(RANLIB), etc.

Don't worry for the multiple pathes in iptables-p2p, so multiple files from multiple directories have to be created.
iptables-p2p/Makefile handles this automatically by calling $(MAKE) -c <directories>.
This was also quite good working for quagga smile

For all package.mk files the slogan is :
Copy the file first into buildroot/sources/dl smile

Hope this helps the other people with that advanced openwrt topics smile
To create a package with ipkg-build, having all the binaries already compiled, shouldn't be a problem anymore really.

Feel free to ask if you have any problems.

Blackvel

one additional tip for Makefile hacking of program sources.

Instead of doing this all on yourself, you can also use in e.g iproute2.mk:

$(SED) "s, ar rcs,$(TARGET_CROSS)ar rcs" $(IPROUTE2_DIR)/lib/Makefile

This replaces (more substitutes) by SED the "ar rcs" by "/home/user/buildroot/build_mipsel/staging_dir/bin/mipsel-linux-uclibc-ar rcs" in /home/user/buildroot/build_mipsel/packages/iproute2/lib/Makefile (in my case, maybe just build_mipsel/iproute2.... in your case).

With this you can replace in a very easy way Makefiles which are hardcoded to gcc, ar, ranlib crosscompiling stuff.

Not always a GCC=xxx environment passing helps for a configure or make process sad

Keep prepared.

Blackvel

BTW: Thanx to lwiddif for this great tip!

Have got iptables-p2p compiled finally.

If you also plan this, you mostly want to change the makefiles in iptables-p2p/iptables/Makefile and iptables-p2p/kernel/Makefile directly.

Biggest problems I had where KERNEL_INCLUDES in kernel/Makefile.

iptables/Makefile:

SOURCES = 
    libipt_p2p.c

OBJECTS = 
    $(SOURCES:%.c=%.o)

TARGET = 
    libipt_p2p.so

###############################################################################

# We don't really require gcc, I'm just being lazy
CC=/home/blackvel/buildroot/build_mipsel/staging_dir/bin/mipsel-linux-uclibc-gcc

# I can't believe we have to do this...a better way, please!
SED=/home/blackvel/buildroot/build_mipsel/staging_dir/bin/sed -i -e
BUILD_DIR=/home/blackvel/buildroot/build_mipsel
IPTABLES_VERSION=iptables-1.2.9
CFLAGS=-O2 -Wall
CPPFLAGS = 
    -DIPTABLES_VERSION="$(IPTABLES_VERSION)" -I../common -I$(BUILD_DIR)/$(IPTABLES_VERSION)/include

###############################################################################

all: $(TARGET)

$(TARGET): $(OBJECTS)
    $(LD) -shared -o $@ $(OBJECTS)

clean:
    $(RM) $(OBJECTS)
    $(RM) $(TARGET)

Yes I know, it's not yet that all sweet. Feel free to make it better smile At least it works.

I had to add for CPPFLAGS the second include, otherwise it couldn't find my  headers.
Also I figgled with setting BUILD_ROOT, probably some cool env variable can be passed by iptables-p2p.mk to Makefiles.

kernel/Makefile:

###############################################################################

SOURCES = 
    main.c 
    match_bittorrent.c 
    match_dc.c 
    match_edonkey.c 
    match_http.c

OBJECTS = 
    $(SOURCES:%.c=%.o)

TARGET_24 = ipt_p2p.o
TARGET_26 = ipt_p2p.ko

###############################################################################

CFLAGS=-O3 
KERNELDIR=/home/blackvel/buildroot/build_mipsel/WRT54GS/release/src/linux/linux
KERNELINC = 
    $(KERNELDIR)/include

# This is not pretty. How can we do this better?
ifdef P2P_COMMON
    INCLUDES+=-I$(P2P_COMMON)
endif

PWD = 
    $(shell pwd)

COMMON = 
    $(PWD)/../common

INCLUDES += 
    -I$(COMMON) 
    -I$(KERNELINC) 
    -I$(KERNELINC)/asm/mach-default

CPPFLAGS += 
    -D__KERNEL__ -DMODULE $(INCLUDES)

###############################################################################
# Common Stuff
###############################################################################

all: linux-2.4


.PHONY: clean

clean:
    $(RM) $(OBJECTS)
    $(RM) $(TARGET_24)
    $(RM) $(TARGET_26)
    $(RM) .*.o.cmd
    $(RM) .*.ko.cmd
    $(RM) ipt_p2p.mod.*


###############################################################################
# Linux 2.4 Stuff
###############################################################################

linux-2.4: $(TARGET_24)

$(TARGET_24): $(OBJECTS)
    $(LD) -r -o $@ $(OBJECTS)

###############################################################################
# Linux 2.6 Stuff
###############################################################################

obj-m := ipt_p2p.o
ipt_p2p-objs := $(OBJECTS)

linux-2.6: $(TARGET_26)

$(TARGET_26):
    $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) P2P_COMMON=$(COMMON) modules

I changed specially KERNELDIR.
Make sure ld and rm are set to ${LD}, ${RM}.
If you are a profi, then pass KERNEL_DIR from iptables-p2p.mk or use the right SED commands.
After playing a while with SED, I give up.
I don't personally need 100% perfect solutions, but more fast ones smile

make/iptables-p2p.mk:

#############################################################
#
# iptables-p2p module for P2P Traffic
#
#############################################################

IPTABLES_P2P_SOURCE=iptables-p2p-0.3.0a.tar.gz
IPTABLES_P2P_SITE=http://sourceforge.net/
IPTABLES_P2P_DIR=$(BUILD_DIR)/packages/iptables-p2p-0.3.0a
IPTABLES_P2P_BINARY1=iptables/libipt_p2p.so
IPTABLES_P2P_TARGET_BINARY1=usr/lib/iptables/libipt_p2p.so
IPTABLES_P2P_BINARY2=kernel/ipt_p2p.o
IPTABLES_P2P_TARGET_BINARY2=lib/modules/2.4.20/ipt_p2p.o

$(DL_DIR)/$(IPTABLES_P2P_SOURCE):
    $(WGET) -P $(DL_DIR) $(IPTABLES_P2P_SITE)/$(IPTABLES_P2P_SOURCE)

$(IPTABLES_P2P_DIR)/.source: $(DL_DIR)/$(IPTABLES_P2P_SOURCE)
    zcat $(DL_DIR)/$(IPTABLES_P2P_SOURCE) | tar -C $(BUILD_DIR)/packages -xvf -
    #$(SOURCE_DIR)/patch-kernel.sh $(IPTABLES_P2P_DIR) $(SOURCE_DIR) iptables-p2p-*.patch
    touch $(IPTABLES_P2P_DIR)/.source

$(IPTABLES_P2P_DIR)/$(IPTABLES_P2P_BINARY1): $(IPTABLES_P2P_DIR)/.source
    $(SED) "s,CC=cc,CC=$(CC)," $(IPTABLES_P2P_DIR)/iptables/Makefile
    $(SED) "s,SED=sed,SED=$(SED)," $(IPTABLES_P2P_DIR)/iptables/Makefile
    $(SED) "s,CC=cc,CC=$(CC)," $(IPTABLES_P2P_DIR)/kernel/Makefile
    $(SED) "s,^KERNEL_DIR.*,KERNEL_DIR=$(LINUX_DIR)," 
        $(IPTABLES_P2P_DIR)/kernel/Makefile
    $(MAKE) CC=$(TARGET_CC) CFLAGS="$(TARGET_CFLAGS)" LD=$(TARGET_CROSS)ld RM=$(TARGET_CROSS)rm 
        BINDIR=/sbin/ MANDIR=/usr/man -C $(IPTABLES_P2P_DIR)

$(TARGET_DIR)/$(IPTABLES_P2P_TARGET_BINARY1): $(IPTABLES_P2P_DIR)/$(IPTABLES_P2P_BINARY1)
    cp -af $(IPTABLES_P2P_DIR)/$(IPTABLES_P2P_BINARY1) $(TARGET_DIR)/$(IPTABLES_P2P_TARGET_BINARY1)
    cp -af $(IPTABLES_P2P_DIR)/$(IPTABLES_P2P_BINARY2) $(TARGET_DIR)/$(IPTABLES_P2P_TARGET_BINARY2)
    $(STRIP) $(TARGET_DIR)/$(IPTABLES_P2P_TARGET_BINARY1)
    $(STRIP) $(TARGET_DIR)/$(IPTABLES_P2P_TARGET_BINARY2)
    rm -Rf $(TARGET_DIR)/usr/man

iptables-p2p: uclibc $(TARGET_DIR)/$(IPTABLES_P2P_TARGET_BINARY1)

iptables-p2p-source: $(DL_DIR)/$(IPTABLES_P2P_SOURCE)

iptables-p2p-clean:
    $(MAKE) -C $(IPTABLES_P2P_DIR) clean

iptables-p2p-dirclean:
    rm -rf $(IPTABLES_P2P_DIR)

Note: This code aint perfect yet.
I don't like the approach of having a BINARY_1 target but also copying BINARY_2 file to TARGET_DIR.
But anyway it's a fast 80% working solution which compiles smile
Also all SED command's are not yet working since the original Makefiles use very weird setups like
CC =
<TAB>cc

As you can see I pass this line for compile :
$(MAKE) CC=$(TARGET_CC) CFLAGS="$(TARGET_CFLAGS)" LD=$(TARGET_CROSS)ld RM=$(TARGET_CROSS

Without crosscompile ld and rm the Makefile runs into a problem.

You can also use the more common solution :
$(TARGET_CONFIGURE_OPTS)

See if it works also.

NOTE:
You will have to compile extension CONNMARK from iptables-1.2.9 to get p2p marking and qos class matching working.

Just change in buildroot/build_mipsel/iptables-1.2.9/extensions/Makefile
PF_EXT_SLIB:=

I suggest to copy the whole line openwrt has created by openwrt-iptables-extension.patch (for the basic iptables libs).

This is, how the line looks to me right now:

PF_EXT_SLIB:=icmp iprange mark multiport standard state tcp udp DNAT LOG MARK MASQUERADE REDIRECT REJECT SNAT TCPMSS connlimit connmark conntrack length limit mac mark tcpmss tos CONNMARK DNAT TOS

You can rely on the first line where all unused extensions are listed.
If you plan to use iptables-p2p you need at least CONNMARK, connmark.

Don't forget to uncomment #PF_EXT_SLIB smile

Jump to buildroot and enter "make iproute2".

This will copy all new extensions as stripped to buildroot/root/usr/lib/iptables.

Important:
If you plan to use ipkg, you should NOT let xxx.mk copy binary from build_mipsel/packages/xxx to $TARGET_DIR which is build_mipsel/root.

I got told 5 minutes ago by mbm, that this actually means the binary will be included in squash_fs, that is openwrt.bin.

I don't think that this is the plan for yourself with all stuff like quagga, tc, etc.

I only can think for this if you want to replace some files like tc (having tc htb patched).

Maybe a huge .bin file would be useful if you are configuring a OpenWRT router for your friend and you don't want to move all ipkg'es manually on router (here also would help a ./setup.sh script!).

I wish I'd found this thread a week ago!  smile
   If you don't mind I'm going to work through all of this (and make sure it works for me!  smile and then maybe re-post it as a step-by-step HOWTO (maybe on the WIKI).


Thanks again!

- Michael

Thank you for your input smile

I'm glad someone can make use of it. Therefore I wrote it for the OpenWRT newbies like I was smile

Feel free to create a more user friendly, real WIKI from it.

Blackvel

If you don't mind I'm going to work through all of this (and make sure it works for me!  smile and then maybe re-post it as a step-by-step HOWTO (maybe on the WIKI).

And? Any results? I just joined because of blackvels good work. I would be very interested...

Anyway, Blackvel, more testers, more fun!

I have tested the makefiles and they all compile after:

1. Adding a directory named packages in build_mipsel (Why that actually?)

2. Changing download-url's and tarball-version-number, updating the software that way. I have compiled Quagga 0.9.5 without problems.

3. Making sure that make-variables like $(SED), $(AR) are set correctly. Otherwise the make-process will fail. An error is that you need to define $(SED) before using it. I have built iproute2 before iptables-p2p. $(SED) is not defined then. I suggest to define $(SED) in buildroot/Makefile. I still prefer a much more simple solution:

4. As I have suggested in http://openwrt.org/forum/viewtopic.php?t=430 I use a preconfigure target i.e. in each of the two *.mk-files to simply copy pre-edited makefiles to like iptables-1.2.9/kernel/Makefile.
So you can keep the pre-edited files in i.e. buildroot/sources/customize, make all targets clean and re-run make without the need to edit all the files that need to be changed again.

Anyway, at least it compiles. Now I still need to test...!

Yes, you are right.
Using this method has the biggest drawback, that you have to edit the Makefile after unpacking / configuring the sources from time to time.

A real SED/AWK crack can probably edit the openwrt .mk files so that all "wrong stuff" gets replaced in the programs Makefiles by SED automatically.

The discussion might have continued from here.