blob: 4badd98866616ceee9cdb09651dc0670bc5b3ba1 [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 Miller886c63a2000-01-20 23:13:36 +11006$usage = "Usage: $0 [-x<file dot-suffix>] [-Dstring=replacement] [[infile] ...]\n";
7
8$ext="out";
Damien Millerc0d73901999-12-27 09:23:58 +11009
10if (!defined(@ARGV)) { die ("$usage"); }
11
12# read in the command line and get some definitions
13while ($_=$ARGV[0], /^-/) {
Damien Miller886c63a2000-01-20 23:13:36 +110014 if (/^-[Dx]/) {
Damien Millerc0d73901999-12-27 09:23:58 +110015 # definition
16 shift(@ARGV);
17 if ( /-D(.*)=(.*)/ ) {
18 $def{"$1"}=$2;
Damien Miller886c63a2000-01-20 23:13:36 +110019 } elsif ( /-x\s*(\w+)/ ) {
20 $ext=$1;
Damien Millerc0d73901999-12-27 09:23:58 +110021 } else {
22 die ("$usage$0: error in command line arguments.\n");
23 }
24 } else {
Damien Miller3ef692a2000-04-20 07:33:24 +100025 @cmd = split(//, $ARGV[0]); $opt = $cmd[1];
26 die ("$usage$0: unknown option '-$opt'\n");
Damien Millerc0d73901999-12-27 09:23:58 +110027 }
28} # while parsing arguments
29
30if (!defined(%def)) {
31 die ("$0: nothing to do - no substitutions listed!\n");
32}
33
34for $f (@ARGV) {
35
36 $f =~ /(.*\/)*(.*)$/;
Damien Miller886c63a2000-01-20 23:13:36 +110037 $of = $2.".$ext";
Damien Millerc0d73901999-12-27 09:23:58 +110038
Damien Millerc0d73901999-12-27 09:23:58 +110039 open(IN, "<$f") || die ("$0: input file $f missing!\n");
40 if (open(OUT, ">$of")) {
41 while (<IN>) {
42 for $s (keys(%def)) {
Damien Miller886c63a2000-01-20 23:13:36 +110043 s#$s#$def{$s}#;
Damien Millerc0d73901999-12-27 09:23:58 +110044 } # for $s
45 print OUT;
46 } # while <IN>
47 } # if (outfile open)
48} # for $f
49
50exit 0;