Put symlinks in the default prefix for builtin dlls.

This commit is contained in:
Esme Povirk 2020-07-12 21:07:18 -05:00 committed by Andrew Eikum
parent 369b57d8c8
commit 87ffa3c205
2 changed files with 107 additions and 19 deletions

View File

@ -82,10 +82,8 @@ endif
ifneq ($(STEAMRT_PATH),)
STEAM_RUNTIME_RUNSH := $(STEAMRT_PATH)/run-in-soldier --
STEAM_RUNTIME_LIB_PATH := $(shell $(STEAM_RUNTIME_RUNSH) env | grep LD_LIBRARY_PATH | cut -d= -f2-)
else
STEAM_RUNTIME_RUNSH :=
STEAM_RUNTIME_LIB_PATH :=
endif
SELECT_DOCKER_IMAGE :=
@ -435,23 +433,7 @@ dist: $(DIST_TARGETS) wine gst_good vrclient lsteamclient steam dxvk vkd3d-proto
echo `date '+%s'` `GIT_DIR=$(abspath $(SRCDIR)/.git) git describe --tags` > $(DIST_VERSION)
cp $(DIST_VERSION) $(DST_BASE)/
rm -rf $(abspath $(DIST_PREFIX))
$(STEAM_RUNTIME_RUNSH) env \
WINEPREFIX=$(abspath $(DIST_PREFIX)) \
LD_LIBRARY_PATH=$(abspath $(DST_DIR)/lib64):$(abspath $(DST_DIR)/lib):$(STEAM_RUNTIME_LIB_PATH) \
$(WINE_OUT_BIN) wineboot
$(STEAM_RUNTIME_RUNSH) env \
WINEPREFIX=$(abspath $(DIST_PREFIX)) \
LD_LIBRARY_PATH=$(abspath $(DST_DIR)/lib64):$(abspath $(DST_DIR)/lib):$(STEAM_RUNTIME_LIB_PATH) \
$(WINE_OUT_SERVER) -w
ln -s $(FONTLINKPATH)/LiberationSans-Regular.ttf $(abspath $(DIST_PREFIX))/drive_c/windows/Fonts/arial.ttf
ln -s $(FONTLINKPATH)/LiberationSans-Bold.ttf $(abspath $(DIST_PREFIX))/drive_c/windows/Fonts/arialbd.ttf
ln -s $(FONTLINKPATH)/LiberationSerif-Regular.ttf $(abspath $(DIST_PREFIX))/drive_c/windows/Fonts/times.ttf
ln -s $(FONTLINKPATH)/LiberationMono-Regular.ttf $(abspath $(DIST_PREFIX))/drive_c/windows/Fonts/cour.ttf
ln -s $(FONTLINKPATH)/SourceHanSansSCRegular.otf $(abspath $(DIST_PREFIX))/drive_c/windows/Fonts/msyh.ttf
#The use of "arial" here is for compatibility with programs that require that exact string. These links do not point to Arial.
#The use of "times" here is for compatibility with programs that require that exact string. This link does not point to Times New Roman.
#The use of "cour" here is for compatibility with programs that require that exact string. This link does not point to Courier New.
#The use of "msyh" here is for compatibility with programs that require that exact string. This link does not point to Microsoft YaHei.
python3 $(SRCDIR)/default_pfx.py $(abspath $(DIST_PREFIX)) $(abspath $(DST_DIR)) $(STEAM_RUNTIME_RUNSH)
deploy: dist | $(filter-out dist deploy install redist,$(MAKECMDGOALS))
mkdir -p $(DEPLOY_DIR) && \

106
default_pfx.py Executable file
View File

@ -0,0 +1,106 @@
#!/usr/bin/env python3
# usage: default_pfx.py path/to/default_pfx_dir path/to/dist
"Helper module for building the default prefix"
import os
import subprocess
def file_is_wine_builtin_dll(path):
if not os.path.exists(path):
return False
try:
sfile = open(path, "rb")
sfile.seek(0x40)
tag = sfile.read(20)
return tag.startswith((b"Wine placeholder DLL", b"Wine builtin DLL"))
except IOError:
return False
def little_endian_bytes_to_uint(b):
result = 0
multiplier = 1
for i in b:
result += i * multiplier
multiplier <<= 8
return result
def dll_bitness(path):
if not os.path.exists(path):
return 0
try:
sfile = open(path, "rb")
sfile.seek(0x3c)
ntheader_ofs = little_endian_bytes_to_uint(sfile.read(4))
sfile.seek(0x18 + ntheader_ofs)
magic = sfile.read(2)
if magic == bytes((11, 1)):
return 32
if magic == bytes((11, 2)):
return 64
return 0
except IOError:
return 0
def make_relative_symlink(target, linkname):
target = os.path.abspath(target)
linkname = os.path.abspath(linkname)
rel = os.path.relpath(target, os.path.dirname(linkname))
os.symlink(rel, linkname)
def setup_dll_symlinks(default_pfx_dir, dist_dir):
for walk_dir, dirs, files in os.walk(default_pfx_dir):
for file_ in files:
filename = os.path.join(walk_dir, file_)
if os.path.isfile(filename) and file_is_wine_builtin_dll(filename):
bitness = dll_bitness(filename)
if bitness == 32:
libdir = os.path.join(dist_dir, 'lib/wine')
elif bitness == 64:
libdir = os.path.join(dist_dir, 'lib64/wine')
else:
continue
if os.path.exists(os.path.join(libdir, file_)):
target = os.path.join(libdir, file_)
elif os.path.exists(os.path.join(libdir, 'fakedlls', file_)):
target = os.path.join(libdir, 'fakedlls', file_)
else:
continue
os.unlink(filename)
make_relative_symlink(target, filename)
def get_runtime_ld_path(runtime):
env = subprocess.check_output(runtime + ["env"], text=True)
for line in env.splitlines():
if line.startswith("LD_LIBRARY_PATH"):
return line.split("=", maxsplit=1)[1]
return None
def make_default_pfx(default_pfx_dir, dist_dir, runtime):
local_env = dict(os.environ)
local_env["WINEPREFIX"] = default_pfx_dir
local_env["WINEDEBUG"] = "-all"
ld_path = dist_dir + "/lib64:" + dist_dir + "/lib"
if runtime is None:
local_env["LD_LIBRARY_PATH"] = ld_path
runtime_args = []
else:
#the runtime overwrites LD_LIBRARY_PATH, so we pass it in on the CL via env
runtime_ld_path = get_runtime_ld_path(runtime)
if not runtime_ld_path is None:
ld_path = ld_path + ":" + runtime_ld_path
runtime_args = runtime + ["env", "LD_LIBRARY_PATH=" + ld_path]
subprocess.run(runtime_args + [os.path.join(dist_dir, 'bin', 'wine'), "wineboot"], env=local_env, check=True)
subprocess.run(runtime_args + [os.path.join(dist_dir, 'bin', 'wineserver'), "-w"], env=local_env, check=True)
setup_dll_symlinks(default_pfx_dir, dist_dir)
if __name__ == '__main__':
import sys
if len(sys.argv) > 3:
make_default_pfx(sys.argv[1], sys.argv[2], sys.argv[3:])
else:
make_default_pfx(sys.argv[1], sys.argv[2], None)