Skip to content

Commit 5808e90

Browse files
committed
Makefile.in: refactor install rules
This refactor aims to reduce the amount of duplicated Bash code that is used in all of the distribution packages (dpkg, AUR, COPR, and Nixpkgs). * Introduce install-linux and install-darwin targets, which are automatically selected by make where appropriate. * install-linux installs icons and the CraftOS-PC.desktop file. * install-darwin installs CraftOS-PC.app to /Applications. * Introduce install-bin, install-headers, and install-liblua targets, which install the respective components. * Introduce fixup-liblua-path target, which uses patchelf to change the name of liblua.so (this patching appears to be common across all packages). * Introduce target for resources/linux-icons. * Remove the DESTDIR variable, instead using Autoconf's install directories feature [1] * Introduce the INSTALL_TARGETS variable, which is used to control what dependencies the install rule has. * Introduce the EXTRA_PLATFORM_INSTALL_TARGETS variable, which is conditionally set depending on the platform. * Introduce the LIBLUA_NAME variable, which is used to control what file patchelf changes liblua.so from. This refactor **does not** include code to install craftos2-rom, since that appears to be out-of-scope. [1]: https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
1 parent 4fff128 commit 5808e90

File tree

1 file changed

+91
-8
lines changed

1 file changed

+91
-8
lines changed

Makefile.in

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ LDFLAGS=@LDFLAGS@
88
LIBEXT=.so
99
ifndef OS
1010
ifeq (@OUT_TARGET@, craftos)
11+
ifeq ($(shell uname), Linux)
12+
EXTRA_PLATFORM_INSTALL_TARGETS=install-linux fixup-liblua-path
13+
endif
14+
endif
15+
endif
16+
ifndef OS
17+
ifeq (@OUT_TARGET@, craftos)
1118
ifeq ($(shell uname), Darwin)
1219
LIBEXT=.dylib
20+
EXTRA_PLATFORM_INSTALL_TARGETS=install-darwin
1321
endif
1422
endif
1523
endif
@@ -22,11 +30,21 @@ LIBEXT=.dylib
2230
endif
2331
endif
2432
endif
33+
INSTALL_TARGETS?=install-bin install-headers install-liblua $(EXTRA_PLATFORM_INSTALL_TARGETS)
2534
PREFIX?=@prefix@
2635
prefix=$(PREFIX)
27-
DESTDIR?=@exec_prefix@
36+
exec_prefix=@exec_prefix@
37+
ifdef DESTDIR
38+
$(error "The DESTDIR variable was removed. Please set PREFIX if you would like to change where everything will be installed, or set BINDIR if you would like to change where binaries will be installed.")
39+
endif
40+
BINDIR=@bindir@
41+
SHAREDIR=@datarootdir@
42+
INCLUDEDIR=@includedir@
43+
LIBDIR=@libdir@
44+
MACAPPDIR=$(PREFIX)/Applications
45+
LIBLUA_NAME=libcraftos2-liblua
2846
ifneq (/usr,$(PREFIX))
29-
CPPFLAGS:=$(CPPFLAGS) -DCUSTOM_ROM_DIR=\"$(PREFIX)/share/craftos\"
47+
CPPFLAGS:=$(CPPFLAGS) -DCUSTOM_ROM_DIR=\"$(SHAREDIR)/craftos\"
3048
endif
3149
SDIR=@srcdir@/src
3250
IDIR=@srcdir@/api
@@ -127,6 +145,9 @@ $(ODIR)/apis_%_handle.o: $(SDIR)/apis/handles/%_handle.cpp $(SDIR)/apis/handles/
127145
echo " [CXX] $@"
128146
$(CXX) -o $@ -c $(CPPFLAGS) $(CXXFLAGS) $(CFLAGS) $<
129147

148+
resources/linux-icons: resources/linux-icons.zip
149+
unzip resources/linux-icons.zip -d resources/linux-icons
150+
130151
mac-plugin:
131152
echo " [LD] ccemux.bundle"
132153
$(CXX) -std=c++17 -bundle -fpic -o ccemux.bundle examples/ccemux.cpp craftos2-lua/src/liblua$(LIBEXT) -lSDL2 -Icraftos2-lua/include -Iapi
@@ -137,20 +158,82 @@ linux-plugin:
137158

138159
clean: $(ODIR)
139160
rm -f craftos
161+
rm -rf resources/linux-icons
140162
find obj -type f -not -name speaker_sounds.o -exec rm -f {} \;
141163

142164
rebuild: clean craftos
143165

