X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/11c073b7e53fb82c67f1adf8cd7c2e60b7518729..ee52f6ec6ba94a9e8bdb99f5c456bd8b6bce37ba:/etc/prefix-gnulib-mk?ds=sidebyside diff --git a/etc/prefix-gnulib-mk b/etc/prefix-gnulib-mk index 08d22f28..81c0924f 100755 --- a/etc/prefix-gnulib-mk +++ b/etc/prefix-gnulib-mk @@ -2,15 +2,53 @@ use strict; use IO::File; +use Getopt::Long; +use File::Basename; # for dirname -my $prefix = "lib/"; +my $VERSION = '2012-01-21 17:13'; # UTC +(my $ME = $0) =~ s|.*/||; + +my $prefix; +my $lib_name; + +sub usage ($) +{ + my ($exit_code) = @_; + my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR); + if ($exit_code != 0) + { + print $STREAM "Try '$ME --help' for more information.\n"; + } + else + { + print $STREAM <getline or die "$file"; $f->close; @@ -26,7 +64,7 @@ sub prefix_word ($) { local ($_) = @_; $_ = $prefix . $_ - unless m{^\$\(\w+\)} || $_ eq "Makefile"; + unless /^-/ || m{^\$\(\w+\)} || $_ eq "Makefile" || $_ eq '\\'; return $_; } @@ -71,10 +109,7 @@ sub prefix_assignment ($$) # Variables which name depend on the location: libbison_a_SOURCES => # lib_libbison_a_SOURCES. - $lhs_and_assign_op =~ s/(libbison)/lib_$1/g; - - # Do not use gl_LIBOBJS, but its prefixed version. - $rhs =~ s/gl_LIBOBJS/gl_PREFIXED_LIBOBJS/g; + $lhs_and_assign_op =~ s/($lib_name)/lib_$1/g; return $lhs_and_assign_op . $rhs; } @@ -93,7 +128,7 @@ sub prefix ($) # Prefix all the occurrence of files in rules. If there is nothing # after in the :, it's probably a phony target, or a suffix rule. # Don't touch it. - s{^([\w.]+ *: *\w.*)$} + s{^([-\w+/]+\.[-\w.]+ *: *\S.*)$} {prefix_words($1)}gem; # Prefix files in variables. @@ -103,7 +138,7 @@ sub prefix ($) # These three guys escape all the other regular rules. s{(charset\.alias|ref-add\.sed|ref-del\.sed)}{$prefix$1}g; # Unfortunately, as a result we sometimes have lib/lib. - s{lib/lib/}{lib/}g; + s{($prefix){2}}{$1}g; # $(srcdir) is actually $(top_srcdir)/lib. s{\$\(srcdir\)}{\$(top_srcdir)/lib}g; @@ -112,6 +147,12 @@ sub prefix ($) # not work when we have a $@ with a directory in it. s{t-\$\@}{\$\@-t}g; + # Some AC_SUBST patterns remain and would better be Make macros. + s{\@(MKDIR_P)\@}{\$($1)}g; + + # Adjust paths in mkdir. + s{(\$\(MKDIR_P\))\s*(\w+)}{$1 $prefix$2}g; + return $_; } @@ -128,8 +169,33 @@ sub process ($) print $out $contents; } -process ("lib/gnulib.mk") - +{ + GetOptions + ( + 'lib-name=s' => \$lib_name, + help => sub { usage 0 }, + version => sub { print "$ME version $VERSION\n"; exit }, + ) or usage 1; + + my $fail = 0; + defined $lib_name + or (warn "$ME: no library name; use --lib-name=NAME\n"), $fail = 1; + + # There must be exactly one argument. + @ARGV == 0 + and (warn "$ME: missing FILE argument\n"), $fail = 1; + 1 < @ARGV + and (warn "$ME: too many arguments:\n", join ("\n", @ARGV), "\n"), + $fail = 1; + $fail + and usage 1; + + my $file = $ARGV[0]; + $prefix = (dirname $file) . '/'; + warn "prefix=$prefix\n"; + + process $file; +} ### Setup "GNU" style for perl-mode and cperl-mode. ## Local Variables: @@ -146,4 +212,9 @@ process ("lib/gnulib.mk") ## cperl-extra-newline-before-brace: t ## cperl-merge-trailing-else: nil ## cperl-continued-statement-offset: 2 +## eval: (add-hook 'write-file-hooks 'time-stamp) +## time-stamp-start: "my $VERSION = '" +## time-stamp-format: "%:y-%02m-%02d %02H:%02M" +## time-stamp-time-zone: "UTC" +## time-stamp-end: "'; # UTC" ## End: