Skip to content

Instantly share code, notes, and snippets.

@ceski-1
Last active February 24, 2021 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceski-1/b8867ff847cca1b55605098ad1b8428b to your computer and use it in GitHub Desktop.
Save ceski-1/b8867ff847cca1b55605098ad1b8428b to your computer and use it in GitHub Desktop.
Scripts for building PrBoom-Plus using MSYS2 (MinGW 32-bit)
# update environment
pacman -Syu --noconfirm
pacman -Su --noconfirm
pacman -S --needed --noconfirm git zip base-devel mingw-w64-i686-cmake mingw-w64-i686-toolchain \
--ignore=mingw-w64-i686-gcc-ada,mingw-w64-i686-gcc-fortran,mingw-w64-i686-gcc-libgfortran,mingw-w64-i686-gcc-objc \
mingw-w64-i686-SDL2 mingw-w64-i686-SDL2_net mingw-w64-i686-SDL2_image mingw-w64-i686-pcre \
mingw-w64-i686-SDL2_mixer mingw-w64-i686-fluidsynth mingw-w64-i686-portmidi mingw-w64-i686-libmad \
mingw-w64-i686-dumb mingw-w64-i686-libvorbis
pacman -Scc --noconfirm
# build prboom-plus
cd ~
git clone https://github.com/coelckers/prboom-plus
cd prboom-plus/prboom2
mkdir build
cd build
cmake .. -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
# prep release
cd ..
mkdir release
cp ./build/*.exe ./release/
cp ./build/*.wad ./release/
# collect .dlls
cd release
~/mingw-bundledlls --copy prboom-plus.exe
~/mingw-bundledlls --copy prboom-plus-game-server.exe
# remove symbols
strip *.exe
# create archive
zip -j -r ~/prboom-plus-$(date +"%Y%m%d")-win32.zip *
# done
cd ~
#!/usr/bin/env python3
# The MIT License (MIT)
#
# Copyright (c) 2015 Martin Preisler
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import subprocess
import os.path
import argparse
import shutil
# The mingw path matches where Fedora 21 installs mingw32; this is the default
# fallback if no other search path is specified in $MINGW_BUNDLEDLLS_SEARCH_PATH
DEFAULT_PATH_PREFIXES = ["C:/msys64/mingw32/bin"]
# ceski - changed path
env_path_prefixes = os.environ.get('MINGW_BUNDLEDLLS_SEARCH_PATH', None)
if env_path_prefixes is not None:
path_prefixes = [path for path in env_path_prefixes.split(os.pathsep) if path]
else:
path_prefixes = DEFAULT_PATH_PREFIXES
# This blacklist may need extending
blacklist = [
"advapi32.dll", "kernel32.dll", "msvcrt.dll", "ole32.dll", "user32.dll",
"ws2_32.dll", "comdlg32.dll", "gdi32.dll", "imm32.dll", "oleaut32.dll",
"shell32.dll", "winmm.dll", "winspool.drv", "wldap32.dll",
"ntdll.dll", "d3d9.dll", "mpr.dll", "crypt32.dll", "dnsapi.dll",
"shlwapi.dll", "version.dll", "iphlpapi.dll", "msimg32.dll", "setupapi.dll",
"opengl32.dll", "dwmapi.dll", "uxtheme.dll", "secur32.dll", "gdiplus.dll",
"usp10.dll", "comctl32.dll", "wsock32.dll", "netapi32.dll", "userenv.dll",
"avicap32.dll", "avrt.dll", "psapi.dll", "mswsock.dll", "glu32.dll",
"bcrypt.dll", "rpcrt4.dll", "dsound.dll"
]
# ceski - added "dsound.dll"
def find_full_path(filename, path_prefixes):
for path_prefix in path_prefixes:
path = os.path.join(path_prefix, filename)
path_low = os.path.join(path_prefix, filename.lower())
if os.path.exists(path):
return path
if os.path.exists(path_low):
return path_low
else:
raise RuntimeError(
"Can't find " + filename + ". If it is an inbuilt Windows DLL, "
"please add it to the blacklist variable in the script and send "
"a pull request!"
)
def gather_deps(path, path_prefixes, seen):
ret = [path]
output = subprocess.check_output(["objdump", "-p", path]).decode(
"utf-8", "replace").split("\n")
for line in output:
if not line.startswith("\tDLL Name: "):
continue
dep = line.split("DLL Name: ")[1].strip()
ldep = dep.lower()
if ldep in blacklist:
continue
if ldep in seen:
continue
dep_path = find_full_path(dep, path_prefixes)
seen.add(ldep)
subdeps = gather_deps(dep_path, path_prefixes, seen)
ret.extend(subdeps)
return ret
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"exe_file",
help="EXE or DLL file that you need to bundle dependencies for"
)
parser.add_argument(
"--copy",
action="store_true",
help="In addition to printing out the dependencies, also copy them next to the exe_file"
)
parser.add_argument(
"--upx",
action="store_true",
help="Only valid if --copy is provided. Run UPX on all the DLLs and EXE."
)
args = parser.parse_args()
if args.upx and not args.copy:
raise RuntimeError("Can't run UPX if --copy hasn't been provided.")
all_deps = set(gather_deps(args.exe_file, path_prefixes, set()))
all_deps.remove(args.exe_file)
print("\n".join(all_deps))
if args.copy:
print("Copying enabled, will now copy all dependencies next to the exe_file.\n")
parent_dir = os.path.dirname(os.path.abspath(args.exe_file))
for dep in all_deps:
target = os.path.join(parent_dir, os.path.basename(dep))
try:
print("Copying '%s' to '%s'" % (dep, target))
shutil.copy2(dep, parent_dir)
# ceski - changed copy to copy2 to preserve file dates
except shutil.SameFileError:
print("Dependency '%s' was already in target directory, "
"skipping..." % (dep))
if args.upx:
subprocess.call(["upx", target])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment