# Makefile.in generated by automake 1.16.1 from Makefile.am.
# @configure_input@

# Copyright (C) 1994-2018 Free Software Foundation, Inc.

# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = { \
  if test -z '$(MAKELEVEL)'; then \
    false; \
  elif test -n '$(MAKE_HOST)'; then \
    true; \
  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
    true; \
  else \
    false; \
  fi; \
}
am__make_running_with_option = \
  case $${target_option-} in \
      ?) ;; \
      *) echo "am__make_running_with_option: internal error: invalid" \
              "target option '$${target_option-}' specified" >&2; \
         exit 1;; \
  esac; \
  has_opt=no; \
  sane_makeflags=$$MAKEFLAGS; \
  if $(am__is_gnu_make); then \
    sane_makeflags=$$MFLAGS; \
  else \
    case $$MAKEFLAGS in \
      *\\[\ \	]*) \
        bs=\\; \
        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
    esac; \
  fi; \
  skip_next=no; \
  strip_trailopt () \
  { \
    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
  }; \
  for flg in $$sane_makeflags; do \
    test $$skip_next = yes && { skip_next=no; continue; }; \
    case $$flg in \
      *=*|--*) continue;; \
        -*I) strip_trailopt 'I'; skip_next=yes;; \
      -*I?*) strip_trailopt 'I';; \
        -*O) strip_trailopt 'O'; skip_next=yes;; \
      -*O?*) strip_trailopt 'O';; \
        -*l) strip_trailopt 'l'; skip_next=yes;; \
      -*l?*) strip_trailopt 'l';; \
      -[dEDm]) skip_next=yes;; \
      -[JT]) skip_next=yes;; \
    esac; \
    case $$flg in \
      *$$target_option*) has_opt=yes; break;; \
    esac; \
  done; \
  test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
subdir = docker/build
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
	$(top_srcdir)/accustomdir.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
	$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES = setup_ci_test.sh
CONFIG_CLEAN_VPATH_FILES =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo "  GEN     " $@;
am__v_GEN_1 = 
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 = 
SOURCES =
DIST_SOURCES =
am__can_run_installinfo = \
  case $$AM_UPDATE_INFO_DIR in \
    n|no|NO) false;; \
    *) (install-info --version) >/dev/null 2>&1;; \
  esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/setup_ci_test.sh.in
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
APBUILD_CC = @APBUILD_CC@
APBUILD_CXX1 = @APBUILD_CXX1@
APBUILD_CXX2 = @APBUILD_CXX2@
APBUILD_STATIC = @APBUILD_STATIC@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BINRELOC_CFLAGS = @BINRELOC_CFLAGS@
BINRELOC_LIBS = @BINRELOC_LIBS@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CODELEVEL = @CODELEVEL@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CXX_ABI = @CXX_ABI@
CYGPATH_W = @CYGPATH_W@
DEBUGLEVEL = @DEBUGLEVEL@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
GREP = @GREP@
HAVE_BASH = @HAVE_BASH@
HAVE_GMAKE = @HAVE_GMAKE@
HAVE_M4 = @HAVE_M4@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBPNG_CFLAGS = @LIBPNG_CFLAGS@
LIBPNG_LIBS = @LIBPNG_LIBS@
LIBS = @LIBS@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
OBJC = @OBJC@
OBJCDEPMODE = @OBJCDEPMODE@
OBJCFLAGS = @OBJCFLAGS@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME := $(shell grep "^PACKAGE_NAME=" context/version.sh | sed -e "s,.*=,,")
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@

#***************************************************************

# variables

# package metadata
PACKAGE_VERSION := $(shell grep "^PACKAGE_VERSION=" context/version.sh | sed -e "s,.*=,,")
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
RANLIB = @RANLIB@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
XMKMF = @XMKMF@
XML2_CFLAGS = @XML2_CFLAGS@
XML2_LIBS = @XML2_LIBS@
X_CFLAGS = @X_CFLAGS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_LIBS = @X_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
ZTHREAD_CONFIG = @ZTHREAD_CONFIG@
ZTHREAD_CXXFLAGS = @ZTHREAD_CXXFLAGS@
ZTHREAD_LIBS = @ZTHREAD_LIBS@
aa_datadir = @aa_datadir@
aa_docdir = @aa_docdir@
aa_infodir = @aa_infodir@
aa_localstatedir = @aa_localstatedir@
aa_logdir = @aa_logdir@
aa_mandir = @aa_mandir@
aa_oldvardir = @aa_oldvardir@
aa_rundir = @aa_rundir@
aa_sysconfdir = @aa_sysconfdir@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_OBJC = @ac_ct_OBJC@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_dedicated = @build_dedicated@
build_os = @build_os@
build_regular = @build_regular@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datadir_suffix = @datadir_suffix@
date_iso = @date_iso@
docdir = @docdir@
docdir_suffix = @docdir_suffix@
docstyle = @docstyle@
enable_desktop = @enable_desktop@
enable_etc = @enable_etc@
enable_initscripts = @enable_initscripts@
enable_migratestate = @enable_migratestate@
enable_multiver = @enable_multiver@
enable_restoreold = @enable_restoreold@
enable_useradd = @enable_useradd@
exec_prefix = @exec_prefix@
executable_suffix = @executable_suffix@
external_uninstall_cmd = @external_uninstall_cmd@
games_suffix_config = @games_suffix_config@
games_suffix_data = @games_suffix_data@
games_suffix_doc = @games_suffix_doc@
games_suffix_var = @games_suffix_var@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir_suffix = @infodir_suffix@
initdir = @initdir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
localstatedir_suffix = @localstatedir_suffix@
logdir = @logdir@
logdir_suffix = @logdir_suffix@
mandir_suffix = @mandir_suffix@
mkdir_p = @mkdir_p@
needdata = @needdata@
oldvardir = @oldvardir@
oldvardir_suffix = @oldvardir_suffix@
prefix = @prefix@
progdir_suffix = @progdir_suffix@
progid = @progid@
progname = @progname@
prognamebase = @prognamebase@
program_transform_name = @program_transform_name@
progtitle = @progtitle@
progtitle_server = @progtitle_server@
progtitle_serverorclient = @progtitle_serverorclient@
protect = @protect@
relocatable = @relocatable@
rundir = @rundir@
rundir_suffix = @rundir_suffix@
sbindir = @sbindir@
scriptdir = @scriptdir@
sharedstatedir = @sharedstatedir@
silent_inc = @silent_inc@
source_date_epoch = @source_date_epoch@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
sysconfdir_suffix = @sysconfdir_suffix@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
version = @version@
PACKAGE_TITLE := $(shell grep "^PACKAGE_TITLE=" context/version.sh | sed -e "s,.*=,,")
PACKAGE_NAME_SUFFIX := $(shell echo $(PACKAGE_NAME) | sed -e "s,.*-,-,")
PACKAGE_TITLE_SUFFIX := $(shell echo $(PACKAGE_TITLE) | sed -e "s,.* , ,")
STEAM_PACKAGE_NAME = retrocycles
STEAM_PACKAGE_TITLE = Retrocycles

