unicorn/COMPILE.TXT

305 lines
9.2 KiB
Text
Raw Normal View History

2015-08-21 07:04:50 +00:00
This documentation explains how to compile, install & run Unicorn on MacOSX,
Linux, *BSD & Solaris. We also show steps to cross-compile for Microsoft Windows.
*-*-*-*-*-*
[0] Dependencies
2015-10-15 08:15:45 +00:00
Unicorn requires few dependent packages as follows.
2015-08-21 07:04:50 +00:00
2015-08-25 22:22:56 +00:00
- For Mac OS X, "pkg-config" and "glib" are needed.
Brew users can install "pkg-config" and "glib" with:
2015-08-21 07:04:50 +00:00
2015-08-25 22:22:56 +00:00
$ brew install pkg-config glib
2015-08-21 07:04:50 +00:00
2015-10-15 14:07:26 +00:00
- For Linux, "glib2-dev" is needed.
2015-08-21 07:04:50 +00:00
Ubuntu/Debian users can install this with:
$ sudo apt-get install libglib2.0-dev
2015-10-15 08:05:30 +00:00
- For Windows, cross-compile requires Mingw. Mingw-glib2 is needed.
2015-10-15 14:07:26 +00:00
At the moment, it is confirmed that Unicorn can be compiled either on Ubuntu
or Windows.
2015-08-21 07:04:50 +00:00
2015-10-15 14:07:26 +00:00
- On Ubuntu 14.04 64-bit, do:
2015-08-21 07:04:50 +00:00
2015-10-15 14:07:26 +00:00
1. Download DEB packages for Mingw64 from:
https://launchpad.net/~greg-hellings/+archive/ubuntu/mingw-libs/+build/2924251
2015-08-21 07:04:50 +00:00
2. To cross-compile for Windows 32-bit, install Mingw with (ignore all the warnings):
$ sudo dpkg -i --force-depends mingw64-x86-glib2_2.31.0_all.deb
To cross-compile for Windows 64-bit, install Mingw with:
$ sudo dpkg -i --force-depends mingw64-x64-glib2_2.31.0_all.deb
2015-10-15 14:07:26 +00:00
- On Windows, install MinGW via package MSYS2 at https://msys2.github.io/
Follow the install instructions and don't forget to update the system packages with:
$ pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime
Then close MSYS2, run it again from Start menu and update the rest with:
$ pacman -Su
Finally, install required toolchain to build C projects.
- To compile for Windows 32-bit, run:
$ pacman -S python2
2015-10-15 14:07:26 +00:00
$ pacman -S make
$ pacman -S pkg-config
$ pacman -S mingw-w64-i686-glib2
$ pacman -S mingw-w64-i686-toolchain
- To compile for Windows 64-bit, run:
$ pacman -S python2
2015-10-15 14:07:26 +00:00
$ pacman -S make
$ pacman -S pkg-config
$ pacman -S mingw-w64-x86_64-glib2
$ pacman -S mingw-w64-x86_64-toolchain
2016-01-01 06:14:03 +00:00
- For Cygwin, "make", "gcc-core", "pkg-config", "libpcre-devel", "zlib-devel"
and "libglib2.0-devel" are needed.
2015-12-17 05:20:57 +00:00
If apt-cyg is available, you can install these with:
$ apt-cyg install make gcc-core pkg-config libpcre-devel zlib-devel libglib2.0-devel
2015-10-15 14:07:26 +00:00
2015-08-21 07:04:50 +00:00
[1] Tailor Unicorn to your need.
2015-09-22 04:12:17 +00:00
Out of 6 archtitectures supported by Unicorn (Arm, Arm64, M68K, Mips, Sparc,
& X86), if you just need several selected archs, choose which ones you want
to compile in by editing "config.mk" before going to next steps.
2015-08-21 07:04:50 +00:00
2015-09-22 04:12:17 +00:00
By default, all 6 architectures are compiled.
2015-08-21 07:04:50 +00:00
The other way of customize Unicorn without having to edit config.mk is to
pass the desired options on the commandline to ./make.sh. Currently,
2015-10-15 08:15:45 +00:00
Unicorn supports 4 options, as follows.
2015-08-21 07:04:50 +00:00
- UNICORN_ARCHS: specify list of architectures to compiled in.
- UNICORN_STATIC: build static library.
- UNICORN_SHARED: build dynamic (shared) library.
2015-09-04 15:56:29 +00:00
- UNICORN_QEMU_FLAGS: specify extra flags for qemu's configure script
2015-08-21 07:04:50 +00:00
To avoid editing config.mk for these customization, we can pass their values to
2015-10-15 08:15:45 +00:00
make.sh, as follows.
2015-08-21 07:04:50 +00:00
$ UNICORN_ARCHS="arm aarch64 x86" ./make.sh
NOTE: on commandline, put these values in front of ./make.sh, not after it.
For each option, refer to docs/README for more details.
2015-10-15 08:05:30 +00:00
[2] Compile and install from source on *nix
2015-08-21 07:04:50 +00:00
2015-10-15 08:05:30 +00:00
To build Unicorn on *nix (such as MacOSX, Linux, *BSD, Solaris):
2015-08-21 07:04:50 +00:00
- To compile for current platform, run:
$ ./make.sh
2015-08-21 07:04:50 +00:00
- Unicorn requires Python 2.x to compile. If Python 2.x is not the default
Python interpreter, ensure that the appropriate option is set:
$ UNICORN_QEMU_FLAGS="--python=/path/to/python2" ./make.sh
2015-10-15 08:05:30 +00:00
- To cross-compile Unicorn on 64-bit OS to target 32-bit binary, run:
2015-08-21 07:04:50 +00:00
$ ./make.sh nix32
2015-08-21 07:04:50 +00:00
2015-10-15 08:05:30 +00:00
After compiling, install Unicorn with:
2015-08-21 07:04:50 +00:00
$ sudo ./make.sh install
2015-08-21 07:04:50 +00:00
For FreeBSD/OpenBSD, where sudo is unavailable, run:
2015-08-21 07:04:50 +00:00
$ su; ./make.sh install
2015-08-21 07:04:50 +00:00
Users are then required to enter root password to copy Unicorn into machine
system directories.
2015-10-15 08:05:30 +00:00
Afterwards, run ./samples/sample_all.sh to test the sample emulations.
2015-08-21 07:04:50 +00:00
NOTE: The core framework installed by "./make.sh install" consist of
following files:
/usr/include/unicorn/unicorn.h
/usr/include/unicorn/x86.h
/usr/include/unicorn/arm.h
/usr/include/unicorn/arm64.h
/usr/include/unicorn/mips.h
/usr/include/unicorn/ppc.h
/usr/include/unicorn/sparc.h
/usr/include/unicorn/m68k.h
/usr/include/unicorn/platform.h
/usr/lib/libunicorn.so (for Linux/*nix), or /usr/lib/libunicorn.dylib (OSX)
/usr/lib/libunicorn.a
2015-08-21 07:04:50 +00:00
2015-10-15 08:05:30 +00:00
[3] Compile from source on Windows - with MinGW (MSYS2)
2015-10-15 14:07:26 +00:00
To compile with MinGW, install MSYS2 as instructed in the first section.
Then, build Unicorn with the next steps:
2015-10-15 08:05:30 +00:00
- To compile Windows 32-bit binary with MinGW, run:
$ ./make.sh cross-win32
- To compile Windows 64-bit binary with MinGW, run:
$ ./make.sh cross-win64
Resulted files unicorn.dll, unicorn.lib & samples/sample*.exe can then
be used on Windows machine.
To run sample_x86.exe on Windows 32-bit, you need the following files:
- unicorn.dll
- %MSYS2%\mingw32\bin\libiconv-2.dll
- %MSYS2%\mingw32\bin\libintl-8.dll
- %MSYS2%\mingw32\bin\libglib-2.0-0.dll
- %MSYS2%\mingw32\bin\libgcc_s_dw2-1.dll
- %MSYS2%\mingw32\bin\libwinpthread-1.dll
To run sample_x86.exe on Windows 64-bit, you need the following files:
- unicorn.dll
- %MSYS2%\mingw64\bin\libiconv-2.dll
- %MSYS2%\mingw64\bin\libintl-8.dll
- %MSYS2%\mingw64\bin\libglib-2.0-0.dll
- %MSYS2%\mingw64\bin\libgcc_s_seh-1.dll
- %MSYS2%\mingw64\bin\libwinpthread-1.dll
2015-12-17 05:20:57 +00:00
[4] Compile and install from source on Cygwin
To build Unicorn on Cygwin, run:
$ ./make.sh
After compiling, install Unicorn with:
$ ./make.sh install
Resulted files cygunicorn.dll, libunicorn.dll.a and libunicorn.a can be
used on Cygwin but not native Windows.
NOTE: The core framework installed by "./make.sh install" consist of
following files:
/usr/include/unicorn/*.h
/usr/bin/cygunicorn.dll
/usr/lib/libunicorn.dll.a
/usr/lib/libunicorn.a
[5] Cross-compile for Windows from *nix
2015-08-21 07:04:50 +00:00
To cross-compile for Windows, Linux & gcc-mingw-w64-i686 (and also gcc-mingw-w64-x86-64
for 64-bit binaries) are required.
- To cross-compile Windows 32-bit binary, simply run:
2015-08-21 07:04:50 +00:00
$ ./make.sh cross-win32
2015-08-21 07:04:50 +00:00
- To cross-compile Windows 64-bit binary, run:
2015-08-21 07:04:50 +00:00
$ ./make.sh cross-win64
2015-08-21 07:04:50 +00:00
Resulted files unicorn.dll, unicorn.lib & samples/sample*.exe can then
2015-08-21 07:04:50 +00:00
be used on Windows machine.
To run sample_x86.exe on Windows 32-bit, you need the following files:
- unicorn.dll
- /usr/i686-w64-mingw32/sys-root/mingw/bin/libglib-2.0-0.dll
- /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll
- /usr/i686-w64-mingw32/lib/libwinpthread-1.dll
To run sample_x86.exe on Windows 64-bit, you need the following files:
- unicorn.dll
- /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libglib-2.0-0.dll
- /usr/lib/gcc/x86_64-w64-mingw32/4.8/libgcc_s_sjlj-1.dll
- /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll
Then run either "sample_x86.exe -32" or "sample_x86.exe -64" to test emulators for X86 32-bit or X86 64-bit.
For other architectures, run "sample_xxx.exe" found in the same directory.
2015-12-17 05:20:57 +00:00
[6] Cross-compile for iOS from Mac OSX.
2015-08-21 07:04:50 +00:00
2015-10-30 21:34:35 +00:00
To cross-compile for iOS (iPhone/iPad/iPod), Mac OSX with XCode installed is required.
2015-08-21 07:04:50 +00:00
- To cross-compile for ArmV7 (iPod 4, iPad 1/2/3, iPhone4, iPhone4S), run:
$ ./make.sh ios_armv7
2015-08-21 07:04:50 +00:00
- To cross-compile for ArmV7s (iPad 4, iPhone 5C, iPad mini), run:
$ ./make.sh ios_armv7s
2015-08-21 07:04:50 +00:00
- To cross-compile for Arm64 (iPhone 5S, iPad mini Retina, iPad Air), run:
$ ./make.sh ios_arm64
2015-08-21 07:04:50 +00:00
- To cross-compile for all iDevices (armv7 + armv7s + arm64), run:
$ ./make.sh ios
2015-08-21 07:04:50 +00:00
Resulted files libunicorn.dylib, libunicorn.a & tests/test* can then
be used on iOS devices.
2015-12-17 05:20:57 +00:00
[7] Cross-compile for Android
2015-08-21 07:04:50 +00:00
To cross-compile for Android (smartphone/tablet), Android NDK is required.
NOTE: Only ARM and ARM64 are currently supported.
$ NDK=/android/android-ndk-r10e ./make.sh cross-android arm
2015-08-21 07:04:50 +00:00
or
$ NDK=/android/android-ndk-r10e ./make.sh cross-android arm64
2015-08-21 07:04:50 +00:00
Resulted files libunicorn.so, libunicorn.a & tests/test* can then
be used on Android devices.
2015-12-17 05:20:57 +00:00
[8] By default, "cc" (default C compiler on the system) is used as compiler.
2015-08-21 07:04:50 +00:00
- To use "clang" compiler instead, run the command below:
2015-08-21 07:04:50 +00:00
$ ./make.sh clang
2015-08-21 07:04:50 +00:00
- To use "gcc" compiler instead, run:
2015-08-21 07:04:50 +00:00
$ ./make.sh gcc
2015-08-21 07:04:50 +00:00
2015-12-17 05:20:57 +00:00
[9] To uninstall Unicorn, run the command below:
2015-08-21 07:04:50 +00:00
$ sudo ./make.sh uninstall
2015-08-21 07:04:50 +00:00
2015-12-17 05:20:57 +00:00
[10] Language bindings
2015-08-21 07:04:50 +00:00
Look for the bindings under directory bindings/, and refer to README file
of corresponding languages.
2015-10-15 08:05:30 +00:00
2015-12-17 05:20:57 +00:00
[11] Unit tests
Automated unit tests use the cmocka unit testing framework (https://cmocka.org/).
It can be installed in most Linux distros using the package manager, e.g.
`sudo yum install libcmocka libcmocka-devel`, or you can easily build and install it from source.
2015-10-30 21:34:35 +00:00
You can run the tests by running `make test` in the project directory.