From f9fffd4a9e04417bc042f3ab1ee710d902a773e8 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 24 Apr 2013 13:21:25 -0400 Subject: [PATCH] Improve compilation process for OpenWrt - common.mk has been tweaked so that the OpenWrt compilation process is more flexible: one can now choose an OPENWRT_TARGET and the OPENWRT_ROOT instead of just the OPENWRT_VERSION. - The OPENWRT_VERSION's default value trunk" has been removed. - Makefile_atheros_openwrt has been deleted, since with recent OpenWrt versions (12.09) everything should compile just fine, and we are not specific to the atheros target any more. - INSTALL.t2t has been updated to reflect these changes, and a new section was added to explain how to compile your own toolchain. --- INSTALL.t2t | 98 ++++++++++++++++++++++++++++++---------- Makefile_atheros_openwrt | 45 ------------------ common.mk | 51 ++++++++++++--------- 3 files changed, 102 insertions(+), 92 deletions(-) delete mode 100644 Makefile_atheros_openwrt diff --git a/INSTALL.t2t b/INSTALL.t2t index 0678425..a5ec166 100644 --- a/INSTALL.t2t +++ b/INSTALL.t2t @@ -51,43 +51,91 @@ specific GCC version to be used. = Compiling for OpenWrt = +== The OpenWrt toolchain == + +We strongly advise that you download the full OpenWrt source tree +instead of just the pre-compiled SDK, because it will allow you to +easily add the components needed by the OwlPS modules you want to build. +The OpenWrt documentation will help you with that: + +- http://wiki.openwrt.org/doc/howto/buildroot.exigence +- http://wiki.openwrt.org/doc/howto/build + + +In the configuration (``make menuconfig``), you have to: + ++ Choose the OpenWrt //Target System// (and possibly //Subtarget//). + ++ Select the components needed to build (press the key to have a + //M// or a //*//). For example: + - in the //Libraries// menu, select //boost-program_options//, + //confuse// and //libiw//; + - in the //Base system// menu, //libpthread//, //librt// and + //libstdcpp// should now be automatically selected. + + +== Make options == + To compile for OpenWrt, you need to set the ``OPENWRT_VERSION`` variable when calling make, for example: -``` make OPENWRT_VERSION=10.03 +``` make OPENWRT_VERSION=12.09 -The makefile ``Makefile_atheros_openwrt`` will help you compile only -modules that have been tested for OpenWrt. If you do not set -``OPENWRT_VERSION``, it will set it for you to "10.03", but you can -specify another version, such as "trunk": -``` make -f Makefile_atheros_openwrt OPENWRT_VERSION=trunk +You can also specify OPENWRT_ROOT and OPENWRT_TARGET: -It is assumed than the OpenWrt SDK is installed in -``$HOME/openwrt/buildroot`` and that the target architecture is -``atheros``. For a different set up, you will need to edit the -``common.mk`` file. +- OPENWRT_ROOT defines the path to the base directory in which the + OpenWrt stuff is (default: $HOME/openwrt). -For now, only OpenWrt 10.03 and trunk are supported. If you set -OPENWRT_VERSION to something different than "10.03", it is replaced by -"trunk". +- OPENWRT_TARGET is the name of the OpenWrt target to build for + (default: atheros). -For this to work we advise that you do something like that: + +The toolchain is assumed to be under the +``$OPENWRT_ROOT/$OPENWRT_TARGET/$OPENWRT_VERSION`` directory. + +For maintainability's sake, we don't handle changes of version of the +toolchain's tools, so you have to create symbolic links under this +directory (change the ``*`` with the relevant version numbers and all): + +- ``target_uClibc`` pointing on ``staging_dir/target-$ARCH_*_uClibc-*`` + +- ``toolchain_gcc_uClibc`` pointing on + ``staging_dir/toolchain-$ARCH_*_gcc-*_uClibc-*`` + + +It might be easier to install your OpenWrt buildroot in a separate +directory, and just use symbolic links to point to the relevant +version (cf. example below). + + +== Example of OpenWrt set-up == + +We assume here that you want to build for the last OpenWrt development +version (//trunk//), for the //ar71xx// target, and that the OpenWrt +material is in the ``/opt/openwrt`` directory. You will compile with the +following command line: + +``` make OPENWRT_VERSION=trunk OPENWRT_TARGET=ar71xx OPENWRT_ROOT=/opt/openwrt + +We also assume your trunk OpenWrt source tree is in the +``/opt/openwrt/trunk`` directory. For this to work, you will first +create the ``/opt/openwrt/ar71xx/trunk`` directory, and link the +toolchain's directories from it. As of writing, the following commands +will do what you need: ``` -mkdir -p ~/openwrt/atheros/trunk -cd ~/openwrt/atheros/trunk -ln -s ../../buildroot/staging_dir -ln -s \ - ../../buildroot/staging_dir/target-mips_uClibc-0.9.33 \ - target-mips_uClibc -ln -s \ - ../../buildroot/staging_dir/toolchain-mips_gcc-4.6-linaro_uClibc-0.9.33/ \ - toolchain-mips_gcc_uClibc + mkdir -p /opt/openwrt/ar71xx/trunk + cd /opt/openwrt/ar71xx/trunk + ln -s ../../trunk/staging_dir + ln -s staging_dir/target-mips_r2_uClibc-0.9.33.2 target_uClibc + ln -s staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2 \ + toolchain_gcc_uClibc ``` -Of course, you will have to update the symlinks when you compile a new -version of the SDK. +Of course, you will have to update the ``target_uClibc`` and +``toolchain_gcc_uClibc`` symbolic links from time to time, as the +tools' version numbers change in trunk. = Installing = diff --git a/Makefile_atheros_openwrt b/Makefile_atheros_openwrt deleted file mode 100644 index c7f4918..0000000 --- a/Makefile_atheros_openwrt +++ /dev/null @@ -1,45 +0,0 @@ -ifndef MAKEFILE - MAKEFILE := Makefile_atheros_openwrt -endif - -ifndef OPENWRT_VERSION - OPENWRT_VERSION := 10.03 -endif - -include common.mk - -.PHONY: \ - all help \ - libowlps \ - libowlps-client \ - owlps-client \ - owlps-listener - - -## Compilation ## - -all: \ - libowlps \ - libowlps-client \ - owlps-client \ - owlps-listener - -libowlps: - @$(MAKE) -C $@ $(TARGET) -libowlps-client: libowlps - @$(MAKE) -C $@ $(TARGET) -owlps-client: libowlps libowlps-client - @$(MAKE) -C $@ $(TARGET) -owlps-listener: libowlps libowlps-client - @$(MAKE) -C $@ $(TARGET) - - -## Help ## - -help : - @echo "Compiles the supported modules for OpenWrt Atheros." - @echo "Supported variables:" - @echo " MAKEFILE: makefile to call (default: $(MAKEFILE))." - @echo " OPENWRT_VERSION: version of OpenWrt to build against \ -(default: $(OPENWRT_VERSION))." - @echo " TARGET: target to call (default: all)." diff --git a/common.mk b/common.mk index 80d4f43..6baac2b 100644 --- a/common.mk +++ b/common.mk @@ -94,35 +94,41 @@ LDFLAGS := ## OpenWrt specifics ## # # To compile for OpenWrt, the OPENWRT_VERSION variable must be set. +# The other relevant variables are: +# OPENWRT_ROOT: path to the base directory in which the OpenWrt stuff +# is (default: $HOME/openwrt). +# OPENWRT_TARGET: name of the OpenWrt target to build for (default: +# atheros). # -# By default (i.e. if OPENWRT_VERSION is set to something else than a -# known version number, we assume compiling for trunk. For this to -# work we advise that you do something like that (assuming the OpenWrt -# builroot is installed in ~/openwrt/buildroot): -# mkdir -p ~/openwrt/atheros/trunk -# cd ~/openwrt/atheros/trunk -# ln -s ../../buildroot/staging_dir -# ln -s \ -# ../../buildroot/staging_dir/target-mips_uClibc-0.9.33 \ -# target-mips_uClibc -# ln -s \ -# ../../buildroot/staging_dir/toolchain-mips_gcc-4.6-linaro_uClibc-0.9.33/ \ -# toolchain-mips_gcc_uClibc -# Of course, you have to update the symlinks when you compile a new -# version of the SDK. +# To allow building against several targets and OpenWrt versions, we +# look for the toolchain in the following base directory, taking into +# account specificities of each version when needed: +# $OPENWRT_ROOT/$OPENWRT_TARGET/$OPENWRT_VERSION +# +# For maintainability's sake, we don't handle changes of version of the +# toolchain's tools, so you have to create symbolic links under this +# directory: +# target_uClibc --> staging_dir/target-$ARCH_*_uClibc-* +# toolchain_gcc_uClibc --> staging_dir/toolchain-$ARCH_*_gcc-*_uClibc-* +# +# See the documentation in INSTALL.t2t for further information on how to +# set up a building environment for OpenWrt. +# +ifndef OPENWRT_PATH + OPENWRT_ROOT = $${HOME}/openwrt +endif +ifndef OPENWRT_TARGET + OPENWRT_TARGET := atheros +endif ifdef OPENWRT_VERSION - TOOLCHAIN_PREFIX := $${HOME}/openwrt/atheros/trunk + TOOLCHAIN_PREFIX := $(OPENWRT_ROOT)/$(OPENWRT_TARGET)/$(OPENWRT_VERSION) STAGING_DIR := $(TOOLCHAIN_PREFIX)/staging_dir - TOOLCHAIN1 := $(TOOLCHAIN_PREFIX)/toolchain-mips_gcc_uClibc + TOOLCHAIN1 := $(TOOLCHAIN_PREFIX)/toolchain_gcc_uClibc TOOLCHAIN_BIN := $(TOOLCHAIN1)/bin - TOOLCHAIN2 := $(TOOLCHAIN_PREFIX)/target-mips_uClibc + TOOLCHAIN2 := $(TOOLCHAIN_PREFIX)/target_uClibc ifeq "$(OPENWRT_VERSION)" "10.03" - TOOLCHAIN_PREFIX := $${HOME}/openwrt/atheros/10.03/staging_dir - STAGING_DIR := $(TOOLCHAIN_PREFIX) - TOOLCHAIN1 := $(TOOLCHAIN_PREFIX)/toolchain-mips_gcc-4.3.3+cs_uClibc-0.9.30.1 TOOLCHAIN_BIN := $(TOOLCHAIN1)/usr/bin - TOOLCHAIN2 := $(TOOLCHAIN_PREFIX)/target-mips_uClibc-0.9.30.1 endif CFLAGS += -I$(TOOLCHAIN1)/usr/include -I$(TOOLCHAIN2)/usr/include @@ -131,6 +137,7 @@ ifdef OPENWRT_VERSION SEMISTATIC_LDFLAGS += $(TOOLCHAIN1)/lib/ld-uClibc.so.0 CC := STAGING_DIR=$(STAGING_DIR) $(TOOLCHAIN_BIN)/mips-openwrt-linux-gcc + CXX := STAGING_DIR=$(STAGING_DIR) $(TOOLCHAIN_BIN)/mips-openwrt-linux-g++ STRIP := STAGING_DIR=$(STAGING_DIR) $(TOOLCHAIN_BIN)/mips-openwrt-linux-strip -s endif