blob: e6f47c713643599c158d866fc6001efed75038fb [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 Miller886c63a2000-01-20 23:13:36 +110025 die ("$usage$0: unknown option '-".$ARGV[0][1]."'\n");
Damien Millerc0d73901999-12-27 09:23:58 +110026 }
27} # while parsing arguments
28
29if (!defined(%def)) {
30 die ("$0: nothing to do - no substitutions listed!\n");
31}
32
33for $f (@ARGV) {
34
35 $f =~ /(.*\/)*(.*)$/;
Damien Miller886c63a2000-01-20 23:13:36 +110036 $of = $2.".$ext";
Damien Millerc0d73901999-12-27 09:23:58 +110037
Damien Millerc0d73901999-12-27 09:23:58 +110038 open(IN, "<$f") || die ("$0: input file $f missing!\n");
39 if (open(OUT, ">$of")) {
40 while (<IN>) {
41 for $s (keys(%def)) {
Damien Miller886c63a2000-01-20 23:13:36 +110042 s#$s#$def{$s}#;
Damien Millerc0d73901999-12-27 09:23:58 +110043 } # for $s
44 print OUT;
45 } # while <IN>
46 } # if (outfile open)
47} # for $f
48
49exit 0;