Makefile: support downstream packages
authorbones_was_here <bones_was_here@xonotic.au>
Thu, 17 Apr 2025 21:21:15 +0000 (07:21 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sat, 19 Apr 2025 09:54:51 +0000 (19:54 +1000)
This is written with reference to the old Makefile (but with updates and
fixes) and some 0.8.6 distro packages. It aims to support the way they want
to package Xonotic to reduce the amount of fragile version-specific
scripting they do so they have less problems building new versions.

- Supports several GNU make "standard" directory variables and targets
- Supports omitting the xonotic-linux-*.sh files and symlinks by setting
  BASEDIR
- Supports client-only and server-only installs
- Supports renaming desktop and icon files (for flathub)
- Installs data to $(prefix)/share/xonotic instead of
  $(prefix)/lib/xonotic to match GNU make docs and current distro
  packages.
- Includes metadata and CA key for player IDs

Some documentation is added at https://gitlab.com/xonotic/xonotic/-/wikis/Compiling

Makefile
misc/logos/xonotic.desktop

index d03994343929fde89b1d27e064d3995f69ce80bf..68e1264d549616ae15b7ed330b35aea5992348df 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,8 @@ SERVERBIN ?= xonotic-dedicated
 
 # CC and MAKEFLAGS are always set so ?= has no effect, therefore
 # we use CFLAGS to set default optimisations which users may override
-CFLAGS ?= -pipe -march=native -mtune=native -flto=auto
+CFLAGS ?= -march=native -mtune=native
+CFLAGS += -flto=auto
 # user can override this with make -j
 MAKEFLAGS := -j$(shell nproc)
 # DP makefile overrides CFLAGS (exporting CFLAGS does work for d0_blind_id but so does this)
@@ -49,7 +50,7 @@ help:
        @echo
        @printf "  make server                Compile \e[1;32m$(SERVERBIN)\e[m\n"
        @printf "  make client                Compile \e[1;32m$(CLIENTBIN)\e[m\n"
-       @echo   "  make both"
+       @echo   "  make all                   Compile both client and server"
        @echo
 
 GIT := $(shell [ -d .git ] && printf "\e[1;31mThis Makefile only supports stable releases and autobuilds, whereas you are using a git repository.  To compile from git, please read https://gitlab.com/xonotic/xonotic/-/wikis/Repository_Access\e[m")
@@ -103,6 +104,116 @@ server: $(SERVERBIN)
 .PHONY: client
 client: $(CLIENTBIN)
 
-.PHONY: both
-both: client server
+.PHONY: all both
+all both: client server
+
+
+# GNU make standard directory variables for install targets
+DESTDIR ?=
+prefix ?= /usr/local
+exec_prefix ?= $(prefix)
+bindir ?= $(exec_prefix)/bin
+libdir ?= $(exec_prefix)/lib
+datarootdir ?= $(prefix)/share
+datadir ?= $(datarootdir)
+docdir ?= $(datarootdir)/doc/xonotic
+
+# $BASEDIR is where data/*.pk3 will be installed.
+# By default this will be located at runtime by installing the engine there and symlinking to it in $bindir.
+# If $BASEDIR (preferred) or $DP_FS_BASEDIR (compat synonym) was defined externally the engine will be installed to $bindir,
+# the value of $BASEDIR / $DP_FS_BASEDIR will be compiled into it, and no symlinks are needed.
+ifdef BASEDIR
+       export DP_FS_BASEDIR = $(BASEDIR)
+else
+       # don't put spaces after the commas, they end up in the path!
+       BASEDIR = $(if $(DP_FS_BASEDIR),$(DP_FS_BASEDIR),$(datadir)/xonotic)
+endif
+
+INSTALL ?= install
+INSTALL_PROGRAM ?= $(INSTALL) -vD
+INSTALL_DATA ?= $(INSTALL) -vDm644
+
+.PHONY: install
+install: install-data install-engine install-desktop install-doc
+.PHONY: install-client
+install-client: install-data install-engine-client install-desktop-client install-doc-client
+.PHONY: install-server
+install-server: install-data install-engine-server install-desktop-server install-doc-server
+.PHONY: install-engine
+install-engine: install-engine-client install-engine-server
+.PHONY: install-desktop
+install-desktop: install-desktop-client install-desktop-server
+.PHONY: install-doc
+install-doc: install-doc-client install-doc-server
+
+.PHONY: install-help
+install-help:
+       @echo
+       @printf "     \e[1;33m===== Xonotic Makefile: install target list =====\e[m\n"
+       @echo
+       @printf "More info is available at \e[1;36mhttps://gitlab.com/xonotic/xonotic/-/wikis/Compiling\e[m\n"
+       @echo
+       @echo   "  install: install-data install-engine install-desktop install-doc"
+       @echo   "  install-client: install-data install-engine-client install-desktop-client install-doc-client"
+       @echo   "  install-server: install-data install-engine-server install-desktop-server install-doc-server"
+       @echo
+       @echo   "  install-data:                                                    data/*.pk3 VFS contents, pubkey"
+       @echo   "  install-engine: install-engine-client install-engine-server      Main binaries"
+       @echo   "  install-desktop: install-desktop-client install-desktop-server   desktop icon, metainfo"
+       @echo   "  install-doc: install-doc-client install-doc-server"
+
+.PHONY: install-data
+install-data:
+       $(RM) -rf $(DESTDIR)$(BASEDIR)/data
+       for p in data/*.pk3; do $(INSTALL_DATA) $$p $(DESTDIR)$(BASEDIR)/$$p || exit 1; done
+       $(INSTALL_DATA) key_0.d0pk $(DESTDIR)$(BASEDIR)/key_0.d0pk
+
+# TODO: when the .sh scripts are fully obsolete, make install-engine-* not PHONY (hint: declare the target inside the ifdef)
+.PHONY: install-engine-client
+install-engine-client: client
+ifdef DP_FS_BASEDIR # path for distro package builds that define $BASEDIR / $DP_FS_BASEDIR
+       $(INSTALL_PROGRAM) source/darkplaces/darkplaces-sdl $(DESTDIR)$(bindir)/xonotic-sdl
+else # end users aren't expected to `make install` but if they do this path makes their install functional
+       $(INSTALL_PROGRAM) source/darkplaces/darkplaces-sdl $(DESTDIR)$(BASEDIR)/xonotic-sdl
+       # install-links
+       $(INSTALL_PROGRAM) xonotic-linux-sdl.sh $(DESTDIR)$(BASEDIR)/xonotic-linux-sdl.sh
+       $(INSTALL) -d $(DESTDIR)$(bindir)
+       ln -snf $(BASEDIR)/xonotic-linux-sdl.sh $(DESTDIR)$(bindir)/xonotic-sdl
+endif
+
+.PHONY: install-engine-server
+install-engine-server: server
+ifdef DP_FS_BASEDIR # path for distro package builds that define $BASEDIR / $DP_FS_BASEDIR
+       $(INSTALL_PROGRAM) source/darkplaces/darkplaces-dedicated $(DESTDIR)$(bindir)/xonotic-dedicated
+else # end users aren't expected to `make install` but if they do this path makes their install functional
+       $(INSTALL_PROGRAM) source/darkplaces/darkplaces-dedicated $(DESTDIR)$(BASEDIR)/xonotic-dedicated
+       # install-links
+       $(INSTALL_PROGRAM) xonotic-linux-dedicated.sh $(DESTDIR)$(BASEDIR)/xonotic-linux-dedicated.sh
+       $(INSTALL) -d $(DESTDIR)$(bindir)
+       ln -snf $(BASEDIR)/xonotic-linux-dedicated.sh $(DESTDIR)$(bindir)/xonotic-dedicated
+endif
 
+# Flathub requires these file names to be changed, which requires editing files that reference them.
+# No file extensions in the values because desktop files omit them from Icon=
+FILENAME_ICON_CLIENT ?= xonotic
+FILENAME_DESKTOP_CLIENT ?= xonotic
+.PHONY: install-desktop-client
+install-desktop-client:
+       $(INSTALL_DATA) misc/logos/xonotic_icon.svg $(DESTDIR)$(datarootdir)/icons/hicolor/scalable/apps/$(FILENAME_ICON_CLIENT).svg
+       $(INSTALL_DATA) misc/logos/xonotic.desktop $(DESTDIR)$(datarootdir)/applications/$(FILENAME_DESKTOP_CLIENT).desktop
+       $(INSTALL_DATA) misc/logos/org.xonotic.Xonotic.metainfo.xml $(DESTDIR)$(datarootdir)/metainfo/org.xonotic.Xonotic.metainfo.xml
+       sed -i 's/Icon=xonotic/Icon=$(FILENAME_ICON_CLIENT)/' $(DESTDIR)$(datarootdir)/applications/$(FILENAME_DESKTOP_CLIENT).desktop
+       sed -i 's/<launchable type=\"desktop-id\">xonotic.desktop<\/launchable>/<launchable type=\"desktop-id\">$(FILENAME_DESKTOP_CLIENT).desktop<\/launchable>/' $(DESTDIR)$(datarootdir)/metainfo/org.xonotic.Xonotic.metainfo.xml
+
+.PHONY: install-desktop-server
+install-desktop-server: # TODO https://gitlab.com/xonotic/xonotic/-/issues/216
+
+.PHONY: install-doc-client
+install-doc-client:
+       $(INSTALL) -d $(DESTDIR)$(docdir)
+       cp -R Docs/* $(DESTDIR)$(docdir)/
+
+.PHONY: install-doc-server
+install-doc-server:
+       $(INSTALL) -d $(DESTDIR)$(docdir)
+       cp -R server $(DESTDIR)$(docdir)/
index 2ace785b38789aa0fcfbc663f53d996ccc07e58e..fbfcd229fcf67d4d277ede1dba722ceb09436b67 100644 (file)
@@ -22,7 +22,9 @@ Icon=xonotic
 # 3)
 #   Recompile Xonotic with DP_FS_BASEDIR=/path/to/xonotic/ , for example
 #   with DP_FS_BASEDIR=/usr/share/xonotic/ it's no longer necessary
-#   to change your PWD and xonotic-sdl can be anywhere in PATH
+#   to change your PWD and xonotic-sdl can be anywhere in PATH .
+#   Downstream packages are expected to use this option, supported in the Makefile,
+#   see: https://gitlab.com/xonotic/xonotic/-/wikis/Compiling
 # 4)
 #   DIY your own wrapper script with "-basedir" "/path/to/Xonotic" arguments
 #   or just place the arguments in this file