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 | 897741e | 2001-04-16 10:41:46 +1000 | [diff] [blame] | 6 | $usage = "Usage: $0 [-Dstring=replacement] [[infile] ...]\n"; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 7 | |
| 8 | if (!defined(@ARGV)) { die ("$usage"); } |
| 9 | |
| 10 | # read in the command line and get some definitions |
| 11 | while ($_=$ARGV[0], /^-/) { |
Damien Miller | 897741e | 2001-04-16 10:41:46 +1000 | [diff] [blame] | 12 | if (/^-D/) { |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 13 | # definition |
| 14 | shift(@ARGV); |
| 15 | if ( /-D(.*)=(.*)/ ) { |
| 16 | $def{"$1"}=$2; |
| 17 | } else { |
| 18 | die ("$usage$0: error in command line arguments.\n"); |
| 19 | } |
| 20 | } else { |
Damien Miller | 3ef692a | 2000-04-20 07:33:24 +1000 | [diff] [blame] | 21 | @cmd = split(//, $ARGV[0]); $opt = $cmd[1]; |
| 22 | die ("$usage$0: unknown option '-$opt'\n"); |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 23 | } |
| 24 | } # while parsing arguments |
| 25 | |
| 26 | if (!defined(%def)) { |
| 27 | die ("$0: nothing to do - no substitutions listed!\n"); |
| 28 | } |
| 29 | |
| 30 | for $f (@ARGV) { |
| 31 | |
| 32 | $f =~ /(.*\/)*(.*)$/; |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 33 | |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 34 | open(IN, "<$f") || die ("$0: input file $f missing!\n"); |
Ben Lindstrom | dbcea87 | 2000-11-08 01:07:51 +0000 | [diff] [blame] | 35 | while (<IN>) { |
| 36 | for $s (keys(%def)) { |
| 37 | s#$s#$def{$s}#; |
| 38 | } # for $s |
Damien Miller | 897741e | 2001-04-16 10:41:46 +1000 | [diff] [blame] | 39 | print; |
Ben Lindstrom | dbcea87 | 2000-11-08 01:07:51 +0000 | [diff] [blame] | 40 | } # while <IN> |
Damien Miller | c0d7390 | 1999-12-27 09:23:58 +1100 | [diff] [blame] | 41 | } # for $f |
| 42 | |
| 43 | exit 0; |