2010-08-14 14:50:06 +00:00
# $Id$
# This file is part of OpenTTD.
# OpenTTD 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, version 2.
# OpenTTD 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. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
#
# Building requires GRFCodec and NFORenum. Older versions of GRFCodec are
# known to miscompile the graphics.
#
# Recent nightlies (including sources) of both can be found at:
# http://www.openttd.org/download-grfcodec
# http://www.openttd.org/download-nforenum
#
# The mercurial repository of both can be found at:
# http://hg.openttdcoop.org/grfcodec
# http://hg.openttdcoop.org/nforenum
#
ROOT_DIR = !!ROOT_DIR!!
GRF_DIR = $( ROOT_DIR) /media/extra_grf
BIN_DIR = !!BIN_DIR!!/data
OBJS_DIR = !!GRF_OBJS_DIR!!
2010-08-19 08:07:19 +00:00
OS = !!OS!!
2010-08-21 10:57:01 +00:00
STAGE = !!STAGE!!
2010-08-14 14:50:06 +00:00
# Check if we want to show what we are doing
i f d e f V E R B O S E
Q =
E = @true
e l s e
Q = @
E = @echo
e n d i f
# Some configurational settings for your environment.
2010-08-21 11:30:41 +00:00
# If GRFCodec doesn't know a command, it'll exit with a non-zero exit code.
2010-08-21 10:57:01 +00:00
GRFCODEC := $( shell grfcodec -s -v >/dev/null 2>/dev/null && echo "grfcodec -s" || echo "grfcodec" )
2010-08-21 11:30:41 +00:00
# Old NFORenums don't give an error code when a parameter isn't known, so we have to work around that.
NFORENUM := $( shell [ ` nforenum -s -v 2>/dev/null | wc -l ` -eq 1 ] && echo "nforenum -s" || echo "nforenum" )
2010-08-19 08:07:19 +00:00
MD5SUM := $( shell [ " $( OS) " = "OSX" ] && echo "md5 -r" || echo "md5sum" )
2010-08-14 14:50:06 +00:00
# Some "should not be changed" settings.
NFO_FILES := $( GRF_DIR) /*.nfo
2010-10-24 15:49:38 +00:00
PNG_FILES := $( GRF_DIR) /*.png
2010-08-14 14:50:06 +00:00
# Build the GRF.
all : $( BIN_DIR ) /openttd .grf
# Make sure the sprites directory exists.
$(OBJS_DIR)/sprites :
$( Q) -mkdir " $@ "
# Generic
2010-10-24 15:49:38 +00:00
$(BIN_DIR)/openttd.grf : $( PNG_FILES ) $( NFO_FILES ) $( OBJS_DIR ) /sprites
2010-08-14 14:50:06 +00:00
@# Only try; if nforenum isn't available, just retouch the file as they likely didn' t need it anyway.
2010-09-01 20:17:25 +00:00
$( Q) ( $( NFORENUM) --help > /dev/null 2>& 1 && $( MAKE) $( OBJS_DIR) /openttd.grf && cp $( OBJS_DIR) /openttd.grf $( BIN_DIR) /openttd.grf) || ( [ -e $( BIN_DIR) /openttd.grf ] && touch $( BIN_DIR) /openttd.grf && echo "no NFORenum and GRFCodec found, skipping rebuild of openttd.grf..." ) || ( echo "no NFORenum and GRFCodec found, but no openttd.grf either. Install NFORenum and GRFCodec." && exit 1)
2010-08-14 14:50:06 +00:00
2010-08-19 08:07:19 +00:00
# Yeah, we'd like to use -i in the sed, but Mac OS X's sed and GNU sed just can't agree on the usage of -i. In any case either one of them fails.
2010-10-24 15:49:38 +00:00
$(OBJS_DIR)/openttd.grf : $( PNG_FILES ) $( NFO_FILES ) $( OBJS_DIR ) /sprites
2010-08-21 10:57:01 +00:00
$( E) '$(STAGE) Assembling openttd.nfo'
2010-10-24 15:49:38 +00:00
$( Q) -cp $( PNG_FILES) $( OBJS_DIR) /sprites 2> /dev/null
2010-08-14 14:50:06 +00:00
$( Q) gcc -I$( GRF_DIR) -C -E - < " $( GRF_DIR) /openttd.nfo " | sed -e '/^#/d' -e '/^$$/d' > $( OBJS_DIR) /sprites/openttd.nfo
$( Q) $( NFORENUM) $( OBJS_DIR) /sprites/openttd.nfo
2010-08-21 10:57:01 +00:00
$( E) '$(STAGE) Compiling openttd.grf'
2010-10-18 12:24:56 +00:00
$( Q) $( GRFCODEC) -e -p1 $( OBJS_DIR) /openttd.grf
2010-08-14 14:50:06 +00:00
$( Q) cp $( OBJS_DIR) /openttd.grf $( BIN_DIR) /openttd.grf
2010-08-21 10:57:01 +00:00
$( E) '$(STAGE) Updating base graphics sets'
2010-08-19 08:07:19 +00:00
$( Q) for grf in $( BIN_DIR) /orig*.obg; do sed 's/^OPENTTD.GRF = [0-9a-f]*$$/OPENTTD.GRF = ' ` $( MD5SUM) $( BIN_DIR) /openttd.grf | sed 's@ .*@@' ` '/' $$ grf > $$ grf.tmp && mv $$ grf.tmp $$ grf; done
2010-08-14 14:50:06 +00:00
# Clean up temporary files.
clean :
$( Q) rm -f *.bak *.grf
2010-09-05 21:50:59 +00:00
# Clean up temporary files
2010-08-14 14:50:06 +00:00
mrproper : clean
$( Q) rm -fr sprites
.PHONY : all mrproper depend clean