Skip to content

Instantly share code, notes, and snippets.

@Jj0YzL5nvJ
Last active June 11, 2023 09:37
Show Gist options
  • Save Jj0YzL5nvJ/5242753837eed35768e61c240f572ecd to your computer and use it in GitHub Desktop.
Save Jj0YzL5nvJ/5242753837eed35768e61c240f572ecd to your computer and use it in GitHub Desktop.
Script to build standalone mupen64plus from upstream for *nix systems as user space application
#!/usr/bin/env bash
set -e
unset CORE_VER
unset NO_ASM
unset POSTFIX
CORE_SHORT_NAME="libmupen64plus"
HOST_ARCH="$(uname -m)"
ENV_NAME="$(uname -s)"
if [[ ${ENV_NAME} == *"MINGW"* ]]; then
CORE_SHORT_NAME="mupen64plus"
EXT="dll"
elif [[ ${ENV_NAME} == *"Darwin"* ]]; then
EXT="dylib"
export CXXFLAGS="-stdlib=libc++"
export LDFLAGS="-mmacosx-version-min=$(sw_vers -productVersion | cut -f1-2 -d.)"
else
EXT="so"
CORE_VER=".2.0.0"
fi
CORE_NAME="${CORE_SHORT_NAME}.${EXT}${CORE_VER}"
if [[ -z ${CPU_TUNE} ]]; then
if [[ "${HOST_ARCH}" == "x86_64" ]]; then export CPU_TUNE="-mtune=core2"; fi
fi
if [[ -z ${CC} ]]; then export CC="gcc"; fi
if [[ -z ${CXX} ]]; then export CXX="g++"; fi
export ORIG="$(pwd)"
if [[ -z ${REBUILD} ]]; then REBUILD="0"; fi
if [[ ${REBUILD} -eq 0 ]]; then rm -rf src; fi
mkdir -p src
if [[ -z ${ONLINE} ]]; then ONLINE="1"; fi
if [[ -z ${BACKUP} ]]; then BACKUP="0"; fi
# export DATE="YYYY-MM-DD"
if [[ -z ${DATE} ]]; then DATE="$(LC_ALL=C date -I)"; fi
if [[ ${REBUILD} -eq 0 ]]; then
for MODULE in core ui-console audio-sdl input-sdl input-raphnetraw rsp-cxd4 rsp-hle rsp-z64 video-arachnoid video-glide64 video-glide64mk2 video-rice video-z64; do
PROJ="mupen64plus"
COMP="mupen64plus"
if [[ "${MODULE}" == "input-raphnetraw" ]]; then PROJ="raphnet"; fi
if [[ ${ONLINE} -eq 1 ]]; then
git clone https://github.com/${PROJ}/${COMP}-${MODULE}.git src/${COMP}-${MODULE}
if [[ ${BACKUP} -eq 1 ]]; then tar -I 'xz -9' -cvf "${ORIG}/${COMP}-${MODULE}_${DATE}.tar.xz" -C src/ "${COMP}-${MODULE}"; fi
else tar xvJf "${ORIG}/${COMP}-${MODULE}_${DATE}.tar.xz" -C src/; fi
done
if [[ ${ONLINE} -eq 1 ]]; then
curl -L -o mupen64plus-core_fix-indy_${DATE}.patch "https://github.com/Jj0YzL5nvJ/mupen64plus-core/commit/791fda23c62a23fc331682bf91861e4367dc46dc.patch"
curl -L -o mupen64plus-audio-sdl_36_${DATE}.patch "https://github.com/mupen64plus/mupen64plus-audio-sdl/pull/36.patch"
curl -L -o mupen64plus-video-glide64mk2_ae_${DATE}.patch "https://github.com/mupen64plus-ae/mupen64plus-video-glide64mk2/compare/2a03e0ba031f33bd9e670d2238e1066330cf5dad...7c2820bce658838af16e47f4161c0f777537c9ed.patch"
# simple64:a3b2ef90939d06c1b0b4568fcaa89ea269081033
curl -L -o parallel-rsp-standalone_smp64_${DATE}.patch "https://github.com/Themaister/parallel-rsp/compare/2a9e196da0726785a58f611ba0d22668d377375d...Jj0YzL5nvJ:ci-smp64.patch"
# simple64:9869fb10025a2f84518696bb9998d6551b42f45a
curl -L -o parallel-rsp-standalone_${DATE}.patch "https://github.com/Themaister/parallel-rsp/compare/2a9e196da0726785a58f611ba0d22668d377375d...Jj0YzL5nvJ:ci-m64p.patch"
# Backup only...
curl -L -o parallel-rdp-standalone_smp64_${DATE}.patch "https://github.com/Themaister/parallel-rdp-standalone/compare/8da2be35abbbf503a485993c717e4917a1560324...simple64:simple64.patch"
# simple64:17d16a664cf414a2f0c9df2c5d034d664764aa8e
curl -L -o parallel-rdp-standalone_${DATE}.patch "https://github.com/Themaister/parallel-rdp-standalone/compare/8da2be35abbbf503a485993c717e4917a1560324...Jj0YzL5nvJ:ci-m64p.patch"
# main:e35757d8a43a1d84cfe46a49f0f1cfeb6ceb6d21
curl -L -o simple64-audio-sdl2_${DATE}.patch "https://github.com/simple64/simple64-audio-sdl2/compare/e35757d8a43a1d84cfe46a49f0f1cfeb6ceb6d21...Jj0YzL5nvJ:ci-smp64.patch"
# simple64:ee86bb54a8a6bda2ce5c7a03a86e8efab34258e5
git clone https://github.com/simple64/mupen64plus-core.git src/smp64_mupen64plus-core
git clone https://github.com/simple64/simple64-audio-sdl2.git src/simple64-audio-sdl2
git clone https://github.com/ata4/angrylion-rdp-plus.git src/angrylion-rdp-plus
git clone https://github.com/Themaister/parallel-rsp.git src/parallel-rsp
git clone https://github.com/Themaister/parallel-rdp-standalone.git src/parallel-rdp-standalone
git clone https://github.com/gonetz/GLideN64.git src/GLideN64
if [[ ${BACKUP} -eq 1 ]]; then
tar -I 'xz -9' -cvf "${ORIG}/simple64_mupen64plus-core_${DATE}.tar.xz" -C src/ "smp64_mupen64plus-core"
tar -I 'xz -9' -cvf "${ORIG}/simple64-audio-sdl2_${DATE}.tar.xz" -C src/ "simple64-audio-sdl2"
tar -I 'xz -9' -cvf "${ORIG}/angrylion-rdp-plus_${DATE}.tar.xz" -C src/ "angrylion-rdp-plus"
tar -I 'xz -9' -cvf "${ORIG}/parallel-rsp_${DATE}.tar.xz" -C src/ "parallel-rsp"
tar -I 'xz -9' -cvf "${ORIG}/parallel-rdp-standalone_${DATE}.tar.xz" -C src/ "parallel-rdp-standalone"
tar -I 'xz -9' -cvf "${ORIG}/GLideN64_${DATE}.tar.xz" -C src/ "GLideN64"
fi
else
tar xvJf "${ORIG}/simple64_mupen64plus-core_${DATE}.tar.xz" -C src/
tar xvJf "${ORIG}/simple64-audio-sdl2_${DATE}.tar.xz" -C src/
tar xvJf "${ORIG}/angrylion-rdp-plus_${DATE}.tar.xz" -C src/
tar xvJf "${ORIG}/parallel-rsp_${DATE}.tar.xz" -C src/
tar xvJf "${ORIG}/parallel-rdp-standalone_${DATE}.tar.xz" -C src/
tar xvJf "${ORIG}/GLideN64_${DATE}.tar.xz" -C src/
fi
fi
cd "${ORIG}/src/smp64_mupen64plus-core"
git checkout simple64
rm -rf CMakeLists.txt data
rm -rf src/device/r4300
rm -rf subprojects/xdelta
git reset --hard HEAD
MYOPT="../../tmp-core_smp64.patch"
echo "--- a/CMakeLists.txt" > ${MYOPT}
echo "+++ b/CMakeLists.txt" >> ${MYOPT}
echo "@@ -1,5 +1,4 @@" >> ${MYOPT}
echo " cmake_minimum_required(VERSION 3.22)" >> ${MYOPT}
echo "-set(CMAKE_OSX_DEPLOYMENT_TARGET \"11.0\")" >> ${MYOPT}
echo " " >> ${MYOPT}
echo " project(mupen64plus LANGUAGES C)" >> ${MYOPT}
echo " " >> ${MYOPT}
echo "@@ -126,15 +125,6 @@ endif ()" >> ${MYOPT}
echo " set_property(TARGET mupen64plus PROPERTY C_VISIBILITY_PRESET hidden)" >> ${MYOPT}
echo " set_property(TARGET mupen64plus PROPERTY CXX_VISIBILITY_PRESET hidden)" >> ${MYOPT}
echo " set_property(TARGET mupen64plus PROPERTY VISIBILITY_INLINES_HIDDEN ON)" >> ${MYOPT}
echo "-target_compile_options(mupen64plus PRIVATE -Ofast)" >> ${MYOPT}
echo "-target_link_options(mupen64plus PRIVATE -Ofast)" >> ${MYOPT}
echo "-if (CMAKE_SYSTEM_PROCESSOR STREQUAL \"aarch64\")" >> ${MYOPT}
echo "- target_compile_options(mupen64plus PRIVATE -march=armv8-a)" >> ${MYOPT}
echo "- target_link_options(mupen64plus PRIVATE -march=armv8-a)" >> ${MYOPT}
echo "-else()" >> ${MYOPT}
echo "- target_compile_options(mupen64plus PRIVATE -march=x86-64-v3)" >> ${MYOPT}
echo "- target_link_options(mupen64plus PRIVATE -march=x86-64-v3)" >> ${MYOPT}
echo "-endif()" >> ${MYOPT}
echo " if (NOT APPLE)" >> ${MYOPT}
echo " target_link_options(mupen64plus PRIVATE -Wl,-Bsymbolic -Wl,-Bsymbolic-functions)" >> ${MYOPT}
echo " endif (NOT APPLE)" >> ${MYOPT}
git apply ${MYOPT}
cd "${ORIG}/src/mupen64plus-core"
git checkout master
git reset --hard HEAD
git apply ../../mupen64plus-core_fix-indy_${DATE}.patch
export NEW_DYNAREC="1"
cd "${ORIG}/src/mupen64plus-audio-sdl"
git checkout master
git reset --hard HEAD
git apply ../../mupen64plus-audio-sdl_36_${DATE}.patch
cd "${ORIG}/src/simple64-audio-sdl2"
rm -rf .github
git checkout main
git reset --hard e35757d8a43a1d84cfe46a49f0f1cfeb6ceb6d21
git apply ../../simple64-audio-sdl2_${DATE}.patch
cd "${ORIG}/src/mupen64plus-video-glide64mk2"
rm -rf src/Neon
git checkout master
git reset --hard HEAD
git apply ../../mupen64plus-video-glide64mk2_ae_${DATE}.patch
MYFIX="../../tmp-glide64mk2_ae.patch"
echo "--- a/src/Glitch64/OGLESglitchmain.cpp" > ${MYFIX}
echo "+++ b/src/Glitch64/OGLESglitchmain.cpp" >> ${MYFIX}
echo "@@ -38,6 +38,7 @@" >> ${MYFIX}
echo " #include \"g3ext.h\"" >> ${MYFIX}
echo " #include \"glitchmain.h\"" >> ${MYFIX}
echo " #include \"m64p.h\"" >> ${MYFIX}
echo "+#include <deque>" >> ${MYFIX}
echo " " >> ${MYFIX}
echo " #define OPENGL_CHECK_ERRORS { const GLenum errcode = glGetError(); if (errcode != GL_NO_ERROR) LOG(\"OpenGL Error code %i in '%s' line %i\n\", errcode, __FILE__, __LINE__-1); }" >> ${MYFIX}
echo " " >> ${MYFIX}
echo "--- a/src/Glitch64/OGLglitchmain.cpp" >> ${MYFIX}
echo "+++ b/src/Glitch64/OGLglitchmain.cpp" >> ${MYFIX}
echo "@@ -38,6 +38,7 @@" >> ${MYFIX}
echo " #include \"g3ext.h\"" >> ${MYFIX}
echo " #include \"glitchmain.h\"" >> ${MYFIX}
echo " #include \"m64p.h\"" >> ${MYFIX}
echo "+#include <deque>" >> ${MYFIX}
echo " " >> ${MYFIX}
echo " #ifdef VPDEBUG" >> ${MYFIX}
echo " #include <IL/il.h>" >> ${MYFIX}
git apply ${MYFIX}
cd "${ORIG}/src/parallel-rsp"
rm -rf .github
rm -rf lightning-2.2.2
git checkout master
git reset --hard 2a9e196da0726785a58f611ba0d22668d377375d
git apply ../../parallel-rsp-standalone_${DATE}.patch
cd "${ORIG}/src/parallel-rdp-standalone"
rm -rf *.c *.cpp *.h *.txt .gitignore .github
git checkout master
git reset --hard 8da2be35abbbf503a485993c717e4917a1560324
git apply ../../parallel-rdp-standalone_${DATE}.patch
cd "${ORIG}"
rm -rf m64p-test
mkdir -p m64p-test
for TSK in core core core ui-console audio-sdl audio-sdl input-sdl input-raphnetraw rsp-cxd4 rsp-cxd4 rsp-hle rsp-z64 rsp-z64 video-arachnoid video-glide64 video-glide64mk2 video-glide64mk2 video-rice video-z64; do
export OPTFLAGS="-O2 -flto ${CPU_TUNE}"
if [[ "${SSE}" == "none" ]]; then export OPTFLAGS="-O2 -flto"; fi
COMP="mupen64plus"
cd "${ORIG}"
make -C src/${COMP}-${TSK}/projects/unix clean
make CC="${CC}" CXX="${CXX}" -C src/${COMP}-${TSK}/projects/unix all ${@}
make -C src/${COMP}-${TSK}/projects/unix install ${@} PLUGINDIR="" SHAREDIR="" BINDIR="" MANDIR="" LIBDIR="" APPSDIR="" ICONSDIR="icons" INCDIR="api" LDCONFIG="true" DESTDIR="${ORIG}/m64p-test/"
unset HLEVIDEO
unset NEW_DYNAREC
unset POSTFIX
unset SSE
if [[ "${TSK}" == "core" ]]; then
if [[ -f "./m64p-test/INDY-CORE.tar.gz" ]]; then
if ! [[ -f "./m64p-test/${CORE_SHORT_NAME}-old.${EXT}${CORE_VER}" ]]; then export POSTFIX="-old"; else tar cvzf "./m64p-test/MASTER-CORE.tar.gz" -C ./m64p-test/ "${CORE_NAME}" "${CORE_SHORT_NAME}-old.${EXT}${CORE_VER}" "mupen64plus.ini"; fi
else
tar cvzf "./m64p-test/INDY-CORE.tar.gz" -C ./m64p-test/ "${CORE_NAME}" "mupen64plus.ini"
cd "${ORIG}/src/mupen64plus-core"
git reset --hard HEAD
export NEW_DYNAREC="1"
fi
elif [[ "${TSK}" == "audio-sdl" ]]; then
if ! [[ -f "./m64p-test/mupen64plus-audio-sdl-test.${EXT}" ]]; then mv "./m64p-test/mupen64plus-audio-sdl.${EXT}" "./m64p-test/mupen64plus-audio-sdl-test.${EXT}"; fi
cd "${ORIG}/src/mupen64plus-audio-sdl"
git reset --hard HEAD
elif [[ "${TSK}" == "rsp-cxd4" ]]; then export SSE="none";
elif [[ "${TSK}" == "rsp-z64" ]]; then export HLEVIDEO="1";
elif [[ "${TSK}" == "video-glide64mk2" ]]; then
if ! [[ -f "./m64p-test/mupen64plus-video-glide64mk2-ae.${EXT}" ]]; then mv "./m64p-test/mupen64plus-video-glide64mk2.${EXT}" "./m64p-test/mupen64plus-video-glide64mk2-ae.${EXT}"; fi
cd "${ORIG}/src/mupen64plus-video-glide64mk2"
rm -rf src/Neon
git reset --hard HEAD
fi
done
cd "${ORIG}/src/smp64_mupen64plus-core"
rm -rf build
mkdir -p build/pkg
cd build
cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_C_FLAGS="${CPU_TUNE}" -DCMAKE_BUILD_TYPE="Release" ..
cmake --build . ${@}
cd pkg
cp ../*.${EXT} "./${CORE_NAME}"
cp ../../data/*.rom .
cp ../../data/*.ini .
chmod 644 *.*
tar cvzf "${ORIG}/m64p-test/SMP64-CORE.tar.gz" *.*
cd "${ORIG}/src/simple64-audio-sdl2"
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_C_FLAGS="${CPU_TUNE}" -DCMAKE_BUILD_TYPE="Release" ..
cmake --build . ${@}
chmod 644 *.${EXT}
cp *.${EXT} "${ORIG}/m64p-test/"
cd "${ORIG}/src/angrylion-rdp-plus"
set +e
git tag --delete nightly-build
set -e
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_C_FLAGS="${CPU_TUNE}" -DCMAKE_CXX_FLAGS="${CPU_TUNE}" -DCMAKE_BUILD_TYPE="Release" ..
cmake --build . ${@}
chmod 644 *.${EXT}
cp *.${EXT} "${ORIG}/m64p-test/"
cd "${ORIG}/src/parallel-rsp"
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_C_FLAGS="${CPU_TUNE}" -DCMAKE_CXX_FLAGS="${CPU_TUNE}" -DCMAKE_BUILD_TYPE="Release" ..
cmake --build . ${@}
chmod 644 *.${EXT}
cp *.${EXT} "${ORIG}/m64p-test/"
cd ..
rm -rf .github
git reset --hard HEAD
git apply ../../parallel-rsp-standalone_smp64_${DATE}.patch
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_C_FLAGS="${CPU_TUNE}" -DCMAKE_CXX_FLAGS="${CPU_TUNE}" -DCMAKE_BUILD_TYPE="Release" ..
cmake --build . ${@}
chmod 644 *.${EXT}
cp *.${EXT} "${ORIG}/m64p-test/"
cd "${ORIG}/src/parallel-rdp-standalone"
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_C_FLAGS="${CPU_TUNE}" -DCMAKE_CXX_FLAGS="${CPU_TUNE}" -DCMAKE_BUILD_TYPE="Release" ..
cmake --build . ${@}
chmod 644 *.${EXT}
cp *.${EXT} "${ORIG}/m64p-test/"
cd "${ORIG}/src/GLideN64"
rm -rf projects/cmake
git reset --hard HEAD
rm -rf src/GLideNHQ/inc
cd projects/cmake
cmake -DCMAKE_C_COMPILER="${CC}" -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_C_FLAGS="${CPU_TUNE}" -DCMAKE_CXX_FLAGS="${CPU_TUNE}" -DCMAKE_BUILD_TYPE="Release" -DUSE_SYSTEM_LIBS="ON" -DVEC4_OPT="ON" -DCRC_OPT="ON" -DMUPENPLUSAPI="ON" ../../src/
cmake --build . ${@}
cd plugin/Release
chmod 644 *.${EXT}
cp *.${EXT} "${ORIG}/m64p-test/"
cd ../../../../ini
chmod 644 *.ini
cp GLideN64.custom.ini "${ORIG}/m64p-test/"
MYSCRIPT="${ORIG}/m64p-test/m64pp"
echo "#!/usr/bin/env bash" > "${MYSCRIPT}"
echo "set -e" >> "${MYSCRIPT}"
echo "" >> "${MYSCRIPT}"
echo "ORIG=\`dirname \"\${0}\"\`" >> "${MYSCRIPT}"
echo "if [[ -z \${CORE_NAME} ]]; then CORE_NAME=\"${CORE_NAME}\"; fi" >> "${MYSCRIPT}"
echo "#mkdir -p \"\${ORIG}/screenshot\" \"\${ORIG}/save\" \"\${ORIG}/hires_texture\"" >> "${MYSCRIPT}"
echo "#PORTABLE=\"--corelib \${ORIG}/\${CORE_NAME} --plugindir \${ORIG} --datadir \${ORIG} --configdir \${ORIG} --sshotdir \${ORIG}/screenshot --set Core[SaveStatePath]=\${ORIG}/save --set Core[SaveSRAMPath]=\${ORIG}/save\"" >> "${MYSCRIPT}"
echo "SEMIPORTABLE=\"--corelib \${ORIG}/\${CORE_NAME} --plugindir \${ORIG} --datadir \${ORIG}\"" >> "${MYSCRIPT}"
echo "" >> "${MYSCRIPT}"
echo "# Utilities" >> "${MYSCRIPT}"
echo "#export LIBGL_SHOW_FPS=\"1\"" >> "${MYSCRIPT}"
echo "#export GALLIUM_HUD=\"cpu+GPU-load+fps\"" >> "${MYSCRIPT}"
echo "" >> "${MYSCRIPT}"
echo "# Troubleshooting" >> "${MYSCRIPT}"
echo "#export LIBGL_ALWAYS_SOFTWARE=\"1\"" >> "${MYSCRIPT}"
echo "#export MESA_GLSL_CACHE_DISABLE=\"1\"" >> "${MYSCRIPT}"
echo "#export MESA_GL_VERSION_OVERRIDE=\"3.3COMPAT\" MESA_GLSL_VERSION_OVERRIDE=\"330\" MESA_EXTENSION_OVERRIDE=\"-GL_ARB_buffer_storage\"" >> "${MYSCRIPT}"
echo "" >> "${MYSCRIPT}"
echo "#\${ORIG}/./mupen64plus \${PORTABLE} --set Video-GLideN64[txPath]=\${ORIG}/hires_texture \"\${@}\"" >> "${MYSCRIPT}"
echo "\${ORIG}/./mupen64plus \${SEMIPORTABLE} \"\${@}\"" >> "${MYSCRIPT}"
chmod 755 "${MYSCRIPT}"
@Martin31416
Copy link

Martin31416 commented Jul 23, 2022

Hi!

Nice work! I found your work from one or the issues you reported on the m64p page. It's exactly what I was looking for... A way to build m64p from the source code. Can I try it?

So far, the flatpak command does not work for me un Xubuntu 20.04 lts. Executing the build.sh script does not work neither, an error about the #Include line from a m64p-input-qt/main.cpp si raised. And trying to run m64p.exe with wine does not work neither.

@HybridDog
Copy link

HybridDog commented Dec 10, 2022

Thanks for publishing this script.
Unfortunately it no longer works for me. The patch application git apply ../../mupen64plus-core_smp64_${DATE}.patch fails:

HEAD is now at ba9a524 Merge pull request #980 from loganmc10/fix_netplay
../../mupen64plus-core_smp64_2022-12-10.patch:9766: trailing whitespace.
  
../../mupen64plus-core_smp64_2022-12-10.patch:9879: space before tab in indent.
 			    & stream->inst_sect.buf,
../../mupen64plus-core_smp64_2022-12-10.patch:10075: trailing whitespace.
	    
../../mupen64plus-core_smp64_2022-12-10.patch:10177: space before tab in indent.
 	dst = stream->next_out + stream->avail_out;
../../mupen64plus-core_smp64_2022-12-10.patch:10767: trailing whitespace.
	  
error: patch failed: src/main/main.h:58
error: src/main/main.h: patch does not apply
error: patch failed: src/main/rom.c:205
error: src/main/rom.c: patch does not apply
error: patch failed: src/main/savestates.c:101
error: src/main/savestates.c: patch does not apply
error: patch failed: src/main/rom.c:44
error: src/main/rom.c: patch does not apply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment