-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Cross compilation
This page describes how to cross-compile jq for Windows on Linux and similar. To cross compile, use the --host=
and --target=
./configure options to select a cross-compilation environment. A similar method could be used to cross-compile for OS X on Linux and similar. It is also possible to "cross-compile" for the same OS/platform, which is helpful for scripting release production as every build can be done the same way, with the only differences being the $PATH
, host triplets, and targets.
This assumes /home/build
is where cross-compilation tools like MinGW32 are found, as well as jq and Oniguruma workspaces.
Pretend : ;
is the shell $PS1
-- this makes it easy to cut-n-paste (because :
is the same as true
). Setting $PS1
this way is quite convenient in general. It also helps to set $PS2
to the empty string, or to a string of whitespace.
Prep:
: ; autoreconf -fi
: ; ./configure
: ; make distclean
: ;
: ; # Install mingw bits into /home/build/mingw/mingw-w64-x86_64
: ;
: ; # Fetch Oniguruma 5.9.5, untar into /home/build/ws/onig-5.9.5
For Windows (64-bit):
: ; # Make a directory for installing cross-built code into
: ; mkdir -p /home/build/proto/win64
: ;
: ; # Set PATH
: ; PATH=/home/build/mingw/mingw-w64-x86_64/bin:$PATH
: ;
: ; # Build Oniguruma
: ; cd /home/build/ws/onig-5.9.5
: ; ./configure --target=win64-x86_64 --host=x86_64-w64-mingw32 --prefix=/home/build/proto/win64/usr/local
: ; make -j16 LDFLAGS=-all-static clean all install
: ;
: ; # Build jq
: ; cd /home/build/ws/jq
: ; scripts/crosscompile win64 --disable-shared --enable-static --enable-all-static --target=win64-x86_64 --host=x86_64-w64-mingw32 --with-oniguruma=/home/build/proto/win64/usr/local
Similarly for Windows 32-bit:
: ; # Make a directory for installing cross-built code into
: ; mkdir -p /home/build/proto/win32
: ;
: ; # Set PATH
: ; PATH=/home/build/mingw/mingw-w32-x86_64/bin:$PATH
: ;
: ; # Build Oniguruma
: ; cd /home/build/ws/onig-5.9.5
: ; ./configure --target=win32-i686 --host=i686-w64-mingw32 --prefix=/home/build/proto/win32/usr/local
: ; make -j16 LDFLAGS=-all-static clean all install
: ;
: ; # Build jq
: ; cd /home/build/ws/jq
: ; scripts/crosscompile win32 --disable-shared --enable-static --enable-all-static --target=win32-i686 --host=i686-w64-mingw32 --with-oniguruma=/home/build/proto/win32/usr/local
This recipe works for any target for which there are cross-compilation tools.
For OS X: (feel free to contribute this)
Some links for OS X cross-compilation (no endorsement implied):
- http://wiki.freepascal.org/Cross_compiling_OSX_on_Linux (probably the best link)
- http://stackoverflow.com/questions/693952/how-to-compile-for-os-x-in-linux-or-windows
- http://devs.openttd.org/~truebrain/compile-farm/apple-darwin9.txt
- http://www.sandroid.org/imcross/
- https://launchpad.net/~flosoft/+archive/ubuntu/cross-apple
- https://github.com/tpoechtrager/osxcross
For debugging cross-compiled Windows executables there is https://github.com/rainers/cv2pdb; see also http://blog.morlad.at/blah/mingw_postmortem.
For alternative way to cross-compile on a platform, the perl5 binding author has made a CMakeList.txt - https://github.com/dxma/perl5-alien-libjq/blob/master/jq/CMakeLists.txt. It is lack of certain feature support, such as dev version auto-fetch, distribution bundle, but can be used to make the executable itself and underlying dynamic/static library.
- Home
- FAQ
- jq Language Description
- Cookbook
- Modules
- Parsing Expression Grammars
- Docs for Oniguruma Regular Expressions (RE.txt)
- Advanced Topics
- Guide for Contributors
- How To
- C API
- jq Internals
- Tips
- Development