Setup cross compilers - ytomino/drake GitHub Wiki
Contents
Copy the files from the target to the host. tar is a good tool to copy a whole directory structure with keeping links.
- ~/opt/ (any path)
- x86_64-apple-darwin13/ (if Mavericks)
- usr/
- include/ (copied from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOS10.9.sdk/usr/include)
- lib/ (copied from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOS10.9.sdk/usr/lib)
- System/ (copied from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOS10.9.sdk/System)
- usr/
- x86_64-apple-darwin13/ (if Mavericks)
- ~/opt/ (any path)
- x86_64-pc-freebsd9/ (if FreeBSD9)
- usr/
- include/ (copied from /usr/include)
- lib/ (copied from /lib and /usr/lib)
- usr/
- x86_64-pc-freebsd9/ (if FreeBSD9)
You may have to adjust the symbolic links.
- ~/opt/ (any path)
- x86_64-linux-gnu/ (if Debian/Ubuntu)
- usr/
- include/ (copied from /usr/include)
- lib/
- *.o (copied from /usr/lib/x86_64-linux-gnu/*.o)
- libc.so (copied from /usr/lib/x86_64-linux-gnu/libc.so, and edit)
- libc.so.6 (link to libc-2.*.so)
- libc-2.*.so (copied from /lib/x86_64-linux-gnu/libc-2.*.so)
- libc_nonshared.a (coped from /usr/lib/x86_64-linux-gnu/libc_nonshared.a)
- ld-linux-x86_64.so.2 (link to ld-2.*.so)
- ld-2.*.so (copied from /lib/x86_64-linux-gnu/ld-2.*.so)
- libm.so (copied from /usr/lib/x86_64-linux-gnu/libm.so, and edit)
- libm.so.6 (link to libm-2.*.so)
- libm-2.*.so (coped from /lib/x86_64-linux-gnu/libm-2.*.so)
- libmvec_nonshared.a (coped from /usr/lib/x86_64-linux-gnu/libmvec_nonshared.a)
- libmvec.so.1 (link to libmvec-2.*.so)
- libmvec-2.*.so (copied from /lib/x86_64-linux-gnu/libmvec-2.27.so)
- libpthread.so (coped from /usr/lib/x86_64-linux-gnu/libpthread.so, and edit)
- libpthread.so.0 (link to libpthread-2.*.so)
- libpthread-2.*.so (coped from /lib/x86_64-linux-gnu/libpthread-2.*.so)
- libpthread_nonshared.a (coped from /usr/lib/x86_64-linux-gnu/libpthread_nonshared.a)
- libdl.so (link to libdl.so.2)
- libdl.so.2 (link to libdl-2.*.so)
- libdl-2.*.so (coped from /lib/x86_64-linux-gnu/libdl-2.*.so)
- librt.so (link to librt.so.1)
- librt.so.1 (link to librt-2.*.so)
- librt-2.*.so (copied from /lib/x86_64-linux-gnu/librt-2.*.so)
- ...
- usr/
- x86_64-linux-gnu/ (if Debian/Ubuntu)
You may have to adjust the symbolic links, and edit the path in libc.so, libm.so, and libpthread.so because those are text files!
- ~/opt/ (any path)
- i686-w64-mingw32/
- mingw32/ (or mingw64)
- i686-w64-mingw32/
- include/ (copied from /mingw32/i686-w64-mingw32/include)
- lib/ (copied from /mingw32/i686-w64-mingw32/lib)
- local/
- include/ (copied from /mingw32/local/include)
- lib/ (copied from /mingw32/local/lib)
- i686-w64-mingw32/
- mingw32/ (or mingw64)
- i686-w64-mingw32/
Use a patched cctools, like https://github.com/tpoechtrager/cctools-port.
configure \ --prefix=$HOME/opt/cctools \ # any path --with-sysroot=$HOME/opt/x86_64-apple-darwin13 \ --target=x86_64-apple-darwin13 \ --disable-clang-as \ --with-llvm-config=/usr/bin/llvm-config-5.0
clang is required for building cctools.
Use binutils.
configure \ --prefix=$HOME/opt/binutils \ # any path --with-sysroot=$HOME/opt/x86_64-pc-freebsd9 \ --target=x86_64-pc-freebsd9 \ --enable-lto \ --enable-plugins \ --disable-nls \ --with-system-zlib
Use binutils.
configure \ --prefix=$HOME/opt/binutils \ # any path --with-sysroot=$HOME/opt/x86_64-linux-gnu \ --target=x86_64-linux-gnu \ --enable-lto \ --enable-plugins \ --disable-nls \ --with-system-zlib
Use binutils.
configure \ --prefix=$HOME/opt/binutils \ # any path --with-sysroot=$HOME/opt/i686-w64-mingw32 \ --with-lib-path='=/mingw32/i686-w64-mingw32/lib:=/mingw32/lib:=/mingw32/local/lib' \ # (or mingw64) from sysroot --target=i686-w64-mingw32 \ --enable-lto \ --enable-plugins \ --disable-nls \ --with-system-zlib
configure \ --prefix=$HOME/opt/gcc-7.3.0 \ # any path --infodir=$HOME/opt/gcc-7.3.0/share/info \ --mandir=$HOME/opt/gcc-7.3.0/share/man \ --with-sysroot=$HOME/i686-w64-mingw32 \ --with-as=$HOME/opt/binutils/i686-w64-mingw32-as \ # absolute path --with-ld=$HOME/opt/binutils/i686-w64-mingw32-ld \ # absolute path --with-native-system-header-dir=/mingw32/i686-w64-mingw32/include \ # from sysroot, if needed --with-local-prefix=/mingw32/local \ # from sysroot, if needed --target=i686-w64-mingw32 \ --enable-languages=c,ada \ --disable-libcc1 \ --disable-nls \ --with-tune=generic \ --with-system-zlib \ --enable-static \ --disable-shared \ --enable-shared=libgcc \ --disable-multilib \ --disable-checking
Append your preferred options like --enable-lto, --with-cpu=, etc.
If the target is Darwin, just dsymutil is required for building libgcc.
Do ln -s /usr/bin/llvm-dsymutil-5.0 ~/bin/dsymutil (any directory in PATH).
If the target is MinGW-w64, the old paths /mingw/include and /mingw/lib are hard-coded in gcc. They should be fixed, or make a symbolic link.
Refer https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-gcc.
diff --git a/configure b/configure
index 0601395512..460904e7c4 100755
--- a/configure
+++ b/configure
@@ -7573,6 +7573,12 @@ case " $target_configdirs " in
esac
case "$target" in
+ i686-w64-mingw32)
+ FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -L${prefix}/${target}/lib -L${prefix}/mingw32/lib -isystem ${prefix}/${target}/include -isystem ${prefix}/mingw32/include'
+ ;;
+ x86_64-w64-mingw32)
+ FLAGS_FOR_TARGET=$FLAGS_FOR_TARGET' -L${prefix}/${target}/lib -L${prefix}/mingw64/lib -isystem ${prefix}/${target}/include -isystem ${prefix}/mingw64/include'
+ ;;
x86_64-*mingw* | *-w64-mingw*)
# MinGW-w64 does not use newlib, nor does it use winsup. It may,
# however, use a symlink named 'mingw' in ${prefix} .
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 7851238c64..5b1ab1d07a 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1805,12 +1805,13 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
case ${target} in
x86_64-w64-*)
tmake_file="${tmake_file} i386/t-mingw-w64"
+ native_system_header_dir=/mingw64/$(target)/include
;;
i[34567]86-w64-*)
tmake_file="${tmake_file} i386/t-mingw-w32"
+ native_system_header_dir=/mingw32/$(target)/include
;;
esac
- native_system_header_dir=/mingw/include
target_gtfiles="\$(srcdir)/config/i386/winnt.c"
extra_options="${extra_options} i386/cygming.opt i386/mingw.opt"
case ${target} in
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index a660108942..6fd66427a7 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -163,7 +163,11 @@ along with GCC; see the file COPYING3. If not see
/* Override startfile prefix defaults. */
#ifndef STANDARD_STARTFILE_PREFIX_1
-#define STANDARD_STARTFILE_PREFIX_1 "/mingw/lib/"
+#if !TARGET_64BIT_DEFAULT
+#define STANDARD_STARTFILE_PREFIX_1 "/mingw32/i686-w64-mingw32/lib/"
+#else
+#define STANDARD_STARTFILE_PREFIX_1 "/mingw64/x86_64-w64-mingw32/lib/"
+#endif
#endif
#ifndef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_2 ""
@@ -171,8 +175,9 @@ along with GCC; see the file COPYING3. If not see
/* For native mingw-version we need to take care that NATIVE_SYSTEM_HEADER_DIR
macro contains POSIX-style path. See bug 52947. */
-#undef NATIVE_SYSTEM_HEADER_DIR
+#ifndef NATIVE_SYSTEM_HEADER_DIR
#define NATIVE_SYSTEM_HEADER_DIR "/mingw/include"
+#endif
/* Output STRING, a string representing a filename, to FILE.
We canonicalize it to be in Unix format (backslashes are replaced