Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # |
| 3 | # fixpaths - substitute makefile variables into text files |
| 4 | |
| 5 | |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 6 | $usage = "Usage: $0 [-x<file dot-suffix>] [-Dstring=replacement] [[infile] ...]\n"; |
| 7 | |
| 8 | $ext="out"; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 9 | |
| 10 | if (!defined(@ARGV)) { die ("$usage"); } |
| 11 | |
| 12 | # read in the command line and get some definitions |
| 13 | while ($_=$ARGV[0], /^-/) { |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 14 | if (/^-[Dx]/) { |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 15 | # definition |
| 16 | shift(@ARGV); |
| 17 | if ( /-D(.*)=(.*)/ ) { |
| 18 | $def{"$1"}=$2; |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 19 | } elsif ( /-x\s*(\w+)/ ) { |
| 20 | $ext=$1; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 21 | } else { |
| 22 | die ("$usage$0: error in command line arguments.\n"); |
| 23 | } |
| 24 | } else { |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 25 | die ("$usage$0: unknown option '-".$ARGV[0][1]."'\n"); |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 26 | } |
| 27 | } # while parsing arguments |
| 28 | |
| 29 | if (!defined(%def)) { |
| 30 | die ("$0: nothing to do - no substitutions listed!\n"); |
| 31 | } |
| 32 | |
| 33 | for $f (@ARGV) { |
| 34 | |
| 35 | $f =~ /(.*\/)*(.*)$/; |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 36 | $of = $2.".$ext"; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 37 | |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 38 | open(IN, "<$f") || die ("$0: input file $f missing!\n"); |
| 39 | if (open(OUT, ">$of")) { |
| 40 | while (<IN>) { |
| 41 | for $s (keys(%def)) { |
Damien Miller | 886c63a | 2000-01-20 23:13:36 +1100 | [diff] [blame] | 42 | s#$s#$def{$s}#; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 43 | } # for $s |
| 44 | print OUT; |
| 45 | } # while <IN> |
| 46 | } # if (outfile open) |
| 47 | } # for $f |
| 48 | |
| 49 | exit 0; |