Improve Build System + Use GCC (Clang Is Just Too Broken)

This commit is contained in:
TheBrokenRail 2022-03-06 15:53:27 -05:00
parent 4a69d38e35
commit c6983ac6c5
9 changed files with 113 additions and 220 deletions

View File

@ -25,14 +25,6 @@ else()
message(FATAL_ERROR "Invalid Mode") message(FATAL_ERROR "Invalid Mode")
endif() endif()
# Use Clang By Default
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "clang")
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER "clang++")
endif()
# Utility Functions # Utility Functions
include(cmake/util.cmake) include(cmake/util.cmake)

View File

@ -1,122 +1,9 @@
# Sanity Check Return
function(sanity_check_return ret)
if(NOT ret EQUAL "0")
message(FATAL_ERROR "Process Failed")
endif()
endfunction()
# Get Host Architecture
find_program(UNAME uname /bin /usr/bin /usr/local/bin REQUIRED)
execute_process(
COMMAND "${UNAME}" "-m"
OUTPUT_VARIABLE HOST_ARCHITECTURE
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE ret
)
sanity_check_return("${ret}")
# Get Include Directories
function(get_include_dirs target compiler result)
# Get Tool Name
set(tool "cc1")
if(compiler MATCHES "^.*g\\+\\+$")
set(tool "cc1plus")
endif()
# Get Tool Path
execute_process(
COMMAND "${compiler}" "-print-prog-name=${tool}"
ERROR_QUIET
OUTPUT_VARIABLE tool
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE ret
)
sanity_check_return("${ret}")
# Run Tool To Get Include Path
set(tool_output "")
execute_process(
COMMAND "${tool}" "-quiet" "-v" "-imultiarch" "${target}"
OUTPUT_QUIET
ERROR_VARIABLE tool_output
ERROR_STRIP_TRAILING_WHITESPACE
INPUT_FILE "/dev/null"
RESULT_VARIABLE ret
)
sanity_check_return("${ret}")
string(REPLACE "\n" ";" tool_output "${tool_output}")
# Loop
set(parsing_include_section FALSE)
foreach(line IN LISTS tool_output)
# Check Include Section Status
if(parsing_include_section)
# Check If Include Section Is Over
if(line MATCHES "^End of search list.$")
# Starting Include Section
set(parsing_include_section FALSE)
break()
else()
# Parsing Include Section
if(line MATCHES "^ .*$")
# Strip Line
string(STRIP "${line}" line)
# Add To List
list(APPEND "${result}" "${line}")
endif()
endif()
else()
# Check If Include Section Is Starting
if(line MATCHES "^#include <\\.\\.\\.> search starts here:$")
# Starting Include Section
set(parsing_include_section TRUE)
endif()
endif()
endforeach()
# Return
set("${result}" "${${result}}" PARENT_SCOPE)
endfunction()
# Setup Include Directories
function(setup_include_dirs compiler target result)
# Get Full Compiler
set(full_compiler "${target}-${compiler}")
# Get Include Directories
set(include_dirs "")
get_include_dirs("${target}" "${full_compiler}" include_dirs)
# Loop
set(flags "")
foreach(include_dir IN LISTS include_dirs)
set(flags "${flags} -isystem ${include_dir}")
endforeach()
# Return
set("${result}" "${${result}} ${flags}" PARENT_SCOPE)
endfunction()
# Setup Toolchain # Setup Toolchain
macro(setup_toolchain target) macro(setup_toolchain target)
# Use ARM Cross-Compiler # Use ARM Cross-Compiler
set(CMAKE_C_COMPILER "clang") set(CMAKE_C_COMPILER "${target}-gcc")
set(CMAKE_C_COMPILER_TARGET "${target}") set(CMAKE_CXX_COMPILER "${target}-g++")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_COMPILER_TARGET "${target}")
set(CMAKE_FIND_ROOT_PATH "/usr/${target}" "/usr/lib/${target}") set(CMAKE_FIND_ROOT_PATH "/usr/${target}" "/usr/lib/${target}")
# Flags
string(CONCAT NEW_FLAGS
"-nostdinc "
"-nostdinc++ "
"-Wno-unused-command-line-argument"
)
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ${NEW_FLAGS}")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ${NEW_FLAGS}")
# Include Directories
setup_include_dirs("gcc" "${target}" CMAKE_C_FLAGS_INIT)
setup_include_dirs("g++" "${target}" CMAKE_CXX_FLAGS_INIT)
# Extra # Extra
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endmacro() endmacro()

View File

