Add MSYS2 MinGW x64 Support (#108)

* Added MSYS2 MinGW x64 Support
* Updated recomp
* Updated tools
This commit is contained in:
MegaMech
2021-12-20 20:33:42 -07:00
committed by GitHub
parent cdb3ca63aa
commit 48a06f2fa5
15 changed files with 336 additions and 86 deletions
+66
View File
@@ -0,0 +1,66 @@
### These instructions are a WIP and may be missing steps
## Compiling mk64 Decomp In Windows
The extraneous and convoluted process to building mk64 decomp on Windows begins with disabling your anti-virus program or adding an exception to the mk64 decomp folder and/or the msys2 installation folder.
Please note that this action may impact the security of your system. Prior to proceeding, make sure to understand the increased security risks that may result from this step. Nobody except you, is responsible and liable for your system and its security.
### Preamble
Any misteps may require a complete uninstall of `MSYS2 MinGW x64` and restarting from the very beginning.
It is unknown if `MSYS MinGW x32` works.
### Step 1: Download MSYS2 MinGW x64
https://www.msys2.org/
Follow the initial instructions to update the base packages. Ignore installing any extra packages in-case they conflict with the below steps.
MinGW is a separate program from Msys2. However, it must be wrapped right into msys2.
Compiling recomp requires steps using `MSYS2 MSYS` *and* `MSYS2 MinGW x64`. The instructions will clearly differentiate which program to launch and run in the section titles.
##### Why flip-flop between both?
Compiling the recomp executable that generates the source files for compiling the compiler requires capstone. A disassembly, analysis, and reverse-engineering framework. Capstone is only available on `MSYS2 MinGW x64`. It is not available on `MSYS2 MSYS`. However, compiling the compiler itself requires `MSYS2 MSYS` because it contains an equivallent dependency for `mman`. A memory mapping library. `MSYS2 MinGW x64` does not contain an equivallent dependancy.
### Step 2: Install Dependancies in MSYS2 MinGW x64
```
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-capstone pkgconf make python3 git
```
### Step 3: Install Dependencies in MSYS2 MSYS
```
pacman -S gcc
```
### Step 4: Compile Binutils For mips and Install
Download and run: [get_bin.sh](get_bin.sh)
### Step 5: Compiling recomp.exe in `MSYS2 MinGW x64`
In `MSYS2 MinGW x64` run in `mk64/tools/ido5.3_recomp/`:
```
g++ recomp.cpp -o recomp -g -lcapstone -Dugen53
```
### Step 6: Compiling the recomp compiler in `MSYS2 MSYS`
In `MSYS2 MSYS` run:
```
make -C tools
```
If the make file is broken then manually compile each executable.
Generate C file in `mk64/tools/ido5.3_recomp/`:
```
./recomp ~/ido7.1_compiler/usr/lib/as1 > as1_c.c
```
Compile generated C file:
```
gcc libc_impl.c as1_c.c -o as1 -g -fno-strict-aliasing -lm -no-pie -DIDO53 -O2
```
`-O2` is an optional optimization flag.
mk64 requires the following: as1, cc, cfe, copt, ugen, ujoin, uld, umerge, uopt
### Step 7: Compile mk64 in `MSYS2 MinGW x64`
In `/mk64/` run:
```
make -j#
```
Replace # with your number of CPU cores for qucker compilation.
+81
View File
@@ -0,0 +1,81 @@
#!/bin/bash
# --- Useful Variables --- #
# This is the specific binutils version that will be downloaded
binutils=binutils-2.36
# Where the built files will end up.
# If this directory doesn't already exist it will be created automatically.
destFolder=./tools/binutils
# The temporary folder name to work from.
tempFolder=build_temp
# The prefix appended to the start of the built files.
prefix=mips64-elf-
# Folder names within the binutils directory.
binFolder=binutils
ldFolder=ld
gasFolder=gas
# How many threads to use with make (All of them)
threadCount=$(nproc --all)
# --- Useful Macros --- #
PRINT_STEP () {
echo "($1) ==== $2 ==== "
}
INSTALL_FILE() {
cp ./$tempFolder/$binutils/$2/$1 $destFolder/$prefix$1
echo "Installed mips64-elf-$1"
}
RENAME_AND_INSTALL_FILE() {
cp ./$tempFolder/$binutils/$2/$1 $destFolder/$prefix$3
echo "Installed mips64-elf-$3"
}
# --- Script --- #
# Make the destintation folder if it already doesn't exist.
mkdir -p $destFolder
# Having a temp folder makes things easy to cleanup
#rm -Rf $tempFolder # This will remove the temp folder if it exists for some reason.
mkdir $tempFolder
cd $tempFolder
PRINT_STEP 1 "DOWNLOADING BINUTILS FROM GNU.ORG"
wget ftp://ftp.gnu.org/gnu/binutils/$binutils.tar.xz
PRINT_STEP 2 "EXTRACTING TAR FILE"
tar -xf $binutils.tar.xz
PRINT_STEP 3 "CONFIGURING THE MAKEFILE"
cd $binutils
# Credit goes to queueRAM for letting me know what the correct arguments are.
./configure --target=mips64-elf --prefix=/usr --with-sysroot=/usr/mips64-elf --with-gnu-as --with-gnu-ld --enable-64-bit-bfd --enable-multilib --enable-plugins --disable-gold --disable-nls --disable-shared --disable-werror
PRINT_STEP 4 "MAKING BINUTILS"
make -j$threadCount
cd ../..
PRINT_STEP 5 "INSTALLING BUILT FILES"
# Add or remove programs here.
INSTALL_FILE ar $binFolder
INSTALL_FILE objcopy $binFolder
INSTALL_FILE objdump $binFolder
RENAME_AND_INSTALL_FILE as-new $gasFolder as
RENAME_AND_INSTALL_FILE ld-new $ldFolder ld
PRINT_STEP 6 "CLEANING UP"
#rm -Rf $tempFolder
PRINT_STEP - "DONE!"