Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] Re: (PR#8640) Target "*.ruleset" at data/nation/Makefile
Home

[Freeciv-Dev] Re: (PR#8640) Target "*.ruleset" at data/nation/Makefile

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8640) Target "*.ruleset" at data/nation/Makefile
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sat, 14 Aug 2004 08:30:59 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8640 >

Jason Short wrote:
> 1.  I don't like the use of an extra generated file.  Seems like you
> should be able to use an internal variable here instead.

  Temp file replaced with env variables.

> 2.  Are you sure , will never be present in the path?  I recently had a
> similar problem in tests/*.sh and I used \ as the regex separator.  We
> should be consistent here, but I don't know what is best.
> 

  This should be taken case of, too. Can't do anything for files 
containing shell escape character '\', though.

  Whta was supposed to be fast fix to points mentioned above turned into 
time consuming test/fix/test cyckle.

  1. Removal of ruleset is impossible to handle perfectly. Previously 
such case required rerunning autogen.sh before you could even run make. 
With this patch make does not fail, but prints message about ruleset 
removal. It requires two passes to build everything correctly (that is: 
user have to run 'make' twice).

  2. .PHONY target is used to force ruleset list update in case some 
ruleset is removed. There is at least two other ways to do same thing 
while .PHONE is way preferred by gnu make. Does it work with all 
relevant make programs? Does even automake support make programs without 
.PHONY.

  3. Character '@' is used to suppress irrelevant output. This might 
notr work with some make programs.

  4. I strip .ruleset suffix from file names when I write 
ruleset_list.txt. I like having it listing nation names without extra 
suffix even if it's not used for anything.

  5. Since automake sets VPATH to sourcedir anyway, I no longer refer 
files in srcdir with full path unless otherwise required.


  - Caz


diff -Nurd freeciv/data/nation/Makefile.am.sh freeciv/data/nation/Makefile.am.sh
--- freeciv/data/nation/Makefile.am.sh  2004-08-13 21:32:07.671875000 +0300
+++ freeciv/data/nation/Makefile.am.sh  2004-08-14 17:51:13.234375000 +0300
@@ -3,19 +3,73 @@
 # Regenerate Makefile.am based on actual contents of directory.
 # This is all so 'make distcheck' will work.
 #
+
+# We need to know where rulesets really are even if called from builddir.
+RSDIR=`dirname $0`
+SED_ESCAPED_RSDIR=`echo $RSDIR | sed -e 's/\//\\\\\\//g'`
+
+# Since following block is written to Makefile.am as is, I haven't
+# added Makefile.am generating specific comments into it as their escape
+# characters would get modified anyway (so comments in Makefile.am would be 
inccorrect).
+# Some heavy escaping is used so Makefile.am turns out right, with all escape 
characters
+# it in turn requires.
+
+# Makefile.am.sh         : sed -e 's/\\//\\\\\\\\\\\\//g'
+# Output to Makefile.am  : sed -e 's/\//\\\\\\//g'
+# sed_escaped_srcdir contains          '\\\/' for every path delimeter
+# shell appends variable               '\/'   delimeters are correctly escaped 
for sed
+
 cat <<EOF
 ## Process this file with automake to produce Makefile.in
 # Note: After adding a new nation file, 'make Makefile.am'
 
+# In case some ruleset is removed, provide ruleset list
+# update in rule 'all'.
+# Too bad we cannot put this before automake generated Makefile
+# regeneration rules. So we still used old Makefile versions while running
+# make this time.
+all : update_ruleset_list
+
 ## Override automake so that "make install" puts these in proper place:
 pkgdatadir = \$(datadir)/@PACKAGE@/nation
 
 pkgdata_DATA = \\
-`find * -name "*.ruleset" -print | sed -e 's/.*ruleset$/               & \\\/' 
-e '$s/.$//'`
+`find $RSDIR/ -name "*.ruleset" -print | sed -e "s/$SED_ESCAPED_RSDIR\///" -e 
's/.*ruleset$/           & \\\/' -e '$s/.$//'`
 
-EXTRA_DIST = \$(pkgdata_DATA) Makefile.am.sh
+EXTRA_DIST = \$(pkgdata_DATA) Makefile.am.sh ruleset_list.txt
 
-Makefile.am: Makefile.am.sh \$(shell echo *.ruleset)
-       sh Makefile.am.sh >Makefile.am
+# Command to update ruleset list
+RSL_UPDATE=( SED_ESCAPED_SRCDIR=\`echo \$(srcdir) | sed -e 
's/\\//\\\\\\\\\\\\//g'\` ; OLD_LIST=\`if test -e \$(srcdir)/ruleset_list.txt ; 
then cat \$(srcdir)/ruleset_list.txt ; else echo empty ; fi\` ; NEW_LIST=\`echo 
-e "\\# Autogenerated list of nation ruleset files.\\n\\# Do not edit, but run 
'make ruleset_list.txt' to regenerate.\\n\\#\\n" ; ls -1 \$(srcdir)/*.ruleset | 
sed -e "s/\$\$SED_ESCAPED_SRCDIR\\///" -e "s/.ruleset//" \` ; if test 
"x\$\$OLD_LIST" != "x\$\$NEW_LIST" ; then echo "\$\$NEW_LIST" > 
\$(srcdir)/ruleset_list.txt ; echo "Nation ruleset list changed" ; fi )
+
+.PHONY : update_ruleset_list
+
+# This rule always updates ruleset list.
+# Compared to ruleset_list.txt:
+#   Pros: This updates ruleset list also when ruleset is removed.
+#   Cons: Every rule that has this as prerequisite is rebuilt always too.
+update_ruleset_list :
+       @ \$(RSL_UPDATE)
+
+# This rule rebuils ruleset list if new ruleset is added.
+# If existing ruleset changes, list is not rebuilt but
+# rules listing this as prereq will be built.
+# See also rule update_ruleset_list.
+ruleset_list.txt : \$(srcdir)/*.ruleset
+       @ \$(RSL_UPDATE)
+
+# If ruleset file is removed, automake generated rule 'all-am'
+# wants to know how to regenerate it. So we provide dummy rule
+# to satisfy it. This works in most cases, but 'make dist' or
+# 'make install' will fail when they actually attempt to copy
+# nonexistent rulesets.
+%.ruleset :
+       @ echo "Ruleset \$@ missing, probably removed since last Makefile.am 
update"
+
+# ruleset_list.txt is rebuilt before Makefile.am if new ruleset is added.
+# We can't use update_ruleset_list as prereq here, since it
+# would lead to recursive loop. This means that if ruleset is just removed,
+# generated Makefile.am is not necessarily upto date.
+\$(srcdir)/Makefile.am: Makefile.am.sh ruleset_list.txt
+       sh \$(srcdir)/Makefile.am.sh > \$(srcdir)/Makefile.am
 
 EOF

[Prev in Thread] Current Thread [Next in Thread]