# 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)
@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")
.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)/