blob: 7e4178e4a96753c4debff32e37a9b1a3bdd5c0c8 [file] [log] [blame]
Damien Millerc0d73901999-12-27 09:23:58 +11001#!/usr/bin/perl -w
2#
3# fixpaths - substitute makefile variables into text files
4
5
Damien Miller897741e2001-04-16 10:41:46 +10006$usage = "Usage: $0 [-Dstring=replacement] [[infile] ...]\n";
Damien Millerc0d73901999-12-27 09:23:58 +11007
8if (!defined(@ARGV)) { die ("$usage"); }
9
10# read in the command line and get some definitions
11while ($_=$ARGV[0], /^-/) {
Damien Miller897741e2001-04-16 10:41:46 +100012 if (/^-D/) {
Damien Millerc0d73901999-12-27 09:23:58 +110013 # 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 Miller3ef692a2000-04-20 07:33:24 +100021 @cmd = split(//, $ARGV[0]); $opt = $cmd[1];
22 die ("$usage$0: unknown option '-$opt'\n");
Damien Millerc0d73901999-12-27 09:23:58 +110023 }
24} # while parsing arguments
25
26if (!defined(%def)) {
27 die ("$0: nothing to do - no substitutions listed!\n");
28}
29
30for $f (@ARGV) {
31
32 $f =~ /(.*\/)*(.*)$/;
Damien Millerc0d73901999-12-27 09:23:58 +110033
Damien Millerc0d73901999-12-27 09:23:58 +110034 open(IN, "<$f") || die ("$0: input file $f missing!\n");
Ben Lindstromdbcea872000-11-08 01:07:51 +000035 while (<IN>) {
36 for $s (keys(%def)) {
37 s#$s#$def{$s}#;
38 } # for $s
Damien Miller897741e2001-04-16 10:41:46 +100039 print;
Ben Lindstromdbcea872000-11-08 01:07:51 +000040 } # while <IN>
Damien Millerc0d73901999-12-27 09:23:58 +110041} # for $f
42
43exit 0;