138 lines (107 with data), 4.7 kB
#!/usr/bin/make -f
# :oCCCCOCoc.
# .cCO8OOOOOOOOO8Oo:
# .oOO8OOOOOOOOOOOOOOOCc
# cO8888: .:oOOOOC. TM
# :888888: :CCCc .oOOOOC. ### ### #########
# C888888: .ooo: .C######## ##### ##### ###### ###### ##########
# O888888: .oO### ### ##### ##### ######## ######## #### ###
# C888888: :8O. .C########## ### #### ### ## ## ## ## #### ###
# :8@@@@8: :888c o### ### #### ### ######## ######## ##########
# :8@@@@C C@@@@ oo######## ### ## ### ###### ###### #########
# cO@@@@@@@@@@@@@@@@@Oc0
# :oO8@@@@@@@@@@Oo.
# .oCOOOOOCc. http://remood.org/
# -----------------------------------------------------------------------------
# Copyright (C) 2013-2013 GhostlyDeath <ghostlydeath@remood.org>
# <ghostlydeath@gmail.com>
# -----------------------------------------------------------------------------
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# -----------------------------------------------------------------------------
# Autobuild system done with makefiles (very modular)
##########################
### PRE INITIALIZATION ###
##########################
__MASTER_TMPDIR := /tmp
__MASTER_CURDIR := $(CURDIR)
__MASTER_THISMAKE := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
__MASTER_PROJ := $(dir ${__MASTER_THISMAKE})
__MASTER_ROOT := ${__MASTER_PROJ}/..
__MASTER_HOST := $(shell gcc -dumpmachine)
__MASTER_DOSEMUPATH := $(shell which dosemu)
__MASTER_VERSION := $(shell cat ${__MASTER_ROOT}/version)
__MASTER_VERSIONND := $(shell cat ${__MASTER_ROOT}/version | sed 's/\.//')
#########################
### FILES IN ARCHIVES ###
#########################
__MASTER_TXTFILES := AUTHORS LICENSE README version
__MASTER_BINFILES := bin/remood.wad
####################
### TARGET SETUP ###
####################
$(info +++ ReMooD Version ${__MASTER_VERSION})
### OBTAIN LIST OF TARGETS ###
__MASTER_SUPLS := $(foreach __target,$(wildcard ${__MASTER_PROJ}/conf/*.sup),$(basename $(notdir ${__target})))
__MASTER_TARGETS := $(foreach __target,$(wildcard ${__MASTER_PROJ}/conf/*.os),$(basename $(notdir ${__target})))
__MASTER_AUTOTARG := $(foreach __target,$(wildcard ${__MASTER_PROJ}/conf/*.aut),$(basename $(notdir ${__target})))
### BASIC SUPPORT ###
# Locates compilers that are shared by most of the rulesets
$(info +++ Adding basic support...)
define __suplbasictemp
-include conf/$1.sup
endef
$(foreach __suplbasic,${__MASTER_SUPLS},$(eval $(call __suplbasictemp,$(__suplbasic))))
### PRECONFIGURE TARGETS BY INCLUDING THEIR RESPECTIVE MAKEFILES ###
# Includes the primary building rules
$(info +++ Preconfiguring targets...)
__MASTER_OKTARGETS :=
define __preconftarget
-include conf/$1.os
endef
$(foreach __pctarget,${__MASTER_TARGETS},$(eval $(call __preconftarget,$(__pctarget))))
### AUTOMATIC TARGETS CHOOSE A DEFAULT TARGET ###
# Some configurations could work with anything and are sub targets of a real
# target. For example is win32, there exists win32all and win32sdl. win32 will
# just choose the best target, provided it is ok.
# So in retrospect: `./auto win32` will choose either win32sdl or win32all (and
# possibly even another target, if it is added later...
$(info +++ Automatic targets...)
define __autoconftarget
-include conf/$1.aut
endef
$(foreach __auttarget,${__MASTER_AUTOTARG},$(eval $(call __autoconftarget,$(__auttarget))))
####################
### DEBUG OUTPUT ###
####################
$(info Root: $(__MASTER_ROOT))
$(info Host: ${__MASTER_HOST})
$(info All Targets: ${__MASTER_TARGETS})
$(info Alias Targets: ${__MASTER_AUTOTARG})
$(info Working Targets: ${__MASTER_OKTARGETS})
#############
### RULES ###
#############
define __rulebase
# Base rule to compile target
.PHONY: $1
$1: $1-build
@:
.PHONY: $1-prep
$1-prep: _$1_prep
@:
.PHONY: $1-build $1-prep
$1-build: _$1_build
@:
.PHONY: $1-archive $1-build
$1-archive: _$1_archive
@:
endef
$(foreach __worktarget,${__MASTER_OKTARGETS},$(eval $(call __rulebase,${__worktarget})))