From 61c68666d622bddf1c8964cb3160ce5d0198af74 Mon Sep 17 00:00:00 2001 From: David Chavez Date: Tue, 2 Aug 2022 16:22:20 +0200 Subject: [PATCH] Closer align Makefiles & Dockerfiles (#748) --- .ci/switch/buildswitch.bash | 11 --- BUILDING.md | 7 -- Dockerfile | 81 +++++++++++-------- Dockerfile.switch | 58 ------------- Jenkinsfile | 19 +++-- ZAPDTR/Makefile | 18 +++-- libultraship/Makefile | 7 +- .../linux/build-appimage.sh | 2 +- scripts/linux/build.sh | 11 +++ {appimage => scripts/linux}/soh.desktop | 0 {appimage => scripts/linux}/soh.sh | 0 scripts/switch/build.sh | 4 + soh/Makefile | 69 +++++++--------- soh/include/z64.h | 2 +- .../Enhancements/debugger/debugSaveEditor.cpp | 2 +- 15 files changed, 116 insertions(+), 175 deletions(-) delete mode 100755 .ci/switch/buildswitch.bash delete mode 100644 Dockerfile.switch rename appimage/appimage.sh => scripts/linux/build-appimage.sh (96%) create mode 100755 scripts/linux/build.sh rename {appimage => scripts/linux}/soh.desktop (100%) rename {appimage => scripts/linux}/soh.sh (100%) create mode 100755 scripts/switch/build.sh diff --git a/.ci/switch/buildswitch.bash b/.ci/switch/buildswitch.bash deleted file mode 100755 index 032b19157..000000000 --- a/.ci/switch/buildswitch.bash +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -cp -av /usr/local/lib/libSDL2* /lib/x86_64-linux-gnu/ -git config --global --add safe.directory /soh -make setup -C soh -j$(nproc) OPTFLAGS=-O2 DEBUG=0 CC="gcc" CXX="g++" - -/opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -B StormLib/build-switch -S StormLib -DCMAKE_INSTALL_PREFIX=/opt/devkitpro/portlibs/switch/ -make -C StormLib/build-switch -j$(nproc) -make install -C StormLib/build-switch - -make -f Makefile.switch -j$(nproc) OPTFLAGS=-O2 DEBUG=0 diff --git a/BUILDING.md b/BUILDING.md index 70ddd16b4..2a52e3f58 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -32,13 +32,6 @@ sudo docker run --rm -it -v $(pwd):/soh soh /bin/bash ``` Inside the Docker container: ```bash -# Clone and build StormLib -git clone https://github.com/ladislav-zezula/StormLib external/StormLib -cmake -B external/StormLib/build -S external/StormLib -cmake --build external/StormLib/build -cp external/StormLib/build/libstorm.a external -cp /usr/local/lib/libGLEW.a external - cd soh # Extract the assets/Compile the exporter/Run the exporter make setup -j$(nproc) OPTFLAGS=-O2 DEBUG=0 diff --git a/Dockerfile b/Dockerfile index 279674229..bf7d49ad5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,45 +3,56 @@ FROM ubuntu:20.04 as build ENV LANG C.UTF-8 ARG DEBIAN_FRONTEND=noninteractive +ENV GCCVER=10 RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y \ - binutils \ - gcc-10 \ - g++-10 \ - patchelf \ - p7zip-full \ - python3.9 \ - make \ - cmake \ - curl \ - git \ - lld \ - libsdl2-dev \ - zlib1g-dev \ - libbz2-dev \ - libpng-dev \ - libgles2-mesa-dev && \ - ln -s /usr/bin/g++-10 /usr/bin/g++ && \ - update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 && \ - gcc --version && \ - g++ --version - -RUN apt-get clean autoclean && apt-get autoremove --yes && rm -rf /var/lib/apt /var/lib/cache /var/lib/log - + apt-get upgrade -y && \ + apt-get install -y \ + binutils \ + gcc-${GCCVER} \ + g++-${GCCVER} \ + p7zip-full \ + python3 \ + make \ + cmake \ + curl \ + git \ + lld \ + wget \ + libglew-dev \ + libsdl2-dev \ + zlib1g-dev \ + libbz2-dev \ + libpng-dev \ + libgles2-mesa-dev && \ + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCCVER} 10 && \ + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${GCCVER} 10 + RUN git clone https://github.com/Perlmint/glew-cmake.git && \ - cmake glew-cmake && \ - make -j$(nproc) && \ - make install - + cmake glew-cmake && \ + make -j$(nproc) && \ + make install + ENV SDL2VER=2.0.22 RUN curl -sLO https://libsdl.org/release/SDL2-${SDL2VER}.tar.gz && \ - tar -xzf SDL2-${SDL2VER}.tar.gz && \ - cd SDL2-${SDL2VER} && \ - ./configure --prefix=/usr && \ - make && make install && \ - rm ../SDL2-${SDL2VER}.tar.gz && \ - cp -av /lib/libSDL* /lib/x86_64-linux-gnu/ + tar -xzf SDL2-${SDL2VER}.tar.gz && \ + cd SDL2-${SDL2VER} && \ + ./configure --build=x86_64-linux-gnu && \ + make -j$(nproc) && make install && \ + rm ../SDL2-${SDL2VER}.tar.gz + +RUN \ + ln -sf /proc/self/mounts /etc/mtab && \ + mkdir -p /usr/local/share/keyring/ && \ + wget -O /usr/local/share/keyring/devkitpro-pub.gpg https://apt.devkitpro.org/devkitpro-pub.gpg && \ + echo "deb [signed-by=/usr/local/share/keyring/devkitpro-pub.gpg] https://apt.devkitpro.org stable main" > /etc/apt/sources.list.d/devkitpro.list && \ + apt-get update -y && \ + apt-get install -y devkitpro-pacman && \ + yes | dkp-pacman -Syu switch-dev switch-portlibs --noconfirm + +ENV DEVKITPRO=/opt/devkitpro +ENV DEVKITARM=/opt/devkitpro/devkitARM +ENV DEVKITPPC=/opt/devkitpro/devkitPPC +ENV PATH=$PATH:/opt/devkitpro/portlibs/switch/bin/ RUN mkdir /soh WORKDIR /soh diff --git a/Dockerfile.switch b/Dockerfile.switch deleted file mode 100644 index 7319f22a6..000000000 --- a/Dockerfile.switch +++ /dev/null @@ -1,58 +0,0 @@ -FROM ubuntu:20.04 as build - -ENV LANG C.UTF-8 -ARG DEBIAN_FRONTEND=noninteractive - -ENV GCCVER=10 -RUN \ - apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y \ - binutils \ - gcc-10 \ - g++-10 \ - p7zip-full \ - python3 \ - make \ - cmake \ - curl \ - git \ - lld \ - wget \ - libsdl2-dev \ - zlib1g-dev \ - libbz2-dev \ - libpng-dev \ - libgles2-mesa-dev && \ - update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCCVER} 10 && \ - update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${GCCVER} 10 - -RUN git clone https://github.com/Perlmint/glew-cmake.git && \ - cmake glew-cmake && \ - make -j$(nproc) && \ - make install ARCH64=true - -ENV SDL2VER=2.0.22 -RUN curl -sLO https://libsdl.org/release/SDL2-${SDL2VER}.tar.gz && \ - tar -xzf SDL2-${SDL2VER}.tar.gz && \ - cd SDL2-${SDL2VER} && \ - ./configure --build=x86_64-linux-gnu && \ - make && make install && \ - rm ../SDL2-${SDL2VER}.tar.gz - -RUN \ - ln -sf /proc/self/mounts /etc/mtab && \ - mkdir -p /usr/local/share/keyring/ && \ - wget -O /usr/local/share/keyring/devkitpro-pub.gpg https://apt.devkitpro.org/devkitpro-pub.gpg && \ - echo "deb [signed-by=/usr/local/share/keyring/devkitpro-pub.gpg] https://apt.devkitpro.org stable main" > /etc/apt/sources.list.d/devkitpro.list && \ - apt-get update -y && \ - apt-get install -y devkitpro-pacman && \ - yes | dkp-pacman -Syu switch-dev switch-portlibs --noconfirm - -ENV DEVKITPRO=/opt/devkitpro -ENV DEVKITARM=/opt/devkitpro/devkitARM -ENV DEVKITPPC=/opt/devkitpro/devkitPPC -ENV PATH=$PATH:/opt/devkitpro/portlibs/switch/bin/ - -RUN mkdir /soh -WORKDIR /soh diff --git a/Jenkinsfile b/Jenkinsfile index 033f1f758..60f022253 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -97,8 +97,7 @@ pipeline { cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64 docker build . -t soh docker run --name sohcont -dit --rm -v $(pwd):/soh soh /bin/bash - cp ../../buildsoh.bash soh - docker exec sohcont soh/buildsoh.bash + docker exec sohcont scripts/linux/build.sh mkdir build mv soh/soh.elf build/ @@ -106,9 +105,9 @@ pipeline { mv OTRGui/build/assets build/ mv ZAPDTR/ZAPD.out build/assets/extractor/ mv README.md readme.txt - - docker exec sohcont appimage/appimage.sh - + + docker exec sohcont scripts/linux/build-appimage.sh + 7z a soh-linux.7z SOH-Linux.AppImage readme.txt ''' @@ -143,9 +142,9 @@ pipeline { sh ''' cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64 cd soh - make setup -j4 OPTFLAGS=-O2 DEBUG=0 LD="ld" - make -j4 DEBUG=0 OPTFLAGS=-O2 LD="ld" - make -j4 appbundle + make setup -j$(sysctl -n hw.physicalcpu) OPTFLAGS=-O2 DEBUG=0 LD="ld" + make -j$(sysctl -n hw.physicalcpu) DEBUG=0 OPTFLAGS=-O2 LD="ld" + make appbundle mv ../README.md readme.txt 7z a soh-mac.7z soh.app readme.txt ''' @@ -177,9 +176,9 @@ pipeline { sh ''' cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64 - docker build . -t sohswitch -f Dockerfile.switch + docker build . -t sohswitch docker run --name sohcont -dit --rm -v $(pwd):/soh sohswitch /bin/bash - docker exec sohcont .ci/switch/buildswitch.bash + docker exec sohcont scripts/switch/build.sh mv soh/soh.nro . mv README.md readme.txt diff --git a/ZAPDTR/Makefile b/ZAPDTR/Makefile index 6d8ba354d..660e0469c 100644 --- a/ZAPDTR/Makefile +++ b/ZAPDTR/Makefile @@ -48,11 +48,15 @@ endif LDFLAGS := -Llib/libgfxd -L../libultraship -L../StormLib/build \ -pthread -lgfxd -lultraship ZAPDUtils/ZAPDUtils.a -lstorm -lbz2 -lm -ldl +LDFLAGS += $(shell pkg-config --libs glew libpng zlib) $(shell sdl2-config --libs) +INC += $(shell pkg-config --cflags libpng) + ifeq ($(UNAME), Darwin) - LDFLAGS += $(shell pkg-config --libs glew libpng zlib) $(shell sdl2-config --libs) -framework OpenGL -framework Foundation - INC += $(shell pkg-config --cflags libpng) -else - LDFLAGS += -lpng -lGL -lGLEW -lX11 -lz -lSDL2 -lpulse + LDFLAGS += -framework OpenGL -framework Foundation +endif + +ifeq ($(UNAME), Linux) + LDFLAGS += $(shell pkg-config --libs x11 libpulse) endif # Use LLD if available. Set LLD=0 to not use it @@ -65,10 +69,12 @@ ifneq ($(LLD),0) endif UNAMEM := $(shell uname -m) -ifneq ($(UNAME), Darwin) +ifeq ($(UNAME), Linux) LDFLAGS += -Wl,-export-dynamic -lstdc++fs EXPORTERS := -Wl,--whole-archive ../OTRExporter/OTRExporter/OTRExporter.a -Wl,--no-whole-archive -else +endif + +ifeq ($(UNAME), Darwin) EXPORTERS := -Wl,-force_load ../OTRExporter/OTRExporter/OTRExporter.a endif diff --git a/libultraship/Makefile b/libultraship/Makefile index 37640969d..8369126f4 100644 --- a/libultraship/Makefile +++ b/libultraship/Makefile @@ -29,7 +29,6 @@ WARN := -Wall -Wextra -Werror \ -Wno-narrowing \ -Wno-missing-field-initializers \ -Wno-error=multichar \ - -Wno-unused-command-line-argument \ -Wno-delete-non-abstract-non-virtual-dtor \ -Wno-unused-private-field \ -Wno-deprecated-copy-with-user-provided-copy \ @@ -46,7 +45,7 @@ endif CXXFLAGS := $(WARN) $(CXXWARN) -std=c++20 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0 CFLAGS := $(WARN) $(CWARN) -std=c99 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0 -CPPFLAGS := -MMD +CPPFLAGS := -MMD $(shell pkg-config --cflags sdl2 glew) MMFLAGS := -Wno-deprecated-declarations -ObjC++ -fobjc-weak -fobjc-arc @@ -62,10 +61,6 @@ ifneq ($(CXX_IS_CLANG),1) MMFLAGS += -stdlib++-isystem ${STD_ISYSTEM} -cxx-isystem ${CXX_ISYSTEM} endif -ifeq ($(UNAME), Darwin) #APPLE - CPPFLAGS += $(shell pkg-config --cflags sdl2 glew) -framework OpenGL -framework Foundation -endif - ifneq ($(DEBUG),0) CXXFLAGS += -g -D_DEBUG CFLAGS += -g -D_DEBUG diff --git a/appimage/appimage.sh b/scripts/linux/build-appimage.sh similarity index 96% rename from appimage/appimage.sh rename to scripts/linux/build-appimage.sh index 7ac03934e..053ce580a 100755 --- a/appimage/appimage.sh +++ b/scripts/linux/build-appimage.sh @@ -6,7 +6,7 @@ curl -sSfL https://github.com$(curl https://github.com/probonopd/go-appimage/rel chmod a+x mkappimage.AppImage mkdir -p AppDir/usr/bin -cp appimage/{soh.desktop,soh.sh} AppDir/ +cp scripts/linux/{soh.desktop,soh.sh} AppDir/ cp soh/macosx/sohIcon.png AppDir/soh.png curl -sSfL https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt -o AppDir/usr/bin/gamecontrollerdb.txt diff --git a/scripts/linux/build.sh b/scripts/linux/build.sh new file mode 100755 index 000000000..f9d1f9e2c --- /dev/null +++ b/scripts/linux/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +cd soh +make setup -j$(nproc) OPTFLAGS=-O2 DEBUG=0 +make -j$(nproc) OPTFLAGS=-O2 DEBUG=0 + +cd ../OTRGui +mkdir build +cd build +cmake .. +cmake --build . --config Release diff --git a/appimage/soh.desktop b/scripts/linux/soh.desktop similarity index 100% rename from appimage/soh.desktop rename to scripts/linux/soh.desktop diff --git a/appimage/soh.sh b/scripts/linux/soh.sh similarity index 100% rename from appimage/soh.sh rename to scripts/linux/soh.sh diff --git a/scripts/switch/build.sh b/scripts/switch/build.sh new file mode 100755 index 000000000..e5d65d99d --- /dev/null +++ b/scripts/switch/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +make setup -C soh -j$(nproc) OPTFLAGS=-O2 DEBUG=0 +make -f Makefile.switch -j$(nproc) diff --git a/soh/Makefile b/soh/Makefile index 2c0f9ff31..24b3c9e8b 100644 --- a/soh/Makefile +++ b/soh/Makefile @@ -16,26 +16,35 @@ DEBUG ?= 1 OPTFLAGS ?= -O0 LTO ?= 0 +# flag to save whether the compiler being used is clang or gcc by checking CXX --version +CXX_IS_CLANG ?= $(shell $(CXX) --version | grep -c clang) + WARN := \ -Wno-return-type \ - -Wno-unused-command-line-argument \ - -Wno-implicit-function-declaration \ - -Wno-c++11-narrowing \ -funsigned-char \ -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-strict-aliasing -fno-inline-functions -fno-inline-small-functions -ffreestanding -fwrapv \ -CXXFLAGS := $(WARN) -std=c++20 -D_GNU_SOURCE -fpermissive -no-pie -nostdlib -CFLAGS := $(WARN) -std=c99 -D_GNU_SOURCE -no-pie -nostdlib -LDFLAGS := - -ifeq ($(UNAME), Linux) #LINUX - CXXFLAGS += -mhard-float -msse2 -mfpmath=sse - CFLAGS += -mhard-float -msse2 -mfpmath=sse +ifeq ($(CXX_IS_CLANG),1) + WARN += -Wno-c++11-narrowing endif -ifeq ($(UNAME), Darwin) #APPLE - CXXFLAGS += $(shell pkg-config --cflags sdl2) $(shell sdl2-config --cflags) $(shell pkg-config --cflags glew) -framework OpenGL - CFLAGS += $(shell pkg-config --cflags sdl2) $(shell sdl2-config --cflags) $(shell pkg-config --cflags glew) -framework OpenGL +CXXFLAGS := $(WARN) -std=c++20 -D_GNU_SOURCE -fpermissive -nostdlib $(shell pkg-config --cflags glew) $(shell sdl2-config --cflags) +CFLAGS := $(WARN) -std=c99 -Wno-implicit-function-declaration -D_GNU_SOURCE -nostdlib $(shell pkg-config --cflags glew) $(shell sdl2-config --cflags) +LDFLAGS := + +ifneq ($(CXX_IS_CLANG),1) + CXXFLAGS += -no-pie + CFLAGS += -no-pie +endif + +ifeq ($(UNAME), Linux) + ifeq ($(UNAMEM), x86_64) + CXXFLAGS += -msse2 -mfpmath=sse -mhard-float + CFLAGS += -msse2 -mfpmath=sse -mhard-float + endif + + CXXFLAGS += $(shell pkg-config --cflags libpulse) + CFLAGS += $(shell pkg-config --cflags libpulse) endif CPPFLAGS := -MMD @@ -57,11 +66,11 @@ ifneq ($(LTO),0) LDFLAGS += -flto endif -ifeq ($(UNAME), Linux) #LINUX +ifeq ($(UNAME), Linux) TARGET := soh.elf endif -ifeq ($(UNAME), Darwin) #APPLE +ifeq ($(UNAME), Darwin) TARGET := soh-$(UNAMEM) endif @@ -78,25 +87,15 @@ INC_DIRS := $(addprefix -I, \ ../libultraship/libultraship/Lib/Fast3D/U64/PR \ ) -ifeq ($(UNAME), Linux) #LINUX - INC_DIRS += $(addprefix -I, \ - /opt/X11/include \ -) -endif - LDDIRS := $(addprefix -L, \ ../libultraship/ \ ) -ifeq ($(UNAME), Linux) #LINUX - LDDIRS += $(addprefix -L, \ - /opt/X11/lib \ -) -endif - LDLIBS := \ $(ZAPDUTILS) \ $(LIBSTORM) \ + $(shell sdl2-config --libs) \ + $(shell pkg-config --libs glew) \ $(addprefix -l, \ dl \ bz2 \ @@ -105,24 +104,16 @@ LDLIBS := \ ultraship \ ) -ifeq ($(UNAME), Linux) #LINUX -LDLIBS += \ - $(addprefix -l, \ - X11 \ - SDL2 \ - GL \ - GLEW \ - pulse \ -) +ifeq ($(UNAME), Linux) +LDLIBS += $(shell pkg-config --libs x11 libpulse) endif -ifeq ($(UNAME), Darwin) #APPLE +ifeq ($(UNAME), Darwin) LDLIBS += \ $(addprefix -framework , \ OpenGL \ Foundation \ -) \ - $(shell sdl2-config --libs) $(shell pkg-config --libs glew) +) endif ASSET_BIN_DIRS := $(shell find assets/* -type d -not -path "assets/xml*") diff --git a/soh/include/z64.h b/soh/include/z64.h index 94d8b280e..d9570ae5e 100644 --- a/soh/include/z64.h +++ b/soh/include/z64.h @@ -30,7 +30,7 @@ #include "ichain.h" #include "regs.h" -#if defined(_WIN64) || defined(__x86_64__) || defined(__arm64__) +#if defined(__LP64__) #define _SOH64 #endif diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp index 513776b2a..48c9c4695 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -1001,7 +1001,7 @@ void DrawFlagsTab() { // Draws a combo that lets you choose and upgrade value from a drop-down of text values void DrawUpgrade(const std::string& categoryName, int32_t categoryId, const std::vector& names) { - ImGui::Text(categoryName.c_str()); + ImGui::Text("%s", categoryName.c_str()); ImGui::SameLine(); ImGui::PushID(categoryName.c_str()); if (ImGui::BeginCombo("##upgrade", names[CUR_UPG_VALUE(categoryId)].c_str())) {