wiki:TipAndDoc/Linux/OpenWRT/CrossCompile

Version 4 (modified by mitty, 12 years ago) (diff)

--

buildroot

  • Ubuntu 12.04 LTS x86_64
  • mitty@precise:~$ sudo aptitude install subversion build-essential libncurses5-dev zlib1g-dev gawk gcc-multilib flex git-core gettext libssl-dev xsltproc bison
  • mitty@precise:~$ mkdir openwrt
  • mitty@precise:~/openwrt/trunk$ make prereq
    Collecting package info: done
    Collecting target info: done
    Checking 'working-make'... ok.
    Checking 'case-sensitive-fs'... ok.
    Checking 'getopt'... ok.
    Checking 'fileutils'... ok.
    Checking 'working-gcc'... ok.
    Checking 'working-g++'... ok.
    Checking 'ncurses'... ok.
    Checking 'zlib'... ok.
    Checking 'gawk'... ok.
    Checking 'flex'... ok.
    Checking 'unzip'... ok.
    Checking 'bzip2'... ok.
    Checking 'patch'... ok.
    Checking 'perl'... ok.
    Checking 'python'... ok.
    Checking 'wget'... ok.
    Checking 'git'... ok.
    Checking 'gnutar'... ok.
    Checking 'svn'... ok.
    Checking 'gnu-find'... ok.
    Checking 'getopt-extended'... ok.
    Checking 'non-root'... ok.
    
  • mitty@precise:~/openwrt/trunk$ make -j 5 V=99 2>&1 | tee build.log | grep -i error
    (snip)
    
    make[2]: [package/rootfs-prepare] Error 2 (ignored)
    Compression errors: 0
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wpe72.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    Compression errors: 0
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wp543.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    [mkmylofw] Error: file /home/mitty/openwrt/trunk/build_dir/linux-ar71xx_generic/tmp/vmlinux-wpe72.bin.lzma is too big
    make[5]: [install] Error 1 (ignored)
    make[3]: [/home/mitty/openwrt/trunk/bin/ar71xx/OpenWrt-ImageBuilder-ar71xx_generic-for-Linux-x86_64.tar.bz2] Error 1 (ignored)
    make[3]: [/home/mitty/openwrt/trunk/bin/ar71xx/OpenWrt-ImageBuilder-ar71xx_generic-for-Linux-x86_64.tar.bz2] Error 1 (ignored)
    
  • mitty@precise:~/openwrt$ cat > test.c
    #include <stdio.h>
    
    int main(void) {
            printf("char        -> %ld\n", sizeof(char));
            printf("short       -> %ld\n", sizeof(short));
            printf("int         -> %ld\n", sizeof(int));
            printf("long        -> %ld\n", sizeof(long));
            printf("long long   -> %ld\n", sizeof(long long));
            printf("float       -> %ld\n", sizeof(float));
            printf("double      -> %ld\n", sizeof(double));
            printf("long double -> %ld\n", sizeof(long double));
    
            return 0;
    }
    
  • mitty@precise:~/openwrt$ gcc test.c -o test.x86
  • mitty@precise:~/openwrt$ ./trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc test.c -o test
    mips-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
    mips-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
    mips-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
    
  • mitty@precise:~/openwrt$ file test test.x86
    test:     ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), with unknown capability 0x41000000 = 0xf676e75, with unknown capability 0x10000 = 0x70403, not stripped
    test.x86: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x53177842cbc614b1f4c71bae24df294892906443, not stripped
    
  • mitty@precise:~/openwrt$ ./test.x86
    char        -> 1
    short       -> 2
    int         -> 4
    long        -> 8
    long long   -> 8
    float       -> 4
    double      -> 8
    long double -> 16
    
  • mitty@precise:~/openwrt$ ./test
    bash: ./test: cannot execute binary file
    
  • mitty@starseed:~$ uname -a
    Linux starseed 3.3.6 #1 Thu May 17 02:19:20 PDT 2012 mips GNU/Linux
    
  • mitty@starseed:~$ ./test
    char        -> 1
    short       -> 2
    int         -> 4
    long        -> 4
    long long   -> 8
    float       -> 4
    double      -> 8
    long double -> 8
    

build others

utvpn

  • mitty@precise:~/openwrt/trunk/package$ svn co https://lab.mitty.jp/svn/lab/trunk/Dev/utvpn/utvpn-unix-v101-7101-public utvpn
  • mitty@precise:~/openwrt/trunk/package/utvpn$ ./configure
    -------------------------------------------------------------
    SoftEther UT-VPN for Unix
    
    Copyright (C) 2004-2010 SoftEther Corporation.
    Copyright (C) 2004-2010 University of Tsukuba, Japan.
    Copyright (C) 2003-2010 Daiyuu Nobori. All Rights Reserved.
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    version 2 as published by the Free Software Foundation.
    -------------------------------------------------------------
    
    Please select your Operating System below:
     1: Linux
     2: FreeBSD
     3: Solaris
     4: Mac OS X
    
    Which is your operating system (1-4):
    1
    
    Please select your CPU Bits below:
     1: 32-bit
     2: 64-bit
    
    Which is the bits of your CPU (1-2):
    1
    
    Makefile is generated. Please execute 'make' to build UT-VPN.
    
  • mitty@precise:~/openwrt/trunk/package/utvpn$ sha1sum Makefile makefiles/linux_32bit_ja.mak
    5d63c1cbb04ef9a3ecc6d4b8f1150cac20fbfa9d  Makefile
    5d63c1cbb04ef9a3ecc6d4b8f1150cac20fbfa9d  makefiles/linux_32bit_ja.mak
    
    • Makefileは単純にcpしているだけ
  • mitty@precise:~/openwrt/trunk/package/utvpn$ svn cp makefiles/linux_32bit_ja.mak Makefile

build with gcc for mips

  • mitty@precise:~/openwrt/trunk/package/utvpn$ export PATH=$PATH:~/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/
  • mitty@precise:~/openwrt/trunk/package/utvpn$ make CC=mips-openwrt-linux-gcc LD=mips-openwrt-linux-ld
    mips-openwrt-linux-gcc -DNDEBUG -DVPN_SPEED -DUNIX -DUNIX_LINUX -D_REENTRANT -DREENTRANT -D_THREAD_SAFE -D_THREADSAFE -DTHREAD_SAFE -DTHREADSAFE -I./src/ -I./src/Cedar/ -I./src/Mayaqua/ -O2 -fsigned-char -c src/Mayaqua/Cfg.c -o tmp/objs/Mayaqua/Cfg.o
    mips-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
    In file included from src/Mayaqua/Cfg.c:90:0:
    ./src/Mayaqua/Mayaqua.h:219:31: fatal error: readline/readline.h: No such file or directory
    compilation terminated.
    make: *** [tmp/objs/Mayaqua/Cfg.o] Error 1
    
  • mitty@precise:~$ sudo aptitude install -R libssl-dev libreadline-dev libncurses-dev
  • mitty@precise:~/openwrt/trunk/package/utvpn$ export STAGING_DIR=~/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/
  • mitty@precise:~/openwrt/trunk/package/utvpn$ make CC=mips-openwrt-linux-gcc LD=mips-openwrt-linux-ld
    (snip)
    
    mips-openwrt-linux-gcc tmp/as/Ham.a -O2 -fsigned-char -lm -ldl -lrt -lpthread -lssl -lcrypto -lreadline -lncurses -lz -o output/ham/ham
    /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lssl
    /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lcrypto
    /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lreadline
    /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lncurses
    /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lz
    collect2: ld returned 1 exit status
    