# configurations for lean builds not supposed to be installed
CONFIGURE_ARGUMENTS := --disable-uninstall --disable-restoreold --enable-etc --enable-automakedefaults --disable-useradd --disable-sysinstall --disable-initscripts
CONFIGURE_ARGUMENTS_SERVER := --disable-glout --enable-armathentication

# other directories
SCRIPTDIR := ${srcdir}/../scripts
GITS := $(SCRIPTDIR)/.cache/gits

#***************************************************************

# create source tarball
TARBALL := ../../armagetronad-@version@.tar.gz

#***************************************************************

# macOS builds are done without docker
MACOS_BUILD_BUNDLE = "src/macosx/build_bundle.sh"
MACOS_CONFIGURE_BUNDLE = "src/macosx/configure_for_bundle.sh"
MACZIP_CLIENT := $(PACKAGE_NAME)-client-$(PACKAGE_VERSION).macOS.zip
MACZIP_SERVER := $(PACKAGE_NAME)-server-$(PACKAGE_VERSION).macOS.zip

# tarball of appdir
APPTAR_SERVER_32 = $(PACKAGE_NAME)-server_32-$(PACKAGE_VERSION).tbz
APPTAR_SERVER_64 = $(PACKAGE_NAME)-server_64-$(PACKAGE_VERSION).tbz
APPTAR_CLIENT_32 = $(PACKAGE_NAME)-client_32-$(PACKAGE_VERSION).tbz
APPTAR_CLIENT_64 = $(PACKAGE_NAME)-client_64-$(PACKAGE_VERSION).tbz
APPIMAGE_BASENAME := $(shell echo $(PACKAGE_TITLE) | sed -e "s, ,,g")
APPIMAGE_CLIENT_64 := $(APPIMAGE_BASENAME).AppImage
APPIMAGE_SERVER_64 := $(APPIMAGE_BASENAME)Dedicated.AppImage
APPIMAGE_CLIENT_32 := $(APPIMAGE_BASENAME)-32bit.AppImage
APPIMAGE_SERVER_32 := $(APPIMAGE_BASENAME)Dedicated-32bit.AppImage

# windows source zip
WINZIP_SOURCE_NAME := $(PACKAGE_NAME)-source-$(PACKAGE_VERSION)
WINZIP_SOURCE_DIR := proto/$(WINZIP_SOURCE_NAME)
WINZIP_SOURCE := upload/$(WINZIP_SOURCE_NAME).zip

# windows client zip
WINZIP_CLIENT_NAME := $(PACKAGE_NAME)-client-$(PACKAGE_VERSION)
WINZIP_CLIENT_DIR := proto/$(WINZIP_CLIENT_NAME)
WINZIP_CLIENT := upload/$(WINZIP_CLIENT_NAME).win32.zip

# windows server zip
WINZIP_SERVER_NAME := $(PACKAGE_NAME)-server-$(PACKAGE_VERSION)
WINZIP_SERVER_DIR := proto/$(WINZIP_SERVER_NAME)
WINZIP_SERVER := upload/$(WINZIP_SERVER_NAME).win32.zip

# copy installers into upload
WININST_CLIENT_NAME := $(PACKAGE_NAME)-$(PACKAGE_VERSION).win32.exe
WININST_SERVER_NAME := $(PACKAGE_NAME)-dedicated-$(PACKAGE_VERSION).win32.exe
WININST_CLIENT = upload/$(WININST_CLIENT_NAME)
WININST_SERVER = upload/$(WININST_SERVER_NAME)
all: all-am

.SUFFIXES:
$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
	@for dep in $?; do \
	  case '$(am__configure_deps)' in \
	    *$$dep*) \
	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
	        && { if test -f $@; then exit 0; else break; fi; }; \
	      exit 1;; \
	  esac; \
	done; \
	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu docker/build/Makefile'; \
	$(am__cd) $(top_srcdir) && \
	  $(AUTOMAKE) --gnu docker/build/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
	@case '$?' in \
	  *config.status*) \
	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
	  *) \
	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
	esac;

$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh

$(top_srcdir)/configure:  $(am__configure_deps)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
setup_ci_test.sh: $(top_builddir)/config.status $(srcdir)/setup_ci_test.sh.in
	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
tags TAGS:

ctags CTAGS:

cscope cscopelist:


distdir: $(BUILT_SOURCES)
	$(MAKE) $(AM_MAKEFLAGS) distdir-am

