Skip to content

Commit 0b409b0

Browse files
Merge pull request #319 from loathingKernel/selfcontained
Make protonfixes self-contained
2 parents 3bbaf67 + c861dbb commit 0b409b0

File tree

3 files changed

+81
-52
lines changed

3 files changed

+81
-52
lines changed

Makefile

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
OBJDIR := builddir
1+
BUILD ?= build
2+
DIST ?= dist
23

3-
PREFIX ?= /usr
4-
DESTDIR ?=
5-
INSTALL_DIR ?= $(shell pwd)/dist/protonfixes
4+
OBJDIR := $(shell realpath $(BUILD))
5+
DSTDIR := $(shell realpath $(DIST))
6+
TARGET_DIR := $(DSTDIR)
7+
8+
BASEDIR := /files
9+
i386_LIBDIR = $(BASEDIR)/lib/i386-linux-gnu
10+
x86_64_LIBDIR = $(BASEDIR)/lib/x86_64-linux-gnu
611

712
.PHONY: all
813

@@ -21,23 +26,32 @@ install: protonfixes-install cabextract-install libmspack-install unzip-install
2126

2227
protonfixes-install: protonfixes
2328
$(info :: Installing protonfixes )
24-
install -d $(INSTALL_DIR)
25-
cp -r gamefixes-* $(INSTALL_DIR)
26-
cp -r verbs $(INSTALL_DIR)
27-
cp *.py $(INSTALL_DIR)
28-
cp winetricks $(INSTALL_DIR)
29-
cp umu-database.csv $(INSTALL_DIR)
30-
rm $(INSTALL_DIR)/protonfixes_test.py
29+
install -d $(TARGET_DIR)
30+
cp -r gamefixes-* $(TARGET_DIR)
31+
cp -r verbs $(TARGET_DIR)
32+
cp *.py $(TARGET_DIR)
33+
mkdir -p $(TARGET_DIR)$(BASEDIR)/bin
34+
cp winetricks $(TARGET_DIR)$(BASEDIR)/bin
35+
cp winetricks $(TARGET_DIR)
36+
cp umu-database.csv $(TARGET_DIR)
37+
rm $(TARGET_DIR)/protonfixes_test.py
38+
39+
#
40+
# libmspack and cabextract
41+
#
42+
43+
$(OBJDIR)/libmspack: | $(OBJDIR)
44+
rsync -arx --delete subprojects/libmspack $(OBJDIR)
3145

3246
#
3347
# cabextract
3448
#
3549

36-
$(OBJDIR)/.build-cabextract-dist: | $(OBJDIR)
50+
$(OBJDIR)/.build-cabextract-dist: | $(OBJDIR)/libmspack
3751
$(info :: Building cabextract )
38-
cd subprojects/libmspack/cabextract && \
39-
./autogen.sh && \
40-
./configure --prefix=/usr --sysconfdir=/etc --mandir=/usr/share/man && \
52+
cd $(OBJDIR)/libmspack/cabextract && \
53+
autoreconf -fiv -I /usr/share/gettext/m4/ && \
54+
./configure --prefix=$(BASEDIR) --libdir=$(x86_64_LIBDIR) && \
4155
make
4256
touch $(@)
4357

@@ -47,20 +61,19 @@ cabextract-dist: $(OBJDIR)/.build-cabextract-dist
4761

4862
cabextract-install: cabextract-dist
4963
$(info :: Installing cabextract )
50-
cd subprojects/libmspack/cabextract && \
51-
make DESTDIR=$(INSTALL_DIR) install
52-
cp $(INSTALL_DIR)/usr/bin/cabextract $(INSTALL_DIR)
53-
rm -r $(INSTALL_DIR)/usr
64+
cd $(OBJDIR)/libmspack/cabextract && \
65+
make DESTDIR=$(TARGET_DIR) install
66+
rm -r $(TARGET_DIR)$(BASEDIR)/share
5467

5568
#
5669
# libmspack
5770
#
5871