zlib

  • mitty@precise:~$ export PATH=$PATH:~/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/
  • mitty@precise:~$ export STAGING_DIR=~/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/
  • mitty@precise:~/openwrt$ wget http://zlib.net/zlib-1.2.7.tar.gz
  • mitty@precise:~/openwrt/zlib-1.2.7$ ./configure --prefix=$STAGING_DIR
  • mitty@precise:~/openwrt/zlib-1.2.7$ vim Makefile
    • Makefile

      old new  
      1616# To install in $HOME instead of /usr/local, use: 
      1717#    make install prefix=$HOME 
      1818 
      19 CC=gcc 
       19CC=mips-openwrt-linux-gcc 
      2020 
      2121CFLAGS=-O3  -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN 
      2222#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 
       
      2727SFLAGS=-O3  -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN 
      2828LDFLAGS=  
      2929TEST_LDFLAGS=-L. libz.a 
      30 LDSHARED=gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map 
      31 CPP=gcc -E 
       30LDSHARED=mips-openwrt-linux-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map 
       31CPP=mips-openwrt-linux-gcc -E 
      3232 
      3333STATICLIB=libz.a 
      3434SHAREDLIB=libz.so 
       
      3636SHAREDLIBM=libz.so.1 
      3737LIBS=$(STATICLIB) $(SHAREDLIBV) 
      3838 
      39 AR=ar 
       39AR=mips-openwrt-linux-ar 
      4040ARFLAGS=rc 
      41 RANLIB=ranlib 
       41RANLIB=mips-openwrt-linux-ranlib 
      4242LDCONFIG=ldconfig 
      4343LDSHAREDLIBC=-lc 
      4444TAR=tar 
  • mitty@precise:~/openwrt/zlib-1.2.7$ make
  • mitty@precise:~/openwrt/zlib-1.2.7$ make install
    cp libz.a /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//lib
    chmod 644 /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//lib/libz.a
    cp libz.so.1.2.7 /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//lib
    chmod 755 /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//lib/libz.so.1.2.7
    cp zlib.3 /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//share/man/man3
    chmod 644 /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//share/man/man3/zlib.3
    cp zlib.pc /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//lib/pkgconfig
    chmod 644 /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//lib/pkgconfig/zlib.pc
    cp zlib.h zconf.h /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//include
    chmod 644 /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//include/zlib.h /home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2//include/zconf.h
    

openssl

  • mitty@precise:~/openwrt$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
  • mitty@precise:~/openwrt/openssl-1.0.1c$ vim Makefile
    • Makefile

      old new  
      2626# for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/. 
      2727# Normally it is left empty. 
      2828INSTALL_PREFIX= 
      29 INSTALLTOP=/usr/local/ssl 
       29INSTALLTOP=/home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/ 
      3030 
      3131# Do not edit this manually. Use Configure --openssldir=DIR do change this! 
      32 OPENSSLDIR=/usr/local/ssl 
       32OPENSSLDIR=/home/mitty/openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/ 
      3333 
      3434# NO_IDEA - Define to build without the IDEA algorithm 
      3535# NO_RC4  - Define to build without the RC4 algorithm 
       
      5959# equal 4. 
      6060# PKCS1_CHECK - pkcs1 tests. 
      6161 
      62 CC= cc 
       62CC= mips-openwrt-linux-gcc 
      6363CFLAG= -O 
      6464DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_STORE 
      6565PEX_LIBS=  
      6666EX_LIBS=  
      6767EXE_EXT=  
      6868ARFLAGS=  
      69 AR= ar $(ARFLAGS) r 
      70 RANLIB= /usr/bin/ranlib 
       69AR= mips-openwrt-linux-ar $(ARFLAGS) r 
       70RANLIB= mips-openwrt-linux-ranlib 
      7171NM= nm 
      7272PERL= /usr/bin/perl 
      7373TAR= tar 
  • mitty@precise:~/openwrt/openssl-1.0.1c$ make
  • mitty@precise:~/openwrt/openssl-1.0.1c$ make install
  • mitty@precise:~$ file openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/openssl
    openwrt/trunk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/openssl: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), with unknown capability 0x41000000 = 0xf676e75, with unknown capability 0x10000 = 0x70403, not stripped