cross compile linux kernel on Mac OS X with crosstool-ng

    • install crosstool-ng on Mac OS X Mojave with brew
      • brew install crosstool-ng
    • make a case-sensitive volume
  • mkdir -p ~/Document/workfoler,   cd ~/Document/workfoler
  • ct-ng x86_64-centos7-linux-gnu
  • ct-ng source
  • ct-ng build
  • then will encouter an error when build gettext:
    [ALL ] /Users/andrew/Documents/learnkernel/.build/src/gettext-0.19.8.1/build-aux/missing: line 81: automake-1.15: command not found
    [ALL ] WARNING: 'automake-1.15' is missing on your system.
    [ALL ] You should only need it if you modified 'Makefile.am' or
    [ALL ] 'configure.ac' or m4 files included by 'configure.ac'.
    [ALL ] The 'automake' program is part of the GNU Automake package:
    [ALL ] <http://www.gnu.org/software/automake>
    [ALL ] It also requires GNU Autoconf, GNU m4 and Perl in order to run:
    [ALL ] <http://www.gnu.org/software/autoconf>
    [ALL ] <http://www.gnu.org/software/m4/>
    [ALL ] <http://www.perl.org/>

    replace 1.15 with 1.16.1 in all the aclocal.m4 file under gettext source folder
    ./gettext-tools/examples/aclocal.m4
    ./gettext-tools/aclocal.m4
    ./gettext-runtime/aclocal.m4
    ./gettext-runtime/libasprintf/aclocal.m4
    ./aclocal.m4
  • make a soft link for automake-1.15
    ln -s /usr/local/Cellar/automake/1.16.1_1/bin/automake /usr/local/bin/automake-1.15

 

  • cd linux kernel src folder

    export PATH=/Users/andrew/Documents/learnkernel/.build/x86_64-centos7-linux-gnu/buildtools/bin:$PATH
    export CROSS_COMPILE=x86_64-centos7-linux-gnu-
    export ARCH=x86
  • then make
  • if encounter below error
    In file included from include/linux/compiler.h:54:0,
    from include/uapi/linux/stddef.h:1,
    from include/linux/stddef.h:4,
    from /Users/andrew/Documents/linux/linux-3.9.4/include/uapi/linux/posix_types.h:4,
    from include/uapi/linux/types.h:13,
    from include/linux/types.h:5,
    from include/linux/page-flags.h:8,
    from kernel/bounds.c:9:
    include/linux/compiler-gcc.h:103:30: fatal error: linux/compiler-gcc6.h: No such file or directory
    #include gcc_header(__GNUC__)
    workaround:
    cp compiler-gcc4.h compiler-gcc6.h
  • if encounter such error “sed: illegal option — r”,</
    $ brew uninstall gnu-sed
    $ brew install gnu-sed --with-default-names
    $ echo $PATH | grep -q '/usr/local/bin'; [ $? -ne 0 ] && export PATH=/usr/local/bin:$PATH
    $ echo a | sed 's_A_X_i'
    li>
  • eee