blob: 8a6740649e5fa6045375d6f3bd65573232dc1a8e [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
6$usage = "Usage: $0 [-D<variable>=<value>] [[infile] ...]\n";
7
8if (!defined(@ARGV)) { die ("$usage"); }
9
10# read in the command line and get some definitions
11while ($_=$ARGV[0], /^-/) {
12 if (/^-D/) {
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 {
21 &usage; die ("$usage$0: unknown option '-".$ARGV[0][1]."'\n");
22 }
23} # while parsing arguments
24
25if (!defined(%def)) {
26 die ("$0: nothing to do - no substitutions listed!\n");
27}
28
29for $f (@ARGV) {
30
31 $f =~ /(.*\/)*(.*)$/;
32 $of = $2; $of =~ s/.in$//;
33
Damien Millerc0d73901999-12-27 09:23:58 +110034 open(IN, "<$f") || die ("$0: input file $f missing!\n");
35 if (open(OUT, ">$of")) {
36 while (<IN>) {
37 for $s (keys(%def)) {
38 s#\@$s\@#$def{$s}#;
39 } # for $s
40 print OUT;
41 } # while <IN>
42 } # if (outfile open)
43} # for $f
44
45exit 0;