Skip to content

Commit 1196a36

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 (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 (appears to be common across all packages). * Introduce target for resources/linux-icons.zip. * 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 1196a36

File tree

1 file changed

+70
-7
lines changed

1 file changed

+70
-7
lines changed

Makefile.in

Lines changed: 70 additions & 7 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,20 @@ 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+
ifdef DESTDIR
37+
$(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.")
38+
endif
39+
BINDIR=@bindir@
40+
SHAREDIR=@datarootdir@
41+
INCLUDEDIR=@includedir@
42+
LIBDIR=@libdir@
43+
MACAPPDIR=$(PREFIX)/Applications
44+
LIBLUA_NAME=libcraftos2-liblua
2845
ifneq (/usr,$(PREFIX))
29-
CPPFLAGS:=$(CPPFLAGS) -DCUSTOM_ROM_DIR=\"$(PREFIX)/share/craftos\"
46+
CPPFLAGS:=$(CPPFLAGS) -DCUSTOM_ROM_DIR=\"$(SHAREDIR)/craftos\"
3047
endif
3148
SDIR=@srcdir@/src
3249
IDIR=@srcdir@/api
@@ -127,6 +144,9 @@ $(ODIR)/apis_%_handle.o: $(SDIR)/apis/handles/%_handle.cpp $(SDIR)/apis/handles/
127144
echo " [CXX] $@"
128145
$(CXX) -o $@ -c $(CPPFLAGS) $(CXXFLAGS) $(CFLAGS) $<
129146

147+
resources/linux-icons: resources/linux-icons.zip
148+
unzip resources/linux-icons.zip -d resources/linux-icons
149+
130150
mac-plugin:
131151
echo " [LD] ccemux.bundle"
132152
$(CXX) -std=c++17 -bundle -fpic -o ccemux.bundle examples/ccemux.cpp craftos2-lua/src/liblua$(LIBEXT) -lSDL2 -Icraftos2-lua/include -Iapi
@@ -137,20 +157,63 @@ linux-plugin:
137157

138158
clean: $(ODIR)
139159
rm -f craftos
160+
rm -rf resources/linux-icons
140161
find obj -type f -not -name speaker_sounds.o -exec rm -f {} \;
141162

142163
rebuild: clean craftos
143164

144-
install: craftos
145-
echo " [CP] $(DESTDIR)/craftos"
146-
cp craftos $(DESTDIR)/craftos
165+
fixup-liblua-path: craftos
166+
echo " [FIXUP] craftos"
167+
patchelf --replace-needed craftos2-lua/src/liblua.so "$(LIBLUA_NAME)$(LIBEXT)" ./craftos
168+
169+
install-darwin: macapp
170+
cp -r CraftOS-PC.app $(MACAPPDIR)
171+
172+
install-linux: resources/linux-icons
173+
echo " [MKDIR] $(SHAREDIR)/applications"
174+
mkdir -p "$(SHAREDIR)/applications"
175+
echo " [CP] resources/CraftOS-PC.desktop"
176+
cp resources/CraftOS-PC.desktop "$(SHAREDIR)/applications"
177+
178+
for dimension in 16 24 32 48 64 96 128 256 1024; do \
179+
icondir="$(SHAREDIR)/icons/hicolor/$${dimension}x$${dimension}/apps"; \
180+
echo " [MKDIR] $${icondir}"; \
181+
mkdir -p "$${icondir}"; \
182+
echo " [CP] resources/linux-icons/$${dimension}.png)"; \
183+
cp "resources/linux-icons/$${dimension}.png" "$${icondir}/craftos.png"; \
184+
done
185+
186+
install-headers:
187+
echo " [MKDIR] $(INCLUDEDIR)"
188+
mkdir -p "$(INCLUDEDIR)"
189+
echo " [CP] api"
190+
cp -R api "$(INCLUDEDIR)/CraftOS-PC"
191+
192+
install-bin: craftos
193+
echo " [CP] $(BINDIR)/craftos"
194+
cp craftos "$(BINDIR)/craftos"
195+
196+
# craftos2-lua does have a ``make install`` rule, but it installs a lot of
197+
# files that conflict with a standard Lua installation.
198+
install-liblua: craftos2-lua/src/liblua$(LIBEXT)
199+
echo " [MKDIR] $(LIBDIR)"
200+
mkdir $(LIBDIR)
201+
cp craftos2-lua/src/liblua$(LIBEXT) $(LIBDIR)/$(LIBLUA_NAME)$(LIBEXT)
202+
203+
install: $(INSTALL_TARGETS)
147204

148205
uninstall:
149206
echo " [RM] $(DESTDIR)/craftos"
150-
rm $(DESTDIR)/craftos
207+
rm -f "$(BINDIR)/craftos"
208+
rm -rf "$(INCLUDEDIR)/CraftOS-PC"
209+
rm -f "$(SHAREDIR)/applications/CraftOS-PC.desktop"
210+
rm -f "$(SHAREDIR)/icons/hicolor/*/apps/craftos.png"
211+
rm -f "$(LIBDIR)/$(LIBLUA_NAME)$(LIBEXT)"
212+
rm -rf "$(MACAPPDIR)/CraftOS-PC.app"
213+
151214

152215
test: craftos
153216
./craftos --headless --script $(shell pwd)/resources/CraftOSTest.lua -d "$(shell mktemp -d)"
154217

155-
.PHONY: all macapp clean rebuild install uninstall test
218+
.PHONY: all macapp clean rebuild install install-bin install-headers install-liblua install-linux install-darwin uninstall test
156219
.SILENT:

0 commit comments

Comments
 (0)