summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-12-05 20:11:42 +0000
committerrubidium <rubidium@openttd.org>2011-12-05 20:11:42 +0000
commitd60ec559836e9a42ca58ff4176587f92f5262139 (patch)
tree1dbe90ed99de16775067b78382e8cbf4ee10654b
parentce21a91db7eadc51a34dad69d9e8f16dd6b60de4 (diff)
downloadopenttd-d60ec559836e9a42ca58ff4176587f92f5262139.tar.xz
(svn r23438) -Fix [FS#4867]: perform checks for nforenum/grfcodec in configure, including a version check so a proper error can be given when a too old grfcodec or nforenum is used
-rw-r--r--Makefile.grf.in25
-rw-r--r--config.lib113
2 files changed, 125 insertions, 13 deletions
diff --git a/Makefile.grf.in b/Makefile.grf.in
index 33fbeeeb9..2112f2a8a 100644
--- a/Makefile.grf.in
+++ b/Makefile.grf.in
@@ -34,11 +34,8 @@ else
E = @echo
endif
-# Some configurational settings for your environment.
-# If GRFCodec doesn't know a command, it'll exit with a non-zero exit code.
-GRFCODEC := $(shell grfcodec -s -v >/dev/null 2>/dev/null && echo "grfcodec -s" || echo "grfcodec")
-# 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")
+GRFCODEC := !!GRFCODEC!!
+NFORENUM := !!NFORENUM!!
MD5SUM := $(shell [ "$(OS)" = "OSX" ] && echo "md5 -r" || echo "md5sum")
# Some "should not be changed" settings.
@@ -46,28 +43,30 @@ NFO_FILES := $(GRF_DIR)/*.nfo $(GRF_DIR)/rivers/*.nfo
PNG_FILES := $(GRF_DIR)/*.png $(GRF_DIR)/rivers/*.png
# Build the GRF.
+ifdef GRFCODEC
all: $(BIN_DIR)/openttd.grf
+else
+all:
+endif
# Make sure the sprites directory exists.
$(OBJS_DIR)/sprites:
$(Q)-mkdir "$@"
# Generic
-$(BIN_DIR)/openttd.grf: $(PNG_FILES) $(NFO_FILES) $(OBJS_DIR)/sprites
- @# Only try; if nforenum isn't available, just retouch the file as they likely didn't need it anyway.
- $(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)
+$(BIN_DIR)/openttd.grf: $(OBJS_DIR)/openttd.grf
+ $(Q)cp $(OBJS_DIR)/openttd.grf $(BIN_DIR)/openttd.grf
+ $(E) '$(STAGE) Updating base graphics sets'
+ $(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
# 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.
$(OBJS_DIR)/openttd.grf: $(PNG_FILES) $(NFO_FILES) $(OBJS_DIR)/sprites
$(E) '$(STAGE) Assembling openttd.nfo'
$(Q)-cp $(PNG_FILES) $(OBJS_DIR)/sprites 2> /dev/null
$(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
+ $(Q) $(NFORENUM) -s $(OBJS_DIR)/sprites/openttd.nfo
$(E) '$(STAGE) Compiling openttd.grf'
- $(Q) $(GRFCODEC) -e -p1 $(OBJS_DIR)/openttd.grf
- $(Q) cp $(OBJS_DIR)/openttd.grf $(BIN_DIR)/openttd.grf
- $(E) '$(STAGE) Updating base graphics sets'
- $(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
+ $(Q) $(GRFCODEC) -s -e -p1 $(OBJS_DIR)/openttd.grf
# Clean up temporary files.
clean:
diff --git a/config.lib b/config.lib
index 5507b9c73..8f1868226 100644
--- a/config.lib
+++ b/config.lib
@@ -90,6 +90,8 @@ set_default() {
with_threads="1"
with_distcc="1"
with_ccache="1"
+ with_nforenum="1"
+ with_grfcodec="1"
save_params_array="
build
@@ -162,6 +164,8 @@ set_default() {
with_threads
with_distcc
with_ccache
+ with_grfcodec
+ with_nforenum
CC CXX CFLAGS CXXFLAGS LDFLAGS"
}
@@ -417,6 +421,14 @@ detect_params() {
--with-ccache) with_ccache="2";;
--with-ccache=*) with_ccache="$optarg";;
+ --without-nforenum) with_nforenum="0";;
+ --with-nforenum) with_nforenum="2";;
+ --with-nforenum=*) with_nforenum="$optarg";;
+
+ --without-grfcodec) with_grfcodec="0";;
+ --with-grfcodec) with_grfcodec="2";;
+ --with-grfcodec=*) with_grfcodec="$optarg";;
+
--without-osx-sysroot) with_osx_sysroot="0";;
--with-osx-sysroot) with_osx_sysroot="2";;
--with-osx-sysroot=*) with_osx_sysroot="$optarg";;
@@ -926,6 +938,21 @@ check_params() {
log 1 "checking ccache... $ccache"
fi
+ detect_grfcodec
+ detect_nforenum
+
+ if [ -z "$grfcodec" ] && [ -n "$nforenum" ]; then
+ log 1 "checking nforenum/grfcodec... nforenum needs grfcodec enabled, disabling nforenum"
+ nforenum=""
+ return 0
+ fi
+
+ if [ -z "$nforenum" ] && [ -n "$grfcodec" ]; then
+ log 1 "checking nforenum/grfcodec... grfcodec needs nforenum enabled, disabling grfcodec"
+ grfcodec=""
+ return 0
+ fi
+
if [ "$os" = "DOS" ]; then
with_threads="0"
fi
@@ -3042,6 +3069,90 @@ detect_sort() {
fi
}
+detect_grfcodec() {
+ # 0 means no, 1 is auto-detect, 2 is force
+ if [ "$with_grfcodec" = "0" ]; then
+ log 1 "checking grfcodec... disabled"
+
+ grfcodec=""
+ return 0
+ fi
+
+ if [ "$with_grfcodec" = "1" ] || [ "$with_grfcodec" = "" ] || [ "$with_grfcodec" = "2" ]; then
+ grfcodec="grfcodec"
+ else
+ grfcodec="$with_grfcodec"
+ fi
+
+ version=`$grfcodec -v | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/' 2>/dev/null`
+ ret=$?
+ log 2 "executing grfcodec -v"
+ log 2 " returned $version"
+ log 2 " exit code $ret"
+
+ if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "846" ]; then
+ if [ -n "$version" ] && [ "$version" -lt "846" ]; then
+ log 1 "checking grfcodec... needs at least version 5.1.3 (r846), disabled"
+ else
+ log 1 "checking grfcodec... not found"
+ fi
+
+ # It was forced, so it should be found.
+ if [ "$with_grfcodec" != "1" ]; then
+ log 1 "configure: error: grfcodec couldn't be found"
+ log 1 "configure: error: you supplied '$with_grfcodec', but it seems invalid"
+ exit 1
+ fi
+
+ grfcodec=""
+ return 0
+ fi
+
+ log 1 "checking grfcodec... found"
+}
+
+detect_nforenum() {
+ # 0 means no, 1 is auto-detect, 2 is force
+ if [ "$with_nforenum" = "0" ]; then
+ log 1 "checking nforenum... disabled"
+
+ nforenum=""
+ return 0
+ fi
+
+ if [ "$with_nforenum" = "1" ] || [ "$with_nforenum" = "" ] || [ "$with_nforenum" = "2" ]; then
+ nforenum="nforenum"
+ else
+ nforenum="$with_nforenum"
+ fi
+
+ version=`$nforenum -v | $awk '{print $3}' | sed 's/[rM]//g;s/-/0/' 2>/dev/null`
+ ret=$?
+ log 2 "executing nforenum -v"
+ log 2 " returned $version"
+ log 2 " exit code $ret"
+
+ if [ -z "$version" ] || [ "$ret" != "0" ] || [ "$version" -lt "846" ]; then
+ if [ -n "$version" ] && [ "$version" -lt "846" ]; then
+ log 1 "checking nforenum... needs at least version 5.1.3 (r846), disabled"
+ else
+ log 1 "checking nforenum... not found"
+ fi
+
+ # It was forced, so it should be found.
+ if [ "$with_nforenum" != "1" ]; then
+ log 1 "configure: error: nforenum couldn't be found"
+ log 1 "configure: error: you supplied '$with_nforenum', but it seems invalid"
+ exit 1
+ fi
+
+ nforenum=""
+ return 0
+ fi
+
+ log 1 "checking nforenum... found"
+}
+
detect_cputype() {
if [ -n "$cpu_type" ] && [ "$cpu_type" != "DETECT" ]; then
log 1 "forcing cpu-type... $cpu_type bits"
@@ -3139,6 +3250,8 @@ make_sed() {
s@!!REVISION!!@$revision@g;
s@!!AWK!!@$awk@g;
s@!!DISTCC!!@$distcc@g;
+ s@!!NFORENUM!!@$nforenum@g;
+ s@!!GRFCODEC!!@$grfcodec@g;
"
if [ "$icon_theme_dir" != "" ]; then