@ -1,23 +1,5 @@
# Building # Building
## Build Options
* ``MCPI_BUILD_MODE``
* ``arm``: Only Build ARM Components
* ``native``: Only Build Native Components
* ``both`` (Default): Build Both ARM And Native Components For ARM
* ``MCPI_SERVER_MODE``
* ``ON``: Enable Server Mode
* ``OFF`` (Default): Disable Server Mode
* ``MCPI_HEADLESS_MODE``
* ``ON`` (Default In Server Mode): Enable Headless Mode
* ``OFF`` (Default In Client Mode): Disable Headless Mode
* ``MCPI_USE_MEDIA_LAYER_PROXY``
* ``ON``: Enable The Media Layer Proxy
* ``OFF`` (Default): Disable The Media Layer Proxy
* ``MCPI_OPEN_SOURCE_ONLY``
* ``ON``: Only Install Open-Source Code (Will Result In Broken Install)
* ``OFF`` (Default): Install All Code
## Build Dependencies ## Build Dependencies
* Common * Common
* ARM Compiler * ARM Compiler
@ -40,37 +22,13 @@
* OpenAL * OpenAL
* Zenity * Zenity
## Two-Step Build ## Instructions
Use this when the host architecture is not ARM.
```sh ```sh
# Create Build Directory ./scripts/build.sh <client|server> <armhf|arm64|i686|amd64>
mkdir build && cd build
# Build ARM Components
mkdir arm && cd arm
cmake -DCMAKE_TOOLCHAIN_FILE=../../cmake/armhf-toolchain.cmake -DMCPI_BUILD_MODE=arm ../..
make -j$(nproc) && sudo make install
cd ../
# Build Native Components
mkdir native && cd native
cmake -DMCPI_BUILD_MODE=native ../..
make -j$(nproc) && sudo make install
cd ../../
``` ```
This will most likely not compile by itself. You will want to enable either server mode or the Media Layer Proxy. ### Custom CMake Arguments
## One-Step Build
Use this when the host architecture is ARM.
```sh ```sh
# Create Build Directory ./scripts/setup.sh <client|server> <armhf|arm64|i686|amd64> <Custom CMake Arguments>
mkdir build && cd build ./scripts/build.sh <client|server> <armhf|arm64|i686|amd64>
# Build
cmake ..
make -j$(nproc) && sudo make install
cd ../
``` ```

View File

@ -146,7 +146,7 @@ static SDLMod glfw_modifier_to_sdl_modifier(int mods) {
} }
// Pass Key Presses To SDL // Pass Key Presses To SDL
static void glfw_key(__attribute__((unused)) GLFWwindow *window, int key, int scancode, int action, __attribute__((unused)) int mods) { static void glfw_key(__attribute__((unused)) GLFWwindow *window, int key, int scancode, int action, int mods) {
if (is_interactable) { if (is_interactable) {
SDL_Event event; SDL_Event event;
int up = action == GLFW_RELEASE; int up = action == GLFW_RELEASE;

View File

@ -1,3 +1,5 @@
#include <errno.h>
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
#include <symbols/minecraft.h> #include <symbols/minecraft.h>
@ -59,6 +61,8 @@ void init_home() {
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop" unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
patch((void *) 0xe0ac, nop_patch); patch((void *) 0xe0ac, nop_patch);
char *binary_directory = get_binary_directory(); char *binary_directory = get_binary_directory();
chdir(binary_directory); if (chdir(binary_directory) != 0) {
ERR("Unable To Change Directory: %s", strerror(errno));
}
free(binary_directory); free(binary_directory);
} }

View File

@ -2,46 +2,27 @@
set -e set -e
# ARM Toolchain File
ARM_TOOLCHAIN_FILE="$(pwd)/cmake/armhf-toolchain.cmake"
# Build # Build
build() { build() {
# Find Toolchain # Use Build Dir
local toolchain_file="$(pwd)/cmake/$2-toolchain.cmake" if [ ! -d "build/${MODE}-${ARCH}" ]; then
if [ ! -f "${toolchain_file}" ]; then ./scripts/setup.sh "${MODE}" "${ARCH}"
echo "Invalid Architecture: $2" > /dev/stderr
exit 1
fi fi
cd "build/${MODE}-${ARCH}"
# Create Build Dir
rm -rf "build/$1-$2"
mkdir -p "build/$1-$2"
cd "build/$1-$2"
# Create Prefix # Create Prefix
local prefix="$(cd ../../; pwd)/out/$1-$2" local prefix="$(cd ../../; pwd)/out/${MODE}-${ARCH}"
rm -rf "${prefix}" rm -rf "${prefix}"
mkdir -p "${prefix}" mkdir -p "${prefix}"
# Prepare
local extra_arg='-DMCPI_USE_MEDIA_LAYER_PROXY=ON'
if [ "$1" = "server" ]; then
extra_arg='-DMCPI_SERVER_MODE=ON'
fi
# Build ARM Components # Build ARM Components
mkdir arm
cd arm cd arm
cmake -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=arm "${extra_arg}" ../../..
make -j$(nproc) make -j$(nproc)
make install DESTDIR="${prefix}" make install DESTDIR="${prefix}"
cd ../ cd ../
# Build Native Components # Build Native Components
mkdir native
cd native cd native
cmake -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native "${extra_arg}" ../../..
make -j$(nproc) make -j$(nproc)
make install DESTDIR="${prefix}" make install DESTDIR="${prefix}"
cd ../ cd ../
@ -52,24 +33,18 @@ build() {
# Build For ARM # Build For ARM
armhf_build() { armhf_build() {
# Create Build Dir # Use Build Dir
rm -rf "build/$1-armhf" if [ ! -d "build/${MODE}-armhf" ]; then
mkdir -p "build/$1-armhf" ./scripts/setup.sh "${MODE}" armhf
cd "build/$1-armhf" fi
cd "build/${MODE}-armhf"
# Create Prefix # Create Prefix
local prefix="$(cd ../../; pwd)/out/$1-armhf" local prefix="$(cd ../../; pwd)/out/${MODE}-armhf"
rm -rf "${prefix}" rm -rf "${prefix}"
mkdir -p "${prefix}" mkdir -p "${prefix}"
# Prepare
local server_mode='OFF'
if [ "$1" = "server" ]; then
server_mode='ON'
fi
# Build All Components # Build All Components
cmake -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=both -DMCPI_SERVER_MODE="${server_mode}" ../..
make -j$(nproc) make -j$(nproc)
make install DESTDIR="${prefix}" make install DESTDIR="${prefix}"
@ -77,15 +52,14 @@ armhf_build() {
cd ../../ cd ../../
} }
# Verify Mode # Variables
if [ "$1" != "client" ] && [ "$1" != "server" ]; then MODE="$1"
echo "Invalid Mode: $1" > /dev/stderr ARCH="$2"
exit 1 shift 2
fi
# Build # Build
if [ "$2" = "armhf" ]; then if [ "${ARCH}" = "armhf" ]; then
armhf_build "$1" armhf_build "${MODE}"
else else
build "$1" "$2" build "${MODE}" "${ARCH}"
fi fi

View File

@ -24,8 +24,6 @@ sudo apt-get install --no-install-recommends -y \
lsb-release \ lsb-release \
dpkg-dev \ dpkg-dev \
git \ git \
clang \
lld \
cmake \ cmake \
make \ make \
libglfw3 libglfw3-dev \ libglfw3 libglfw3-dev \

80
scripts/setup.sh Executable file
View File

@ -0,0 +1,80 @@
#!/bin/sh
set -e
# ARM Toolchain File
ARM_TOOLCHAIN_FILE="$(pwd)/cmake/armhf-toolchain.cmake"
# Setup
setup() {
# Find Toolchain
local toolchain_file="$(pwd)/cmake/${ARCH}-toolchain.cmake"
if [ ! -f "${toolchain_file}" ]; then
echo "Invalid Architecture: ${ARCH}" > /dev/stderr
exit 1
fi
# Create Build Dir
rm -rf "build/${MODE}-${ARCH}"
mkdir -p "build/${MODE}-${ARCH}"
cd "build/${MODE}-${ARCH}"
# Prepare
local extra_arg='-DMCPI_USE_MEDIA_LAYER_PROXY=ON'
if [ "${MODE}" = "server" ]; then
extra_arg='-DMCPI_SERVER_MODE=ON'
fi
# Build ARM Components
mkdir arm
cd arm
cmake -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=arm "${extra_arg}" "$@" ../../..
cd ../
# Build Native Components
mkdir native
cd native
cmake -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" -DMCPI_BUILD_MODE=native "${extra_arg}" "$@" ../../..
cd ../
# Exit
cd ../../
}
# Setup For ARM
armhf_setup() {
# Create Build Dir
rm -rf "build/${MODE}-armhf"
mkdir -p "build/${MODE}-armhf"
cd "build/${MODE}-armhf"
# Prepare
local server_mode='OFF'
if [ "${MODE}" = "server" ]; then
server_mode='ON'
fi
# Build All Components
cmake -DCMAKE_TOOLCHAIN_FILE="${ARM_TOOLCHAIN_FILE}" -DMCPI_BUILD_MODE=both -DMCPI_SERVER_MODE="${server_mode}" "$@" ../..
# Exit
cd ../../
}
# Variables
MODE="$1"
ARCH="$2"
shift 2
# Verify Mode
if [ "${MODE}" != "client" ] && [ "${MODE}" != "server" ]; then
echo "Invalid Mode: ${MODE}" > /dev/stderr
exit 1
fi
# Setup
if [ "${ARCH}" = "armhf" ]; then
armhf_setup "$@"
else
setup "$@"
fi

View File

@ -63,7 +63,7 @@ struct AABB {
}; };
struct LevelSettings { struct LevelSettings {
unsigned long seed; int32_t seed;
int32_t game_type; int32_t game_type;
}; };
@ -637,7 +637,7 @@ static AppPlatform_readAssetFile_t AppPlatform_readAssetFile = (AppPlatform_read
// Minecraft // Minecraft
typedef void (*Minecraft_selectLevel_t)(unsigned char *minecraft, std::string const& level_dir, std::string const& level_name, LevelSettings const& vsettings); typedef void (*Minecraft_selectLevel_t)(unsigned char *minecraft, std::string const& level_dir, std::string const& level_name, LevelSettings const& settings);
static Minecraft_selectLevel_t Minecraft_selectLevel = (Minecraft_selectLevel_t) 0x16f38; static Minecraft_selectLevel_t Minecraft_selectLevel = (Minecraft_selectLevel_t) 0x16f38;
// ExternalFileLevelStorageSource // ExternalFileLevelStorageSource