distdir-am: $(DISTFILES)
	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
	list='$(DISTFILES)'; \
	  dist_files=`for file in $$list; do echo $$file; done | \
	  sed -e "s|^$$srcdirstrip/||;t" \
	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
	case $$dist_files in \
	  */*) $(MKDIR_P) `echo "$$dist_files" | \
			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
			   sort -u` ;; \
	esac; \
	for file in $$dist_files; do \
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
	  if test -d $$d/$$file; then \
	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
	    if test -d "$(distdir)/$$file"; then \
	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
	    fi; \
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
	    fi; \
	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
	  else \
	    test -f "$(distdir)/$$file" \
	    || cp -p $$d/$$file "$(distdir)/$$file" \
	    || exit 1; \
	  fi; \
	done
check-am: all-am
check: check-am
all-am: Makefile
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am

installcheck: installcheck-am
install-strip:
	if test -z '$(STRIP)'; then \
	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
	      install; \
	else \
	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
	fi
mostlyclean-generic:

clean-generic:

distclean-generic:
	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)

maintainer-clean-generic:
	@echo "This command is intended for maintainers to use"
	@echo "it deletes files that may require special tools to rebuild."
clean-am: clean-generic mostlyclean-am

distclean-am: clean-am distclean-generic

dvi: dvi-am

dvi-am:

html: html-am

html-am:

info: info-am

info-am:

install-data-am:

install-dvi: install-dvi-am

install-dvi-am:

install-exec-am:

install-html: install-html-am

install-html-am:

install-info: install-info-am

install-info-am:

install-man:

install-pdf: install-pdf-am

install-pdf-am:

install-ps: install-ps-am

install-ps-am:

installcheck-am:

maintainer-clean: maintainer-clean-am
	-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

mostlyclean: mostlyclean-am

mostlyclean-am: mostlyclean-generic

pdf: pdf-am

pdf-am:

ps: ps-am

ps-am:

uninstall-am:

.MAKE: install-am install-strip

.PHONY: all all-am check check-am clean clean-generic cscopelist-am \
	ctags-am distclean distclean-generic distdir dvi dvi-am html \
	html-am info info-am install install-am install-data \
	install-data-am install-dvi install-dvi-am install-exec \
	install-exec-am install-html install-html-am install-info \
	install-info-am install-man install-pdf install-pdf-am \
	install-ps install-ps-am install-strip installcheck \
	installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
	pdf-am ps ps-am tags-am uninstall uninstall-am

.PRECIOUS: Makefile

.PHONY: tarball clean distclean source free closed full all

# We want everything deleted if something bad happens
.DELETE_ON_ERROR:

default:
	echo "Nothing generic to do."

# individual targets for split jobs
CI_prepare: gits_artifacts.tag source make_ci.sh rootcontext.64
CI_linux_server_32: appimage_server_32.tag apptar_server_32.tag
CI_linux_client_32: appimage_client_32.tag apptar_client_32.tag
CI_linux_server_64: appimage_server_64.tag apptar_server_64.tag
CI_linux_client_64: appimage_client_64.tag apptar_client_64.tag
CI_windows: winzip.tag windows.tag
CI_debtest: debtest.tag
CI_linux_steam: steamdirs/steam_linux
CI_windows_steam: steamdirs/steam_windows

# full open source builds
free.tag: appimage.tag apptar.tag sourcetar.tag
	touch $@
free: free.tag

# builds for non-open source systems/environments
closed_regular.tag: windows.tag winzip.tag
	touch $@
closed_regular: closed.tag
closed_steam.tag: steam_windows.tag steam_linux.tag
	touch $@
closed_steam: closed_steam.tag
closed.tag: closed_steam.tag closed_regular.tag
	touch $@
closed: closed.tag

# closed comes first because windows builds take the longest and are not internally parallelized
full.tag: result.winsource_32 result.winsource_steam closed.tag free.tag
	touch $@
full: full.tag

# what to build from GitLab CI, divided into stages
CI_base.tag: gits.tag source.tag result.build_server_32 result.build_client_64 context.64
	touch $@

# minimal expected build to be packable
CI_pack.tag: gits_artifacts.tag source.tag CI_base.tag free.tag upload/PATCHNOTES.md upload/CHANGELOG.md upload/RELEASENOTES.md
	touch $@

# all windows builds
CI_windows.tag: CI_base.tag steam_windows.tag closed_regular.tag
	touch $@

# all free linux builds (so, no steam)
CI_free.tag: CI_base.tag free.tag
	touch $@

# (OBSOLETE) targets for CI merge tests, a bit leaner than a full build
CI_merge.tag: windows.tag debtest.tag
	touch $@
CI_merge: CI_merge.tag
CI_merge_nodeb.tag: windows.tag CI_base.tag
	touch $@
CI_merge_nodeb: CI_merge_nodeb.tag

# all builds
#CI.tag: CI_pack.tag apptar_server_64.tag
CI.tag: CI_windows.tag CI_free.tag full.tag CI_pack.tag
	touch $@

CI_base: CI_base.tag
CI: CI.tag

# all tests
test: debtest.tag appimagetests.tag CI.tag deploy_base.tag

all:	default

dockertest.tag:
	cp ${srcdir}/fakerelease_proto.sh .
	@echo "Testing whether 'docker' works..."
	if which docker; then docker help > /dev/null; fi
	echo > $@

tarwrapper.sh: ${top_srcdir}/docker/scripts/tarwrapper.sh
	ln -s $< $@

# dump CI data and variables determined from it
CI_INFO: ${srcdir}/../scripts/brand.sh
	. ${srcdir}/../scripts/brand.sh @top_srcdir@ && \
	echo SERIES=$${SERIES} > $@ && \
	echo PROGRAM_NAME=$${PROGRAM_NAME} >> $@ && \
	echo PROGRAM_TITLE=$${PROGRAM_TITLE} >> $@ && \
	echo CI_COMMIT_REF_PROTECTED=$${CI_COMMIT_REF_PROTECTED} >> $@ && \
	echo CI_COMMIT_SHA=$${CI_COMMIT_SHA} >> $@ && \
	echo CI_RELEASE_YEAR=$${CI_RELEASE_YEAR} >> $@ && \
	echo CI_COMMIT_REF_NAME=$${CI_COMMIT_REF_NAME} >> $@

.PRECIOUS: CI_INFO

#***************************************************************

upload/.tag:
	mkdir -p upload
	echo > $@
proto.tag:
	mkdir -p proto
	echo > $@

make_ci.sh: ${srcdir}/make_ci.sh.in
	cp $< $@

context/version.sh: ${srcdir}/context/version.sh.in
	cd ../../; ./config.status docker/build/context/version.sh

../deploy/targets.sh: ${srcdir}/../deploy/targets.sh.in
	cd ../../; ./config.status docker/deploy/targets.sh
$(TARBALL):
	$(MAKE) -C ../../ dist GZIP_ENV=""
tarball: $(TARBALL)

# unpack source tarball
source.tag: $(TARBALL) dockertest.tag
	rm -rf source armagetronad-@version@
	tar -xzf $(TARBALL)
	mv armagetronad-@version@ source
	echo > $@
source: source.tag

# rebranded tarball for upload
upload/$(PACKAGE_NAME)-@version@.tbz: $(TARBALL) upload/.tag tarwrapper.sh
	rm -rf $@ repack
	mkdir -p repack_1 repack_2
	cd repack_1; tar -xzf ../$(TARBALL)
	mv repack_1/armagetronad-@version@ repack_2/$(PACKAGE_NAME)-@version@
	cd repack_2; ../tarwrapper.sh -cjf repacked.tbz $(PACKAGE_NAME)-@version@
	mv repack_2/repacked.tbz $@
	rm -rf repack_1 repack_2

sourcetar.tag: upload/$(PACKAGE_NAME)-@version@.tbz
	touch $@

# foreign gits (in the cache)
gits.tag: $(SCRIPTDIR)/fix_gits.sh
	$(SCRIPTDIR)/fix_gits.sh
	echo > $@

# bits of gits we need in artifacts
gits_artifacts.tag: gits.tag
	rm -rf gits
	mkdir -p gits
	mkdir -p gits/steam
	cp -a ${GITS}/steam-art/good/title.png gits/steam
	echo > $@

upload/PATCHNOTES.md: sourcetar.tag upload/.tag
	${top_srcdir}/batch/make/patchnotes.py ${top_srcdir} ${top_srcdir}/CHANGELOG_FROZEN.md armagetronad armagetronad -p > $@

upload/CHANGELOG.md: sourcetar.tag upload/.tag
	${top_srcdir}/batch/make/patchnotes.py ${top_srcdir} ${top_srcdir}/CHANGELOG_FROZEN.md armagetronad armagetronad > $@

upload/RELEASENOTES.md: ${src_dir}../deploy/RELEASENOTES.md upload/.tag
	cp $< $@

#***************************************************************

# generic context with source
# technically everything here depends on the Makefile, but enforcing rebuilds on all
# Makefile edits is too annoying during develop/test cycles.
rootcontext.64: source.tag ${srcdir}/*.sh ${srcdir}/context/build.sh #Makefile
	${srcdir}/prepare_context.sh $@.dir source ${srcdir}/context/build.sh
	echo "armabuild_64" > $@.dir/image
	echo > $@

context.64: rootcontext.64
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	echo > $@

#***************************************************************

# switch container to use to 32 bit
context.32: context.64
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	rm $@.dir/image
	echo "armabuild_32" > $@.dir/image
	echo > $@

# switch container to use to steam SDK, rebrand
context.steam: context.64 gits_artifacts.tag
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	rm $@.dir/image
	echo "armasteam_64" > $@.dir/image
#	rebrand
	rm -f $@.dir/version.sh # required because the source and dest are hard links to the same file originally
	sed < $<.dir/version.sh > $@.dir/version.sh -e s/PACKAGE_NAME=armagetronad/PACKAGE_NAME=$(STEAM_PACKAGE_TITLE)/ -e s/PACKAGE_TITLE=\"Armagetron\ Advanced/PACKAGE_TITLE=\"$(STEAM_PACKAGE_TITLE)/ -e s/PACKAGE_TITLE=\"Armagetron/PACKAGE_TITLE=\"$(STEAM_PACKAGE_TITLE)/
# 	no remotely adult stuff
	rm -f $@.dir/source/src/engine/ePlayer.cpp
	sed < $<.dir/source/src/engine/ePlayer.cpp > $@.dir/source/src/engine/ePlayer.cpp -e "s/pr0n/cat videos/"
#   install alternative title, adapt sources
	cp gits/steam/title.png $@.dir/source/textures/
	for f in source/src/tron/gLogo.cpp source/Makefile.am; do \
		rm -f $@.dir/$$f; \
		sed < $<.dir/$$f > $@.dir/$$f -e "s,textures/title.jpg,textures/title.png,"; \
	done
	cd $@.dir/source; ./bootstrap.sh
#   done
	echo > $@

# add debian/ubuntu build info for release %. Requires GPG key from ~/.gnupg
context.debsrc_%: rootcontext.64 ${srcdir}/rebrand_debian_core.sh ${srcdir}/debian_source.sh gits_artifacts.tag $(TARBALL)
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' $(TARBALL) ${srcdir}/rebrand_debian_core.sh ${srcdir}/debian_source.sh ${srcdir}/context/debian
	if test -r  ../deploy/secrets/sec.gpg; then cp -lrf ../deploy/secrets/*.gpg $@.dir/; fi
	rm -f $@.dir/image
	echo "armadeb_64" > $@.dir/image
	echo > $@
result.debsrc_%: context.debsrc_%
	+$(srcdir)/context_to_result.sh $@.dir ./debian_source.sh $*
	echo > $@

# test build a debian package (with a really old ubuntu codename)
context.debsrc_test: context.debsrc_dapper
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
#	extract fake secrets
	base64 -d < ${srcdir}/../deploy/anonymous_secrets.b64 | tar -xjf - --one-top-level=$@.dir
#   reverse to pack: tar -cjf - secrets | base64 > anonymous_secrets.b64 
	mv $@.dir/secrets/* $@.dir
	rmdir $@.dir/secrets/
	echo > $@
context.debtest: result.debsrc_test
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	echo "cd source && debuild -i -us -uc -b && rm -rf *" > $@.dir/build_deb.sh
	chmod +x $@.dir/build_deb.sh
	echo > $@

result.debtest: context.debtest
	+$(srcdir)/context_to_result.sh $@.dir bash ./build_deb.sh
	echo > $@

debtest.tag: result.debtest
	echo > $@

# switch container to use alpine
context.test: rootcontext.64
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	rm $@.dir/image
	echo "armalpine_32" > $@.dir/image
	echo > $@

macOS/steam_build.tag: context.steam #macOS/client_build.tag #Makefile
	mkdir -p macOS/steam
	. context.steam.dir/version.sh && cd macOS/steam && ../../$<.dir/source/$(MACOS_CONFIGURE_BUNDLE) progname="$${PACKAGE_NAME}-${PACKAGE_VERSION}" progtitle="$${PACKAGE_TITLE}" && ${MAKE}
	echo > $@

macOS/server_build.tag: context.64 #smacOS/client_build.tag #Makefile
	mkdir -p macOS/server
	cd macOS/server && ../../$<.dir/source/$(MACOS_CONFIGURE_BUNDLE) --disable-glout && ${MAKE}
	echo > $@

macOS/client_build.tag: context.64 #Makefile
	mkdir -p macOS/client
	cd macOS/client && ../../$<.dir/source/$(MACOS_CONFIGURE_BUNDLE) && ${MAKE}
	echo > $@

macOS/%_sign.tag: macOS/%_build.tag #Makefile
	@echo /////////////////////////////////////////
	@echo // Bundle, sign and notarize macOS $*
	@echo /////////////////////////////////////////
	rm -rf macOS/$*/*.app macOS/$*/*.zip macOS/$*/*.dmg 
	cd macOS/$* && SKIP_PART_2=yes bash ${MACOS_BUILD_BUNDLE}
	echo > $@

macOS/%.tag: macOS/%_sign.tag upload/.tag #Makefile
	@echo /////////////////////////////////
	@echo // Staple and pack macOS $*
	@echo /////////////////////////////////
	cd macOS/$* && SKIP_PART_1=yes bash ${MACOS_BUILD_BUNDLE}
	cp macOS/$*/*.dmg macOS/$*/*.macOS.zip upload/
	echo > $@

#macOS/server_sign.tag: macOS/steam_sign.tag
#macOS/client_sign.tag: macOS/server_sign.tag
macOS/server.tag: macOS/steam.tag
macOS/client.tag: macOS/server.tag

.PRECIOUS: macOS/server_build.tag macOS/client_build.tag macOS/steam_build.tag
.PRECIOUS: macOS/server_sign.tag macOS/client_sign.tag macOS/steam_sign.tag
.PRECIOUS: macOS/server.tag macOS/client.tag macOS/steam.tag

macOS_build: macOS/client_build.tag macOS/server_build.tag macOS/steam_build.tag
macOS: macOS/client.tag macOS/server.tag macOS/steam.tag
upload/${MACZIP_CLIENT}: macOS/client.tag
upload/${MACZIP_SERVER}: macOS/server.tag

#***************************************************************

context.build_server_%: context.%
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	echo "server" > $@.dir/serverclient
	echo > $@

context.build_client_%: context.%
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	echo "client" > $@.dir/serverclient
	echo > $@

.PRECIOUS: context.build_server_32 context.build_client_32  context.build_server_64 context.build_client_64

#***************************************************************

# server build for further processing
result.build_server_%: context.build_server_%
	+$(srcdir)/context_to_result.sh $@.dir ./build.sh $(CONFIGURE_ARGUMENTS) $(CONFIGURE_ARGUMENTS_SERVER)
	echo > $@

# client build for further processing
result.build_client_%: context.build_client_%
	+$(srcdir)/context_to_result.sh $@.dir ./build.sh $(CONFIGURE_ARGUMENTS)
	echo > $@

.PRECIOUS: result.build_server_32 result.build_client_32  result.build_server_64 result.build_client_64

#***************************************************************

# portable application directories
context.appdir_%: result.build_% ${srcdir}/context/portable/* ${srcdir}/context/appdir.sh ${srcdir}/context/steam.sh
	${srcdir}/prepare_context.sh $@.dir $<.dir/* ${srcdir}/context/portable ${srcdir}/context/appdir.sh ${srcdir}/context/steam.sh
	echo > $@

result.appdir_%: context.appdir_%
	+$(srcdir)/context_to_result.sh $@.dir ./appdir.sh
	echo > $@

# use different script for steam builds, rearranging some things
result.appdir_%_steam: context.appdir_%_steam
	+$(srcdir)/context_to_result.sh $@.dir ./steam.sh
	echo > $@
apptar_server_32.tag: upload/$(APPTAR_SERVER_32)
	echo > $@
apptar_server_64.tag: upload/$(APPTAR_SERVER_64)
	echo > $@
apptar_client_32.tag: upload/$(APPTAR_CLIENT_32)
	echo > $@
apptar_client_64.tag: upload/$(APPTAR_CLIENT_64)
	echo > $@

upload/$(APPTAR_SERVER_32): result.appdir_server_32 upload/.tag tarwrapper.sh
	cd $<.dir/appdir; ../../tarwrapper.sh -cjf ../../$@ .
upload/$(APPTAR_CLIENT_32): result.appdir_client_32 upload/.tag tarwrapper.sh
	cd $<.dir/appdir; ../../tarwrapper.sh -cjf ../../$@ .
upload/$(APPTAR_SERVER_64): result.appdir_server_64 upload/.tag tarwrapper.sh
	cd $<.dir/appdir; ../../tarwrapper.sh -cjf ../../$@ .
upload/$(APPTAR_CLIENT_64): result.appdir_client_64 upload/.tag tarwrapper.sh
	cd $<.dir/appdir; ../../tarwrapper.sh -cjf ../../$@ .

apptar.tag: apptar_server_32.tag apptar_client_32.tag apptar_server_64.tag apptar_client_64.tag upload/$(APPTAR_SERVER_32) upload/$(APPTAR_SERVER_64) upload/$(APPTAR_CLIENT_32) upload/$(APPTAR_CLIENT_64)
	echo > $@
apptar: apptar.tag

.PHONY: appdir apptar

.PRECIOUS: context.apptar_server_32 context.apptar_client_32  context.apptar_server_64 context.apptar_client_64

.PRECIOUS: context.appdir_server_32 context.appdir_client_32  context.appdir_server_64 context.appdir_client_64

#***************************************************************

# Docker image building
build_docker.tag: rootcontext.64 ${srcdir}/../deploy/deploy_docker.sh CI_INFO
	DOCKER_NODEPLOY="nodeploy" ${srcdir}/../deploy/deploy_docker.sh $<.dir/source
	echo > $@

deploy_docker.tag: rootcontext.64 ${srcdir}/../deploy/deploy_docker.sh CI_INFO
	${srcdir}/../deploy/deploy_docker.sh $<.dir/source
	echo > $@

#***************************************************************

# AppImages with optional signing
context.appimage_%: upload/$(PACKAGE_NAME)-%-$(PACKAGE_VERSION).tbz context/version.sh ${srcdir}/context/appimage.sh gits.tag
	${srcdir}/prepare_context.sh $@.dir ${srcdir}/context/appimage.sh $(GITS)/pkg2appimage
	mkdir -p $@.dir/appdir/ && tar -jxf $< -C $@.dir/appdir/
	echo $* | sed -e 's,.*_,armabuild_,' > $@.dir/image
	if test -r  ../deploy/secrets/sec.gpg; then cp -lrf ../deploy/secrets/*.gpg $@.dir/; fi
	echo > $@

result.appimage_client_64: context.appimage_client_64
	+$(srcdir)/context_to_result.sh $@.dir "./appimage.sh ${APPIMAGE_CLIENT_64}"
	echo > $@
result.appimage_server_64: context.appimage_server_64
	+$(srcdir)/context_to_result.sh $@.dir "./appimage.sh ${APPIMAGE_SERVER_64}"
	echo > $@
result.appimage_client_32: context.appimage_client_32
	+$(srcdir)/context_to_result.sh $@.dir "./appimage.sh ${APPIMAGE_CLIENT_32}"
	echo > $@
result.appimage_server_32: context.appimage_server_32
	+$(srcdir)/context_to_result.sh $@.dir "./appimage.sh ${APPIMAGE_SERVER_32}"
	echo > $@

upload/$(APPIMAGE_CLIENT_64): result.appimage_client_64 upload/.tag
	cp $<.dir/`basename $@` $@
	cp $<.dir/`basename $@`.zsync $@.zsync
upload/$(APPIMAGE_SERVER_64): result.appimage_server_64 upload/.tag
	cp $<.dir/`basename $@` $@
	cp $<.dir/`basename $@`.zsync $@.zsync
upload/$(APPIMAGE_CLIENT_32): result.appimage_client_32 upload/.tag
	cp $<.dir/`basename $@` $@
	cp $<.dir/`basename $@`.zsync $@.zsync
upload/$(APPIMAGE_SERVER_32): result.appimage_server_32 upload/.tag
	cp $<.dir/`basename $@` $@
	cp $<.dir/`basename $@`.zsync $@.zsync

appimage_client_64.tag: upload/$(APPIMAGE_CLIENT_64)
	echo > $@
appimage_server_64.tag: upload/$(APPIMAGE_SERVER_64)
	echo > $@
appimage_client_32.tag: upload/$(APPIMAGE_CLIENT_32)
	echo > $@
appimage_server_32.tag: upload/$(APPIMAGE_SERVER_32)
	echo > $@

appimage.tag: appimage_client_64.tag appimage_server_64.tag appimage_client_32.tag appimage_server_32.tag
	echo > $@

.PRECIOUS: context.appimage_server_32 context.appimage_client_32 context.appimage_server_64 context.appimage_client_64

#***************************************************************

# appimage tests; test scripts are in contest/tests/Dockerfile.*

test.appimage_server_64_ubuntu_latest: upload/$(APPIMAGE_SERVER_64)
test.appimage_server_64_ubuntu_oldest: upload/$(APPIMAGE_SERVER_64)
test.appimage_client_64_ubuntu_latest: upload/$(APPIMAGE_CLIENT_64)
test.appimage_client_64_ubuntu_oldest: upload/$(APPIMAGE_CLIENT_64)

test.appimage_server_64_ubuntu_rolling: upload/$(APPIMAGE_SERVER_64)
test.appimage_client_64_ubuntu_rolling: upload/$(APPIMAGE_CLIENT_64)

test.appimage_client_64_ubuntu_latest_skewed: upload/$(APPIMAGE_CLIENT_64)
test.appimage_client_64_ubuntu_oldest_skewed: upload/$(APPIMAGE_CLIENT_64)

test.appimage_server_64_fedora_latest: upload/$(APPIMAGE_SERVER_64)
test.appimage_server_64_fedora_oldest: upload/$(APPIMAGE_SERVER_64)
test.appimage_client_64_fedora_latest: upload/$(APPIMAGE_CLIENT_64)
test.appimage_client_64_fedora_oldest: upload/$(APPIMAGE_CLIENT_64)

test.appimage_server_32_debian_latest: upload/$(APPIMAGE_SERVER_32)
test.appimage_server_32_debian_oldest: upload/$(APPIMAGE_SERVER_32)
test.appimage_client_32_debian_latest: upload/$(APPIMAGE_CLIENT_32)
test.appimage_client_32_debian_oldest: upload/$(APPIMAGE_CLIENT_32)

test.%: context/tests/Dockerfile.%
	rm -rf $@.dir
	mkdir -p $@.dir
	cp $^ $@.dir
	cd $@.dir; docker rmi $*:last || true
	cd $@.dir; docker tag $*:latest $*:last || true
	cd $@.dir; docker build . -f Dockerfile.* --pull -t $*:latest
	cd $@.dir; docker rmi $*:last || true
	echo > $@

appimagetests.tag: \
	test.appimage_server_64_ubuntu_latest \
	test.appimage_server_64_ubuntu_oldest \
	test.appimage_client_64_ubuntu_latest \
	test.appimage_client_64_ubuntu_oldest \
	test.appimage_client_64_ubuntu_latest_skewed \
	test.appimage_client_64_ubuntu_oldest_skewed \
	test.appimage_server_64_ubuntu_rolling \
	test.appimage_client_64_ubuntu_rolling \
	test.appimage_server_64_fedora_latest \
	test.appimage_server_64_fedora_oldest \
	test.appimage_client_64_fedora_latest \
	test.appimage_client_64_fedora_oldest \
	test.appimage_server_32_debian_latest \
	test.appimage_server_32_debian_oldest \
	test.appimage_client_32_debian_latest \
	test.appimage_client_32_debian_oldest \
	upload/.tag
	echo > $@

appimagetests: appimagetests.tag

appimagetests_ci.tag: \
	test.appimage_client_64_ubuntu_latest \
	test.appimage_client_64_ubuntu_oldest_skewed \
	test.appimage_client_64_fedora_latest \
	test.appimage_server_64_fedora_oldest \
	test.appimage_client_64_fedora_oldest \
	test.appimage_server_32_debian_oldest \
	test.appimage_client_32_debian_oldest \
	upload/.tag
	echo > $@

appimagetests_ci: appimagetests_ci.tag

appimagetests_extra.tag: \
	test.appimage_server_64_ubuntu_rolling \
	test.appimage_client_64_ubuntu_rolling \
	upload/.tag
	echo > $@

appimagetests_extra: appimagetests_extra.tag

#***************************************************************

# windows source
context.winsource_%: result.build_server_% ${srcdir}/context/winsource.sh gits.tag
	${srcdir}/prepare_context.sh $@.dir $<.dir/* ${srcdir}/context/winsource.sh $(GITS)/codeblocks
	echo > $@
result.winsource_%: context.winsource_%
	+$(srcdir)/context_to_result.sh $@.dir ./winsource.sh
	echo > $@

# windows build
context.winbuild_%: result.winsource_% ${srcdir}/context/winbuild.sh gits.tag
	${srcdir}/prepare_context.sh $@.dir $<.dir/* ${srcdir}/context/winbuild.sh $(GITS)/winlibs
	rm $@.dir/image
	echo "armawineblocks" > $@.dir/image
	echo > $@
result.winbuild_%: context.winbuild_%
	+$(srcdir)/context_to_result.sh $@.dir ./winbuild.sh
	echo > $@

# windows installers
context.wininst_%: result.winbuild_% ${srcdir}/context/wininst.sh
	${srcdir}/prepare_context.sh $@.dir $<.dir/* ${srcdir}/context/wininst.sh
	rm $@.dir/image
	echo "armawineblocks" > $@.dir/image
	echo > $@
result.wininst_%: context.wininst_%
	+$(srcdir)/context_to_result.sh $@.dir ./wininst.sh
	echo > $@
$(WINZIP_SOURCE_DIR): result.winsource_32 proto.tag Makefile
	rm -rf $@.dir
	cp -al $<.dir/winsource $@.dir
	echo > $@
$(WINZIP_SOURCE): $(WINZIP_SOURCE_DIR) upload/.tag
	cd $(WINZIP_SOURCE_DIR).dir; zip -9 -r ../../$(WINZIP_SOURCE) *
winzip_source.tag: $(WINZIP_SOURCE)
	echo > $@
$(WINZIP_CLIENT_DIR): result.winbuild_32 proto.tag Makefile
	rm -rf $@.dir
	cp -al $<.dir/dist $@.dir
	rm $@.dir/$(PACKAGE_NAME)_dedicated.exe $@.dir/*.nsi $@.dir/banner* $@.dir/INSTALL.txt
	echo > $@
$(WINZIP_CLIENT): $(WINZIP_CLIENT_DIR) upload/.tag
	cd $(WINZIP_CLIENT_DIR).dir; zip -9 -r ../../$(WINZIP_CLIENT) *
winzip_client.tag: $(WINZIP_CLIENT)
	echo > $@
$(WINZIP_SERVER_DIR): result.winbuild_32 proto.tag Makefile
	rm -rf $@.dir
	cp -al $<.dir/dist $@.dir
	rm -r $@.dir/$(PACKAGE_NAME).exe $@.dir/*.nsi $@.dir/banner* \
		$@.dir/INSTALL.txt $@.dir/models $@.dir/sound $@.dir/textures \
		$@.dir/SDL* $@.dir/libpng* $@.dir/jpeg*
	echo > $@
$(WINZIP_SERVER): $(WINZIP_SERVER_DIR) upload/.tag
	cd $(WINZIP_SERVER_DIR).dir; zip -9 -r ../../$(WINZIP_SERVER) *
winzip_server.tag: $(WINZIP_SERVER)
	echo > $@

winzip.tag: winzip_server.tag winzip_client.tag winzip_source.tag
	echo > $@
$(WININST_CLIENT): result.wininst_32 upload/.tag
	rm -f $@
	cp $<.dir/$(WININST_CLIENT_NAME) $@
$(WININST_SERVER): result.wininst_32 upload/.tag
	rm -f $@
	cp $<.dir/$(WININST_SERVER_NAME) $@
windows.tag: $(WININST_CLIENT) $(WININST_SERVER)
	echo > $@

# prerequisites for zeroinstall
zeroinstall.tag: winzip.tag apptar.tag
	touch $@
zeroinstall: zeroinstall.tag

.PHONY: windows winzip_client winzip_server zeroinstall

.PRECIOUS: context.wininst_32 context.winbuild_32 context.winsource_32

#***************************************************************

steamdirs/.tag:
	mkdir -p steamdirs
	echo > $@

# steam packaging
steamdirs/steam_linux: result.appdir_server_steam result.appdir_client_steam steamdirs/.tag
	rm -rf $@.dir
	cp -al $<.dir/appdir $@.dir
	cp -al result.appdir_client_steam.dir/appdir/* $@.dir/
	echo > $@

steamdirs/steam_windows: result.winbuild_steam steamdirs/.tag ${srcdir}/context/steam/windows/*
	rm -rf $@.dir
	cp -al $<.dir/dist $@.dir
	mv $@.dir/*dedicated.exe $@.dir/DEDICATED.hex
	mv $@.dir/*.exe $@.dir/CLIENT.hex
	mv $@.dir/CLIENT.hex $@.dir/$(STEAM_PACKAGE_TITLE).exe
	mv $@.dir/DEDICATED.hex $@.dir/$(STEAM_PACKAGE_TITLE)_Dedicated.exe
	cp -al ${srcdir}/context/steam/windows/* $@.dir/
	rm -rf $@.dir/*.nsi
	rm -rf $@.dir/*.url
	rm -rf $@.dir/banner*
	echo > $@

steamdirs/steam_macos: macOS/steam.tag steamdirs/.tag
	rm -rf $@.dir
	mkdir -p $@.dir
	cd $@.dir; unzip ../../upload/${STEAM_PACKAGE_TITLE}*-client-$(PACKAGE_VERSION).macOS.zip
	mv $@.dir/*.app $@.dir/CLIENT.app
	mv $@.dir/CLIENT.app $@.dir/${STEAM_PACKAGE_TITLE}.app
	echo > $@

steam_linux.tag: steamdirs/steam_linux result.appdir_client_steam result.appdir_server_steam
	echo > $@
steam_windows.tag: steamdirs/steam_windows result.winbuild_steam
	echo > $@
steam_macos.tag: steamdirs/steam_macos
	echo > $@

steam.tag: steam_windows.tag steam_linux.tag steam_macos.tag
	echo > $@
.PHONY: steam steam_windows steam_linux

.PRECIOUS:  context.build_client_steam result.build_client_steam context.appdir_client_steam result.build_server_steam context.build_server_steam context.appdir_server_steam context.winbuild_steam context.winsource_steam

#***************************************************************
# Reformat .md files

context.reformat: rootcontext.64 CI_pack.tag ${srcdir}/context/reformat.sh
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' upload/*.md ${srcdir}/context/reformat.sh
	rm -f $@.dir/image
	echo "armadeploy_64" > $@.dir/image
	echo > $@
result.reformat: context.reformat
	+$(srcdir)/context_to_result.sh $@.dir ./reformat.sh $*
	echo > $@

reformat.tag: result.reformat
	cp -a $<.dir/*.txt upload/
	cp -a $<.dir/*.html upload/
	echo > $@

#***************************************************************

# for testing, we want minimal builds before any deployment
# in production, the CI solution is responsible for having built
# everything not explicitly required here
deploy_base.tag: CI_pack.tag debtest.tag reformat.tag ../deploy/targets.sh
	echo > $@
deploy_base: deploy_base.tag

# out of our control deploy targets that break from time to time; the whole deploy process needs to be delayed if they fail
deploy_essential: result.deploy_lp result.deploy_scp
deploy_external: deploy_essential

# targets in our control
deploy_ours: result.deploy_zi result.deploy_download

context.deploy_base_%: rootcontext.64 deploy_base.tag ${srcdir}/../deploy/deploy_%.sh ${srcdir}/../deploy/wait_for_upload.sh ../deploy/* CI_INFO
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' upload ../deploy/'*' ${srcdir}/../deploy/deploy_$*.sh ${srcdir}/../deploy/wait_for_upload.sh CI_INFO
	echo > $@
context.deploy_%: context.deploy_base_%
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*'
	echo > $@
result.deploy_%: context.deploy_%
	+$(srcdir)/context_to_result.sh $@.dir ./deploy_$*.sh
	echo > $@

# special case steam: run in steamcmd image
context.deploy_steam: context.deploy_base_steam ${srcdir}/../deploy/steamcontentbuilder/*/* steam.tag
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' ${srcdir}/../deploy/steamcontentbuilder
	sed -i $@.dir/steamcontentbuilder/scripts/app_build_1306180.vdf -e "s/BUILD_DESCRIPTION/$(STEAM_PACKAGE_TITLE)$(PACKAGE_TITLE_SUFFIX) $(PACKAGE_VERSION)/"
	mkdir -p $@.dir/steamcontentbuilder/content $@.dir/steamcontentbuilder/output
	cp -al steamdirs/steam_windows.dir $@.dir/steamcontentbuilder/content/steam_windows
	cp -al steamdirs/steam_linux.dir $@.dir/steamcontentbuilder/content/steam_linux
	cp -al steamdirs/steam_macos.dir $@.dir/steamcontentbuilder/content/steam_macos
	rm -rf $@.dir/upload
	rm -f $@.dir/image
	echo "steamcmd" > $@.dir/image
	echo > $@

# special case steam: obtain steam guard unlock data
context.steam_guard: rootcontext.64 ${srcdir}/prepare_context.sh ${srcdir}/../deploy/steamcontentbuilder/*/* ${srcdir}/../deploy/*steam_guard*.sh CI_INFO Makefile
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' ../deploy/'*' ${srcdir}/../deploy/steamcontentbuilder ${srcdir}/../deploy/*steam_guard*.sh CI_INFO
	mkdir -p $@.dir/steamcontentbuilder/content $@.dir/steamcontentbuilder/output
	rm -rf $@.dir/upload
	rm -f $@.dir/image
	echo "steamcmd" > $@.dir/image
	echo > $@

result.steam_guard: context.steam_guard
	$(srcdir)/context_to_result.sh $@.dir ./obtain_steam_guard_1.sh
	echo "Enter Steam Guard Code : " && read STEAM_GUARD_CODE && echo "STEAM_GUARD_CODE=$${STEAM_GUARD_CODE}" > ./context.steam_guard.dir/secrets/steamguard.sh
	$(srcdir)/context_to_result.sh $@.dir ./obtain_steam_guard_2.sh
	echo > $@

steam_guard: result.steam_guard
	scp result.steam_guard.dir/output/config.vdf armadeploy@builder.armagetronad.org:~/secrets/
	echo > $@

context.deploy_gitlab: rootcontext.64 deploy_base.tag ../deploy/* ${srcdir}/../deploy/deploy_gitlab.sh CI_INFO
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' upload ../deploy/'*' ${srcdir}/../deploy/deploy_gitlab.sh CI_INFO
	echo "#/bin/bash" > $@.dir/CI_INFO_DEPLOY_GITLAB
	echo "CI_JOB_TOKEN=${CI_JOB_TOKEN}" >> $@.dir/CI_INFO_DEPLOY_GITLAB
	echo "CI_API_V4_URL=${CI_API_V4_URL}" >> $@.dir/CI_INFO_DEPLOY_GITLAB
	echo "CI_PROJECT_ID=${CI_PROJECT_ID}" >> $@.dir/CI_INFO_DEPLOY_GITLAB
	chmod 755 $@.dir/CI_INFO_DEPLOY_GITLAB
	echo > $@

context.deploy_ppa_%: result.debsrc_% ${srcdir}/../deploy/deploy_ppa.sh ../deploy/targets.sh CI_INFO
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' ${srcdir}/../deploy/deploy_ppa.sh ../deploy/targets.sh ../deploy/secrets/*.gpg CI_INFO
	echo > $@
result.deploy_ppa_%: context.deploy_ppa_%
	+$(srcdir)/context_to_result.sh $@.dir ./deploy_ppa.sh $*
	echo > $@

# deploy for launchpad needs armadeb image
context.deploy_lp: context.deploy_base_lp ${srcdir}/../deploy/lp-project-upload
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' ${srcdir}/../deploy/lp-project-upload
	rm -f $@.dir/image
	echo "armadeb_64" > $@.dir/image
	echo > $@

context.update_zi: context.deploy_base_zeroinstall ${srcdir}/../deploy/*_zeroinstall.sh
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' ${srcdir}/../deploy/*_zeroinstall.sh
	rm -f $@.dir/image
	echo "armadeploy_64" > $@.dir/image
	echo > $@
result.update_zi: context.update_zi
	+$(srcdir)/context_to_result.sh $@.dir ./update_zeroinstall.sh
	echo > $@
context.deploy_zi: context.deploy_base_zeroinstall result.update_zi ${srcdir}/../deploy/*_zeroinstall.sh
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' result.update_zi.dir/zeroinstall ${srcdir}/../deploy/*_zeroinstall.sh
	rm -f $@.dir/image
	echo "armadeploy_64" > $@.dir/image
	echo > $@
result.deploy_zi: context.deploy_zi result.deploy_download
	+$(srcdir)/context_to_result.sh $@.dir ./deploy_zeroinstall.sh
	echo > $@

context.deploy_fp: context.deploy_base_flatpak ${srcdir}/../deploy/*_flatpak.sh
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' ${srcdir}/../deploy/*_flatpak.sh
	rm -f $@.dir/image
	echo "armadeploy_64" > $@.dir/image
	echo > $@
result.deploy_fp: context.deploy_fp
	+$(srcdir)/context_to_result.sh $@.dir ./deploy_flatpak.sh
	echo > $@

context.deploy_itch: context.deploy_base_itch ${srcdir}/../deploy/*_itch.sh upload/$(APPTAR_CLIENT_64) upload/$(APPTAR_CLIENT_32) $(WINZIP_CLIENT) upload/${MACZIP_CLIENT}
	${srcdir}/prepare_context.sh $@.dir $<.dir/'*' ${srcdir}/../deploy/*_itch.sh
	mkdir -p $@.dir/appdir_macos; cd $@.dir/appdir_macos; unzip ../../upload/$(MACZIP_CLIENT); mv ${PACKAGE_TITLE}.app ${PACKAGE_TITLE}" ${PACKAGE_VERSION}".app
	mkdir -p $@.dir/appdir_linux_64; cd $@.dir/appdir_linux_64; tar -xjf ../../upload/$(APPTAR_CLIENT_64)
	mkdir -p $@.dir/appdir_linux_32; cd $@.dir/appdir_linux_32; tar -xjf ../../upload/$(APPTAR_CLIENT_32)
	mkdir -p $@.dir/appdir_windows; cd $@.dir/appdir_windows; unzip ../../$(WINZIP_CLIENT)
	rm -f $@.dir/image
	echo "armadeploy_64" > $@.dir/image
	echo > $@
result.deploy_itch: context.deploy_itch
	+$(srcdir)/context_to_result.sh $@.dir ./deploy_itch.sh
	echo > $@

# individual deploy targets
deploy_lp: result.deploy_lp
deploy_scp: result.deploy_scp
deploy_gitlab: result.deploy_gitlab
deploy_steam: result.deploy_steam
deploy_zi: result.deploy_zi
deploy_fp: result.deploy_fp
deploy_download: result.deploy_download
deploy_itch: result.deploy_itch

deploy_ppa: \
deploy_ppa_noble \
deploy_ppa_mantic \
deploy_ppa_jammy \
deploy_ppa_focal \
deploy_ppa_bionic \
deploy_ppa_xenial \
deploy_ppa_trusty

deploy_ppa_%: result.deploy_ppa_%
	@echo Deployed $*

deploy: deploy_lp deploy_scp deploy_zi deploy_fp deploy_steam deploy_download deploy_itch
#deploy: deploy_scp
#deploy: deploy_zi
#deploy: deploy_ppa

unstaged_%:
# disable staging, deploy for real
	sed -i ../deploy/targets.sh -e "s/STAGING=true/STAGING=false/"
	STAGING=false MAKE=$(MAKE) ${srcdir}/make_deploy.sh $*

staged_%:
# enforce staging
	sed -i ../deploy/targets.sh -e "s/STAGING=false/STAGING=true/"
	MAKE=$(MAKE) ${srcdir}/make_deploy.sh $*

.PHONY: deploy deploy_ppa deploy_scp deploy_gitlab deploy_steam deploy_base deploy_download

.PRECIOUS: context.debsrc_dapper \
context.debsrc_bionic result.debsrc_bionic context.deploy_ppa_bionic result.deploy_ppa_bionic \
context.debsrc_trusty result.debsrc_trusty context.deploy_ppa_trusty result.deploy_ppa_trusty \
context.debsrc_xenial result.debsrc_xenial context.deploy_ppa_xenial result.deploy_ppa_xenial \
context.debsrc_focal  result.debsrc_focal  context.deploy_ppa_focal  result.deploy_ppa_focal \
context.debsrc_hirsute result.debsrc_hirsute context.deploy_ppa_hirsute result.deploy_ppa_hirsute \
context.debsrc_impish result.debsrc_impish context.deploy_ppa_impish result.deploy_ppa_impish \
context.deploy_base_scp context.deploy_scp \
context.deploy_base_gitlab context.deploy_gitlab \
context.deploy_base_download result.deploy_download context.deploy_download

#***************************************************************

# base64 encode secrets so they can be passed in via a protected configuration variable
../deploy/secrets.b64: ../deploy/secrets/* ../deploy/secrets/*/*
	cd ../deploy; tar --exclude-backups -cjf - secrets | base64 > secrets.b64

secrets: ../deploy/secrets.b64

.PHONY: secrets

#***************************************************************

# test client build on lean alpine linux
test: result.build_client_test result.build_server_test

#***************************************************************

intermediateclean:
	rm -rf context.*

# keep the artifacts clean of junk not needed in the next phase
artifactclean:
	rm -rf \
	*.dir \
	proto/*.dir \
	source

clean: intermediateclean
	rm -rf \
	*.tag \
	gits \
	proto \
	result.* \
	rootcontext.* \
	source \
	steamdirs \
	test.* \
	macOS \
	upload

	if git -C ${srcdir} rev-parse --abbrev-ref HEAD > /dev/null; then rm -f CI_INFO; fi
distclean: clean
	rm -rf $(TARBALL) CI_INFO
	cd ${top_srcdir} && ./bootstrap.sh
	cat ${top_srcdir}/version.m4

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
