From 8fa42362e984b1dbfb911b78543afc512c9863ea Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 30 Jul 2014 17:21:42 +0000 Subject: [PATCH] (svn r26708) -Codechange: replace C preprocessor with all kinds of options to prevent adding certain things to the result and the sed script to remove everything that shouldn't be in the resulting nfo file but came out of the C preprocessor by a small-ish awk program. This means no more breaking if a C preprocessor decides to add more data to the processed file (like GCC's inclusion of stdc-predef.h when not passing -nostdinc). It furthermore more than halfs the time needed for the assemble step of the extra GRF compilation --- Makefile.grf.in | 4 ++-- media/extra_grf/assemble_nfo.awk | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 media/extra_grf/assemble_nfo.awk diff --git a/Makefile.grf.in b/Makefile.grf.in index 81089efb11..c2d058d597 100644 --- a/Makefile.grf.in +++ b/Makefile.grf.in @@ -75,10 +75,10 @@ $(BIN_DIR)/%.obm: $(BASESET_DIR)/%.obm $(OBJS_DIR)/langfiles.tmp $(BASESET_DIR)/ $(Q) awk -v langfiles='$(OBJS_DIR)/langfiles.tmp' -f $(BASESET_DIR)/translations.awk $< >$@ # Compile extra grf -$(BIN_DIR)/openttd.grf: $(PNG_FILES) $(NFO_FILES) $(OBJS_DIR)/sprites +$(BIN_DIR)/openttd.grf: $(PNG_FILES) $(NFO_FILES) $(OBJS_DIR)/sprites $(GRF_DIR)/assemble_nfo.awk $(E) '$(STAGE) Assembling openttd.nfo' $(Q)-cp $(PNG_FILES) $(OBJS_DIR)/sprites 2> /dev/null - $(Q) $(CC_BUILD) -nostdinc -I$(GRF_DIR) -C -E - < "$(GRF_DIR)/openttd.nfo" | sed -e '/^#/d' -e '/^$$/d' > $(OBJS_DIR)/sprites/openttd.nfo + $(Q) awk -f $(GRF_DIR)/assemble_nfo.awk $(GRF_DIR)/openttd.nfo > $(OBJS_DIR)/sprites/openttd.nfo $(Q) $(NFORENUM) -s $(OBJS_DIR)/sprites/openttd.nfo $(E) '$(STAGE) Compiling openttd.grf' $(Q) $(GRFCODEC) -n -s -e -p1 $(OBJS_DIR)/openttd.grf diff --git a/media/extra_grf/assemble_nfo.awk b/media/extra_grf/assemble_nfo.awk new file mode 100644 index 0000000000..cf6b425c1d --- /dev/null +++ b/media/extra_grf/assemble_nfo.awk @@ -0,0 +1,32 @@ +# $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 . + +BEGIN { + # Very basic variant function; barely any error checking. + # Just use the first argument as the file to start from when assembling everything + path = ARGV[1]; + gsub("[^/\\\\]*$", "", path); + assemble(ARGV[1]); +} + +# Recursive function for assembling by means of resolving the #includes. +function assemble(filename) { + while ((getline < filename) > 0) { + if (NF == 2 && $1 == "#include" ) { + # Remove the quotes. + gsub("[\"'<>]", "", $2); + assemble(path $2); + } else { + print $0; + } + } + + if (close(filename) < 0) { + print "Could not open " filename > "/dev/stderr"; + exit -1; + } +}