From ddbc9d85baab7fc1698e215afee7d3970065cfc3 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 21 Apr 2005 21:44:37 +0000 Subject: [PATCH] Stop generating per-directory sed scripts, and use perl to compute the patterns on the fly instead. (Next step, someday, integrate this script and depfix.sed, so we only have to run one script.) * config/post.in (depend-dependencies): Use (and depend on) depfix2.pl instead of .depfix2.sed. (.depfix2.sed): Target deleted. (DEPTARGETS): Delete .depfix2.sed and .depfix2.tmp. * util/depgen.sed: Deleted. * util/depfix2.pl: New file. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17187 dc483132-0cff-0310-8789-dd5450dbe970 --- src/config/ChangeLog | 7 +++ src/config/post.in | 17 ++---- src/util/ChangeLog | 5 ++ src/util/depfix2.pl | 108 +++++++++++++++++++++++++++++++++ src/util/depgen.sed | 141 ------------------------------------------- 5 files changed, 126 insertions(+), 152 deletions(-) create mode 100644 src/util/depfix2.pl delete mode 100644 src/util/depgen.sed diff --git a/src/config/ChangeLog b/src/config/ChangeLog index a5ccc5437..d25c11138 100644 --- a/src/config/ChangeLog +++ b/src/config/ChangeLog @@ -1,3 +1,10 @@ +2005-04-21 Ken Raeburn + + * post.in (depend-dependencies): Use (and depend on) depfix2.pl + instead of .depfix2.sed. + (.depfix2.sed): Target deleted. + (DEPTARGETS): Delete .depfix2.sed and .depfix2.tmp. + 2005-03-25 Ken Raeburn * lib.in (hpux10.exports): New target, constructed similar to diff --git a/src/config/post.in b/src/config/post.in index 573232cb4..32066a1a8 100644 --- a/src/config/post.in +++ b/src/config/post.in @@ -87,19 +87,14 @@ depend-dependencies: .dtmp: $(ALL_DEP_SRCS) $(CC) -M -DDEPEND $(ALL_CFLAGS) $? > .dtmp -# Generate a script for dropping in the appropriate make variables, using -# directory-specific parameters. General substitutions independent of local -# make variables happen in depfix.sed. -.depfix2.sed: $(BUILDTOP)/.depend-verify-gcc Makefile $(SRCTOP)/util/depgen.sed - x=`$(CC) -print-libgcc-file-name` ; \ - echo '$(SRCTOP)' '$(myfulldir)' '$(srcdir)' '$(BUILDTOP)' "$$x" '$(STLIBOBJS)' | sed -f $(SRCTOP)/util/depgen.sed > .depfix2.tmp - mv -f .depfix2.tmp .depfix2.sed - # NOTE: This will also generate spurious $(OUTPRE) and $(OBJEXT) # references in rules for non-library objects in a directory where # library objects happen to be built. It's mostly harmless. -.depend: .d .depfix2.sed $(SRCTOP)/util/depfix.sed - sed -f .depfix2.sed < .d | sed -f $(SRCTOP)/util/depfix.sed | \ +.depend: .d $(SRCTOP)/util/depfix.sed $(SRCTOP)/util/depfix2.pl + x=`$(CC) -print-libgcc-file-name` ; \ + perl $(SRCTOP)/util/depfix2.pl \ + '$(SRCTOP)' '$(myfulldir)' '$(srcdir)' '$(BUILDTOP)' "$$x" '$(STLIBOBJS)' \ + < .d | sed -f $(SRCTOP)/util/depfix.sed | \ sed -e '/^$$/d' > .depend depend-update-makefile: .depend depend-recurse @@ -110,7 +105,7 @@ depend-update-makefile: .depend depend-recurse $(SRCTOP)/config/move-if-changed $(srcdir)/Makefile.in.new $(srcdir)/Makefile.in ; \ else :; fi -DEPTARGETS = .depend .d .dtmp .depfix2.sed .depfix2.tmp $(DEP_VERIFY) +DEPTARGETS = .depend .d .dtmp $(DEP_VERIFY) # # end dependency generation diff --git a/src/util/ChangeLog b/src/util/ChangeLog index 5454b176d..0af5b4fa2 100644 --- a/src/util/ChangeLog +++ b/src/util/ChangeLog @@ -1,3 +1,8 @@ +2005-04-21 Ken Raeburn + + * depgen.sed: Deleted. + * depfix2.pl: New file. + 2005-04-20 Ken Raeburn * depgen.sed: Delete faulty check for $(srcdir), and redundant diff --git a/src/util/depfix2.pl b/src/util/depfix2.pl new file mode 100644 index 000000000..0e11b0fde --- /dev/null +++ b/src/util/depfix2.pl @@ -0,0 +1,108 @@ +#!env perl -w +eval 'exec perl -S $0 ${1+"$@"}' + if 0; +$0 =~ s/^.*?(\w+)[\.\w+]*$/$1/; + +# Input: srctop thisdir srcdir buildtop libgccfilename stlibobjs + +# Notes: myrelativedir is something like "lib/krb5/asn.1" or ".". +# stlibobjs will usually be empty, or include spaces. + +# A typical set of inputs, produced with srcdir=.. at top level: +# +# SRCTOP = ../../../util/et/../.. +# thisdir = util/et +# srcdir = ../../../util/et +# BUILDTOP = ../.. +# libgcc file name = /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/libgcc.a +# STLIBOBJS = error_message.o et_name.o com_err.o + +my($SRCTOP,$thisdir,$srcdir,$BUILDTOP,$libgccpath,$STLIBOBJS) = @ARGV; + +if (0) { + print STDERR "SRCTOP = $SRCTOP\n"; + print STDERR "BUILDTOP = $BUILDTOP\n"; + print STDERR "STLIBOBJS = $STLIBOBJS\n"; +} + +$libgccincdir = $libgccpath; +$libgccincdir =~ s,libgcc\.[^ ]*$,include,; +$libgccincdir = quotemeta($libgccincdir); +#$srcdirpat = quotemeta($srcdir); + +sub my_qm { + my($x) = @_; + $x = quotemeta($x); + $x =~ s,\\/,/,g; + return $x; +} + +sub strrep { + my($old,$new,$s) = @_; + my($l) = "strrep('$old','$new','$s')"; + my($out) = ""; + while ($s ne "") { + my($i) = index($s, $old); + if ($i == -1) { + $out .= $s; + $s = ""; + } else { + $out .= substr($s, 0, $i) . $new; + if (length($s) > $i + length($old)) { + $s = substr($s, $i + length($old)); + } else { + $s = ""; + } + } + } +# print STDERR "$l = '$out'\n"; + return $out; +} + +sub do_subs { + local($_) = @_; + s,\\$, \\,g; s, + \\$, \\,g; + s,//+,/,g; s, \\./, ,g; + if ($STLIBOBJS ne "") { + # Only care about the additional prefixes if we're building + # shared libraries. + s,^([a-zA-Z0-9_\-]*)\.o:,$1.so $1.po \$(OUTPRE)$1.\$(OBJEXT):,; + } else { + s,^([a-zA-Z0-9_\-]*)\.o:,\$(OUTPRE)$1.\$(OBJEXT):,; + } + # Drop GCC include files, they're basically system headers. + s,$libgccincdir/[^ ]* ,,go; + s,$libgccincdir/[^ ]*$,,go; + # Recognize $(SRCTOP) and variants. + my($srct) = $SRCTOP . "/"; + $_ = strrep(" $srct", " \$(SRCTOP)/", $_); +# s, $pat, \$(SRCTOP)/,go; + while ($srct =~ m,/[a-z][a-zA-Z0-9_.\-]*/\.\./,) { + $srct =~ s,/[a-z][a-zA-Z0-9_.\-]*/\.\./,/,; + $_ = strrep(" $srct", " \$(SRCTOP)/", $_); + } + # Now try to produce pathnames relative to $(srcdir). + if ($thisdir eq ".") { + # blah + } else { + my($pat) = " \$(SRCTOP)/$thisdir/"; + my($out) = " \$(srcdir)/"; + $_ = strrep($pat, $out, $_); + while ($pat =~ m,/[a-z][a-zA-Z0-9_.\-]*/$,) { + $pat =~ s,/[a-z][a-zA-Z0-9_.\-]*/$,/,; + $out .= "../"; + if ($pat ne " \$(SRCTOP)/") { + $_ = strrep($pat, $out, $_); + } + } + } + # Now substitute for BUILDTOP: + $_ = strrep(" $BUILDTOP/", " \$(BUILDTOP)/", $_); + return $_; +} + +while () { + chop; + print &do_subs($_), "\n"; +} +exit 0; diff --git a/src/util/depgen.sed b/src/util/depgen.sed deleted file mode 100644 index 29bc986bd..000000000 --- a/src/util/depgen.sed +++ /dev/null @@ -1,141 +0,0 @@ -# input srctop myfulldir srcdir buildtop libgccfilename stlibobjs -# something like ../../../../asrc/lib/krb5/asn.1/../../../ lib/krb5/asn.1 -# -# output a sequence of sed commands for recognizing and replacing srctop, -# something like: -# s; ../../../../asrc/lib/krb5/asn.1/../../../; $(SRCTOP)/;g -# s; ../../../../asrc/lib/krb5/../../; $(SRCTOP)/;g -# s; ../../../../asrc/lib/../; $(SRCTOP)/;g -# s; ../../../../asrc/; $(SRCTOP)/;g -# s; $(SRCTOP)/lib/krb5/asn.1/; $(srcdir)/;g -# s; $(SRCTOP)/lib/krb5/; $(srcdir)/../;g -# ... - -# Notes: -# Keep "s..." and "p" commands on separate lines. The "s///p" form is -# supposed to print the result if a substitution is done. When we -# then alter the pattern space and print other stuff, the IRIX sed -# seems to omit some of the earlier intended output. I think we're -# always doing the substitutions anyways, so always printing should be -# fine. -# -# STLIBOBJS will usually be empty, or include spaces. - - -# Output some mostly-fixed patterns first -h -s|^\([^ ]*\) \([^ ]*\) \([^ ]*\) \([^ ]*\) \([^ ]*\) \(.*\)$|# This file is automatically generated by depgen.sed, do not edit it.\ -#\ -# Parameters used to generate this instance:\ -#\ -# SRCTOP = \1\ -# thisdir = \2\ -# srcdir = \3\ -# BUILDTOP = \4\ -# libgcc file name = \5\ -# STLIBOBJS = \6\ -#\ -\ -# First, remove redundant leading "//" and "./" ...\ -s;///*;/;g\ -s; \\./; ;g\ -\ -# change foo.o -> $(OUTPRE)foo.$(OBJEXT)\ -s;^\\([a-zA-Z0-9_\\-]*\\).o:;$(OUTPRE)\\1.$(OBJEXT):;| -p -x - -# If the STLIBOBJS argument is not empty, emit a pattern to -# change the target name into $(OUTPRE)foo.$(OBJEXT) foo.so foo.po. -h -s|^[^ ]* [^ ]* [^ ]* [^ ]* [^ ]* || -s|^..*$|\ -# Fix up target name for the various different objects we might build.\ -s;^\\\$(OUTPRE)\\([a-zA-Z0-9_\\-]*\\)\\.\\\$(OBJEXT):;\\1.so \\1.po \&;| -p -x - -# Now throw away STLIBOBJS, we don't need it any more. -s|^\([^ ]* [^ ]* [^ ]* [^ ]* [^ ]*\) .*$|\1| - -h -s|^[^ ]* [^ ]* [^ ]* [^ ]* || -s|libgcc\.[^ ]*$|include| -s|\.|\\.|g -s|\([^ ][^ ]*\)|\ -# Remove gcc's include files resulting from "fixincludes";\ -# they're essentially system include files.\ -s;\1/[^ ]* ;;g\ -s;\1/[^ ]*$;;g\ -\ -# Recognize $(SRCTOP) and variants.| -p -x - -# Drop the last (possibly empty?) word, gcc's prefix. Then save four words. -s, [^ ]*$,, -h - -# just process first "word" -s/ .*$// -# replace multiple slashes with one single one -s,///*,/,g -# replace /./ with / -s,/\./,/,g -# strip trailing slashes, but not if it'd leave the string empty -s,\(..*\)///*,\1/, -# quote dots -s,\.,\\.,g -# turn string into sed pattern -s,^,s; , -s,$,/; $(SRCTOP)/;g, -# emit potentially multiple patterns -:loop -/\/[a-z][a-zA-Z0-9_.\-]*\/\\\.\\\.\// { -p -s;/[a-z][a-zA-Z0-9_.\-]*/\\\.\\\./;/; -bloop -} -p - -x -h -s|^.*$|\ -# Now try to produce pathnames relative to $(srcdir).| -p - -# now process second "word" -x -h -s/^[^ ]* // -s/ [^ ]* [^ ]*$// - -# treat "." specially -/^\.$/{ -d -q -} -# make sed pattern -s,^,s; $(SRCTOP)/, -s,$,/; $(srcdir)/;g, -# emit potentially multiple patterns -:loop2 -\,[^/)]/; , { -p -# strip trailing dirname off first part; append "../" to second part -s,/[a-z][a-zA-Z0-9_.\-]*/; ,/; , -s,/;g,/\.\./;g, -bloop2 -} - -x -s/^[^ ]* [^ ]* [^ ]* // -s/\./\\./g -s|^\(.*\)$|\ -# Now substitute for BUILDTOP:\ -s; \1/; $(BUILDTOP)/;g| -p - -# kill implicit print at end; don't change $(SRCTOP) into .. sequence -s/^.*$/\ -# end of sed code generated by depgen.sed/ -- 2.26.2