59-
$(OBJDIR)/.build-libmspack-dist: | $(OBJDIR)
72+
$(OBJDIR)/.build-libmspack-dist: | $(OBJDIR)/libmspack
6073
$(info :: Building libmspack )
61-
cd subprojects/libmspack/libmspack && \
74+
cd $(OBJDIR)/libmspack/libmspack && \
6275
autoreconf -vfi && \
63-
./configure --prefix=/usr --disable-static --sysconfdir=/etc --localstatedir=/var && \
76+
./configure --prefix=$(BASEDIR) --libdir=$(x86_64_LIBDIR) --disable-static && \
6477
sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool && \
6578
make
6679
touch $(@)
@@ -71,11 +84,11 @@ libmspack-dist: $(OBJDIR)/.build-libmspack-dist
7184

7285
libmspack-install: libmspack-dist
7386
$(info :: Installing libmspack )
74-
cd subprojects/libmspack/libmspack && \
75-
make DESTDIR=$(INSTALL_DIR) install
76-
cp -d $(INSTALL_DIR)/usr/lib/libmspack* $(INSTALL_DIR)
77-
rm -r $(INSTALL_DIR)/usr
78-
rm $(INSTALL_DIR)/libmspack.la
87+
cd $(OBJDIR)/libmspack/libmspack && \
88+
make DESTDIR=$(TARGET_DIR) install
89+
rm -r $(TARGET_DIR)$(BASEDIR)/include
90+
rm -r $(TARGET_DIR)$(BASEDIR)/lib/x86_64-linux-gnu/pkgconfig
91+
rm $(TARGET_DIR)$(BASEDIR)/lib/x86_64-linux-gnu/libmspack.la
7992

8093
#
8194
# unzip
@@ -92,9 +105,10 @@ UNZIP_PATCHES := $(shell cat subprojects/unzip/debian/patches/series)
92105

93106
$(OBJDIR)/.build-unzip-dist: | $(OBJDIR)
94107
$(info :: Building unzip )
95-
cd subprojects/unzip && \
108+
rsync -arx --delete subprojects/unzip $(OBJDIR)
109+
cd $(OBJDIR)/unzip && \
96110
$(foreach pch, $(UNZIP_PATCHES),patch -Np1 -i debian/patches/$(pch) &&) \
97-
make -f unix/Makefile prefix=/usr D_USE_BZ2=-DUSE_BZIP2 L_BZ2=-lbz2 LF2="$(LDFLAGS)" CF="$(CFLAGS) -I. $(DEFINES)" unzips
111+
make -f unix/Makefile prefix=$(BASEDIR) D_USE_BZ2=-DUSE_BZIP2 L_BZ2=-lbz2 LF2="$(LDFLAGS)" CF="$(CFLAGS) -I. $(DEFINES)" unzips
98112
touch $(@)
99113

100114
.PHONY: unzip-dist
@@ -103,21 +117,20 @@ unzip-dist: $(OBJDIR)/.build-unzip-dist
103117

104118
unzip-install: unzip-dist
105119
$(info :: Installing unzip )
106-
cd subprojects/unzip && \
107-
make -f unix/Makefile prefix=$(INSTALL_DIR) install
120+
cd $(OBJDIR)/unzip && \
121+
make -f unix/Makefile prefix=$(TARGET_DIR)$(BASEDIR) install
108122
# Post install
109-
cp -a $(INSTALL_DIR)/bin/unzip $(INSTALL_DIR)
110-
rm -r $(INSTALL_DIR)/bin $(INSTALL_DIR)/man
123+
rm -r $(TARGET_DIR)$(BASEDIR)/man
111124

112125
#
113126
# python-xlib
114127
#
115128

116129
$(OBJDIR)/.build-python-xlib-dist: | $(OBJDIR)
117130
$(info :: Building python-xlib )
118-
cd subprojects/python-xlib && \
119-
dpkg-source --before-build . && \
120-
dh_auto_build -O--buildsystem=pybuild
131+
rsync -arx --delete subprojects/python-xlib $(OBJDIR)
132+
cd $(OBJDIR)/python-xlib && \
133+
python setup.py build
121134
touch $(@)
122135

