#!/bin/bash # Use project-local GCC if available, otherwise system GCC TOOLCHAIN_GCC="./toolchain/gcc-15.2.0/bin/gcc" if [ -f "${TOOLCHAIN_GCC}" ]; then CC="${TOOLCHAIN_GCC}" else CC=gcc fi # Set the project name here PROJECT_NAME="mknes" # Change this for each new project WIN_CC=x86_64-w64-mingw32-gcc # Base configuration common to all builds CFLAGS="-std=gnu11 -mtune=generic " # -fdump-tree-alias " CFLAGS+="-falign-functions=32 -falign-loops=32 " CFLAGS+="-finline-limit=800 " CFLAGS+="-mbmi -fno-argument-alias " CFLAGS+="-mfunction-return=keep -mindirect-branch=keep " CFLAGS+="-fwrapv -ffast-math -fno-trapping-math -fvisibility=hidden " CFLAGS+="-fno-stack-protector -fno-PIE -no-pie -fcf-protection=none -ffunction-sections -fdata-sections " CFLAGS+="-fno-non-call-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables " CFLAGS+="-Wall -Wextra -Wstrict-aliasing=3 -Wstrict-overflow=5 " CFLAGS+="-Wno-unused-parameter -Wno-sign-compare -Wno-trigraphs -Wno-maybe-uninitialized " CFLAGS+="-Wno-unused-variable -Wno-unused-const-variable -Wno-unused-function -Wno-write-strings -Wno-missing-field-initializers " CFLAGS+="-U_FORTIFY_SOURCE -fno-pic " # Enable occationally to check for errors.. # CFLAGS+="-fanalyzer " LDFLAGS="-Wl,--gc-sections -Wl,--as-needed " # Base include paths (common for all platforms) INCLUDE_PATHS="-Ibase -I../mkfw " # Linux-specific includes and libraries LINUX_INCLUDE=" " LINUX_LIBS="-lXi -lX11 -lGL -lm -ldl -pthread -larchive -lSDL2" # Windows-specific includes and libraries WINDOWS_INCLUDE="" WINDOWS_LIBS="-lwinmm -lgdi32 -lopengl32 -lavrt " # To enable ZIP support via libarchive, uncomment the line below and comment the line above: # WINDOWS_LIBS="-static -larchive -lz -lbz2 -llzma -lbcrypt -lwinmm -lgdi32 -lopengl32" # You'll also need to add -DUSE_LIBARCHIVE to CFLAGS # Determine build type-specific flags BUILD_TYPE=$1 if [ -z "$BUILD_TYPE" ]; then BUILD_TYPE="normal" fi case "$BUILD_TYPE" in "normal") CFLAGS+="-ggdb -fno-omit-frame-pointer -O2 -DDEBUG_INTERNAL " # CFLAGS+="-fsanitize=address,undefined,alignment,object-size,unreachable " # -pg # for gprof ;; "release") CFLAGS+="-s -Wl,--strip-all -O2 " ;; "profile") CFLAGS+="-O2 -fprofile-generate -ftest-coverage -DBENCHMARK " ;; "profile_release") # CFLAGS+="-s -Wl,--strip-all -O2 -fprofile-use " CFLAGS+="-g -O2 -fprofile-use -DBENCHMARK " ;; "debug") CFLAGS+="-g -O0 " # -DTIMER_DEBUG " LDFLAGS+="-fno-pie -no-pie " ;; "coverage") gcov -b -c *.c exit 0 ;; "clean") rm -f *.gcda *.gcno *.gcov perf.data* *.alias mknes exit 0 ;; *) echo "Unknown build type: $BUILD_TYPE" exit 1 ;; esac # Make sure the compilation stops if any error happens. set -e # Build Linux version ( $CC $CFLAGS ${PROJECT_NAME}.c -o ${PROJECT_NAME} $INCLUDE_PATHS $LINUX_INCLUDE $LDFLAGS $LINUX_LIBS objdump -d -Mintel mknes > mknes.s ) & # Build Windows version #( # $WIN_CC $CFLAGS ${PROJECT_NAME}.c -o ${PROJECT_NAME}.exe $INCLUDE_PATHS $WINDOWS_INCLUDE $LDFLAGS $WINDOWS_LIBS #) & wait