Sync docs from wiki and remove cmake.sh
This commit is contained in:
108
docs/COMPILE.md
108
docs/COMPILE.md
@ -1,55 +1,56 @@
|
||||
This HOWTO introduces how to build Unicorn2 natively on Linux/Mac/Windows,
|
||||
or cross-build to Windows from Linux host.
|
||||
This HOWTO introduces how to build Unicorn2 natively on Linux/Mac/Windows or cross-build to Windows from Linux host.
|
||||
|
||||
---
|
||||
### Native build on Linux/MacOS
|
||||
## Native build on Linux/macOS
|
||||
|
||||
This builds Unicorn2 on Linux/MacOS. The output is `libunicorn.so` or `libunicorn.dylib`, respectively.
|
||||
This builds Unicorn2 on Linux/macOS. Note that this also applies to Apple Silicon M1 users.
|
||||
|
||||
- Require `cmake` & `pkg-config` packages (besides `gcc`/`clang` compiler):
|
||||
- Install `cmake` and `pkg-config` with your favorite package manager:
|
||||
|
||||
```
|
||||
Ubuntu:
|
||||
|
||||
``` bash
|
||||
$ sudo apt install cmake pkg-config
|
||||
```
|
||||
|
||||
macOS:
|
||||
|
||||
```bash
|
||||
$ brew install cmake pkg-config
|
||||
```
|
||||
|
||||
- Build with the following commands.
|
||||
|
||||
```
|
||||
```bash
|
||||
$ mkdir build; cd build
|
||||
$ ../cmake.sh
|
||||
$ cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
$ make
|
||||
```
|
||||
|
||||
Then run the sample `sample_riscv` with:
|
||||
|
||||
```
|
||||
$ ./sample_riscv
|
||||
```
|
||||
|
||||
---
|
||||
### Native build on Windows, with MSVC
|
||||
|
||||
This builds Unicorn2 on Windows, using Microsoft MSVC compiler. The output is `unicorn.dll`.
|
||||
This builds Unicorn2 on Windows, using Microsoft MSVC compiler.
|
||||
|
||||
- Require `cmake` & `Microsoft Visual Studio`.
|
||||
|
||||
- From Visual Studio Command Prompt, build with the following commands.
|
||||
|
||||
```bash
|
||||
mkdir build; cd build
|
||||
cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
|
||||
nmake
|
||||
```
|
||||
|
||||
Note, other generators like `Ninja` and `Visual Studio 16 2019` would also work.
|
||||
|
||||
```
|
||||
mkdir build; cd build
|
||||
../nmake.sh
|
||||
cmake .. -G "Visual Studio 16 2019" -A "win32" -DCMAKE_BUILD_TYPE=Release
|
||||
msbuild unicorn.sln -p:Plaform=Win32 -p:Configuration=Release
|
||||
```
|
||||
|
||||
Then run the sample `sample_riscv` with:
|
||||
|
||||
```
|
||||
sample_riscv.exe
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Cross build from Linux host to Windows, with Mingw
|
||||
|
||||
This cross-builds Unicorn2 from **Linux host** to Windows, using `Mingw` compiler. The output is `libunicorn.dll`
|
||||
This cross-builds Unicorn2 from **Linux host** to Windows, using `Mingw` compiler.
|
||||
|
||||
- Install required package.
|
||||
|
||||
@ -61,31 +62,17 @@ $ sudo apt install mingw-w64-x86-64-dev
|
||||
|
||||
```
|
||||
$ mkdir build; cd build
|
||||
$ ../cmake.sh mingw
|
||||
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../mingw64-w64.cmake
|
||||
$ make
|
||||
```
|
||||
|
||||
The resulted `sample_riscv.exe` can be run with `libunicorn.dll`, and some dependecies DLLs
|
||||
already provided in `bin/` directory.
|
||||
|
||||
To prepare for `sample_riscv.exe`, do:
|
||||
|
||||
```
|
||||
cp libunicorn.dll ../bin
|
||||
cp sample_riscv.exe ../bin
|
||||
```
|
||||
|
||||
Then inside the `bin/` directory, you can run `sample_riscv.exe` (from `CMD.exe` prompt, for example)
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Native build on Windows host, with MSYS2/Mingw
|
||||
|
||||
This builds Unicorn2 on **Windows host**, using **MSYS2/Mingw** compiler. The output is `libunicorn.dll`
|
||||
This builds Unicorn2 on **Windows host**, using **MSYS2/Mingw** compiler.
|
||||
|
||||
This requires MSYS2 to be installed on Windows machine. You need to download & install MSYS2 from https://www.msys2.org.
|
||||
This requires MSYS2 to be installed on the Windows machine. You need to download & install MSYS2 from https://www.msys2.org.
|
||||
|
||||
Then from MSYS2 console, install required packages:
|
||||
Then from MSYS2 console, install packages below:
|
||||
|
||||
```
|
||||
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
|
||||
@ -95,37 +82,26 @@ pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
|
||||
|
||||
```
|
||||
mkdir build; cd build
|
||||
../cmake.sh msys
|
||||
/mingw64/bin/cmake .. -G "MSYS Makefiles" -DCMAKE_C_COMPILER=/mingw64/bin/gcc.exe -DCMAKE_MAKE_PROGRAM=/mingw64/bin/mingw32-make.exe -DCMAKE_AR=/mingw64/bin/ar.exe -DUNICORN_ARCH=x86
|
||||
mingw32-make
|
||||
```
|
||||
|
||||
The resulted `sample_riscv.exe` can be run with `libunicorn.dll`, and some dependecies DLLs
|
||||
already provided in `bin/` directory.
|
||||
Note that the way to build on MSYS changes as time goes, please keep in mind that always use the cmake shipped with mingw64 and choose MSYS Makefiles.
|
||||
|
||||
To prepare for `sample_riscv.exe`, do:
|
||||
### Cross build from Linux host to other architectures
|
||||
|
||||
```
|
||||
cp libunicorn.dll ../bin
|
||||
cp sample_riscv.exe ../bin
|
||||
```
|
||||
This cross-builds Unicorn2 from **Linux host** to other architectures, using a cross compiler.
|
||||
|
||||
Then inside the `bin/` directory, you can run `sample_riscv.exe` (from `CMD.exe` prompt, for example)
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Cross build from Linux host to other arch
|
||||
|
||||
This cross-builds Unicorn2 from **Linux host** to other arch, using cross compiler. The output is `libunicorn.so`
|
||||
|
||||
- Install cross compiler package. For example, cross compile to ARM require below command.
|
||||
- Install cross compiler package. For example, cross-compile to ARM requires the below command.
|
||||
|
||||
```
|
||||
$ sudo apt install gcc-arm-linux-gnueabihf
|
||||
```
|
||||
|
||||
- Build Unicorn and samples with the following commands (note that you need to specify compiler with CC).
|
||||
- Build Unicorn and samples with the following commands. The compiler name differs according to your targets.
|
||||
|
||||
```
|
||||
$ mkdir build; cd build
|
||||
$ CC=arm-linux-gnueabihf-gcc ../cmake.sh
|
||||
$ cmake .. -DCMAKE_C_COMPILER=gcc-arm-linux-gnueabihf
|
||||
$ make
|
||||
```
|
||||
|
Reference in New Issue
Block a user