123136
.PHONY: python-xlib-dist
@@ -126,10 +139,10 @@ python-xlib-dist: $(OBJDIR)/.build-python-xlib-dist
126139

127140
python-xlib-install: python-xlib-dist
128141
$(info :: Installing python-xlib )
129-
mkdir -p $(INSTALL_DIR)/_vendor && \
130-
cd subprojects/python-xlib && \
131-
dh_auto_install -O--buildsystem=pybuild && \
132-
find debian/tmp -type d -name Xlib | xargs -I {} mv {} $(INSTALL_DIR)/_vendor; \
142+
mkdir $(TARGET_DIR)/_vendor
143+
cd $(OBJDIR)/python-xlib && mkdir dist && \
144+
python setup.py install --root=dist --optimize=1 --skip-build && \
145+
find dist -type d -name Xlib | xargs -I {} mv {} $(TARGET_DIR)/_vendor;
133146

134147
$(OBJDIR):
135148
@mkdir -p $(@)

__init__.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
import traceback
6+
from typing import Callable
67

78
from . import fix
89
from .logger import log
@@ -12,6 +13,10 @@
1213
f'{os.path.dirname(os.path.realpath(__file__))}/_vendor', # noqa: PTH120
1314
)
1415

16+
bin_dir: str = f'{os.path.dirname(os.path.realpath(__file__))}/files/bin'
17+
i386_lib_dir: str = f'{os.path.dirname(os.path.realpath(__file__))}/files/lib/i386-linux-gnu'
18+
x86_64_lib_dir: str = f'{os.path.dirname(os.path.realpath(__file__))}/files/lib/x86_64-linux-gnu'
19+
1520

1621
def check_conditions() -> bool:
1722
"""Determine, if the actual game was executed and protonfixes isn't deactivated.
@@ -38,15 +43,26 @@ def check_iscriptevaluator() -> bool:
3843
return len(sys.argv) >= 3 and 'iscriptevaluator.exe' in sys.argv[2]
3944

4045

41-
if check_iscriptevaluator():
42-
log.debug('Skipping fix execution. We are running "iscriptevaluator.exe".')
43-
elif not check_conditions():
44-
log.warn('Skipping fix execution. We are probably running an unit test.')
45-
else:
46-
try:
47-
fix.main()
46+
def setup(env: dict, bin_path_var: str, lib_path_var: str, func: Callable[[dict, str, str, str], None]) -> None:
47+
"""Setup PATH and LD_LIBRARY_PATH to include protonfixes's binary and library paths"""
48+
func(env, bin_path_var, bin_dir, ':')
49+
func(env, lib_path_var, f'{x86_64_lib_dir}:{i386_lib_dir}', ':')
50+
51+
52+
def execute() -> None:
53+
"""Execute protonfixes"""
54+
if check_iscriptevaluator():
55+
log.debug('Skipping fix execution. We are running "iscriptevaluator.exe".')
56+
elif not check_conditions():
57+
log.warn('Skipping fix execution. We are probably running an unit test.')
58+
else:
59+
try:
60+
fix.main()
61+
62+
# Catch any exceptions and print a traceback
63+
except Exception:
64+
sys.stderr.write('ProtonFixes ' + traceback.format_exc())
65+
sys.stderr.flush()
66+
4867

49-
# Catch any exceptions and print a traceback
50-
except Exception:
51-
sys.stderr.write('ProtonFixes ' + traceback.format_exc())
52-
sys.stderr.flush()
68+
__all__ = ["setup", "execute"]

util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def protontricks(verb: str) -> bool:
321321
env['WINETRICKS_LATEST_VERSION_CHECK'] = 'disabled'
322322
env['LD_PRELOAD'] = ''
323323

324-
winetricks_bin = os.path.abspath(__file__).replace('util.py', 'winetricks')
324+
winetricks_bin = 'winetricks'
325325
winetricks_cmd = [winetricks_bin, '--unattended'] + verb.split(' ')
326326
if verb == 'gui':
327327
winetricks_cmd = [winetricks_bin, '--unattended']

0 commit comments

Comments
 (0)