144-
install: craftos
145-
echo " [CP] $(DESTDIR)/craftos"
146-
cp craftos $(DESTDIR)/craftos
166+
fixup-liblua-path: craftos $(filter linux-plugin,$(MAKECMDGOALS))
167+
echo " [FIXUP] craftos"
168+
patchelf --replace-needed craftos2-lua/src/liblua.so "$(LIBLUA_NAME)$(LIBEXT)" craftos
169+
if [ -f ccemux$(LIBEXT) ]; then; \
170+
echo " [FIXUP] ccemux$(LIBEXT)" \
171+
patchelf --replace-needed craftos2-lua/src/liblua.so "$(LIBLUA_NAME)$(LIBEXT)" ccemux$(LIBEXT) \
172+
fi
173+
174+
install-darwin: macapp
175+
cp -r CraftOS-PC.app $(MACAPPDIR)
176+
177+
install-linux: resources/linux-icons
178+
echo " [MKDIR] $(SHAREDIR)/applications"
179+
mkdir -p "$(SHAREDIR)/applications"
180+
echo " [CP] resources/CraftOS-PC.desktop"
181+
cp resources/CraftOS-PC.desktop "$(SHAREDIR)/applications"
182+
183+
for dimension in 16 24 32 48 64 96 128 256 1024; do \
184+
icondir="$(SHAREDIR)/icons/hicolor/$${dimension}x$${dimension}/apps"; \
185+
echo " [MKDIR] $${icondir}"; \
186+
mkdir -p "$${icondir}"; \
187+
echo " [CP] resources/linux-icons/$${dimension}.png"; \
188+
cp "resources/linux-icons/$${dimension}.png" "$${icondir}/craftos.png"; \
189+
done
190+
191+
install-headers:
192+
echo " [MKDIR] $(INCLUDEDIR)"
193+
mkdir -p "$(INCLUDEDIR)"
194+
echo " [CP] api"
195+
cp -R api "$(INCLUDEDIR)/CraftOS-PC"
196+
197+
install-bin: craftos $(filter fixup-liblua-path,$(MAKECMDGOALS))
198+
echo " [MKDIR] $(BINDIR)"
199+
mkdir -p "$(BINDIR)"
200+
echo " [CP] craftos"
201+
cp craftos "$(BINDIR)/craftos"
202+
203+
# craftos2-lua does have a ``make install`` rule, but it installs a lot of
204+
# files that conflict with a standard Lua installation.
205+
install-liblua: craftos2-lua/src/liblua$(LIBEXT)
206+
echo " [MKDIR] $(LIBDIR)"
207+
mkdir "$(LIBDIR)"
208+
echo " [CP] craftos2-lua/src/liblua$(LIBEXT)"
209+
cp craftos2-lua/src/liblua$(LIBEXT) $(LIBDIR)/$(LIBLUA_NAME)$(LIBEXT)
210+
211+
install: $(INSTALL_TARGETS)
212+
213+
# Not installed by default, since this is not always wanted.
214+
extra-install-linux-plugin: linux-plugin fixup-liblua-path
215+
echo " [MKDIR] $(SHAREDIR)/craftos/plugins"
216+
mkdir -p "$(SHAREDIR)/craftos/plugins"
217+
echo " [CP] ccemux$(LIBEXT)"
218+
cp "ccemux$(LIBEXT)" "$(SHAREDIR)/craftos/plugins"
147219

148220
uninstall:
149-
echo " [RM] $(DESTDIR)/craftos"
150-
rm $(DESTDIR)/craftos
221+
echo " [RM] $(BINDIR)/craftos"
222+
rm -f "$(BINDIR)/craftos"
223+
echo " [RM] $(SHAREDIR)/applications/CraftOS-PC.desktop"
224+
rm -f "$(SHAREDIR)/applications/CraftOS-PC.desktop"
225+
echo ' [RM] $(SHAREDIR)/icons/hicolor/*/apps/craftos.png'
226+
rm -f "$(SHAREDIR)/icons/hicolor/*/apps/craftos.png"
227+
echo ' [RM] $(LIBDIR)/$(LIBLUA_NAME)$(LIBEXT)'
228+
rm -f "$(LIBDIR)/$(LIBLUA_NAME)$(LIBEXT)"
229+
echo ' [RM] $(INCLUDEDIR)/CraftOS-PC'
230+
rm -rf "$(INCLUDEDIR)/CraftOS-PC"
231+
echo ' [RM] $(MACAPPDIR)/CraftOS-PC.app'
232+
rm -rf "$(MACAPPDIR)/CraftOS-PC.app"
233+
151234

152235
test: craftos
153236
./craftos --headless --script $(shell pwd)/resources/CraftOSTest.lua -d "$(shell mktemp -d)"
154237

155-
.PHONY: all macapp clean rebuild install uninstall test
238+
.PHONY: all macapp clean rebuild install install-bin install-headers install-liblua install-linux install-darwin extra-install-linux-plugin uninstall test
156239
.SILENT:

0 commit comments

Comments
 (0)