blob: 6a2a3a0b3954d860860667c236073fad0ac5d31b [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
34 print("Making substitutions for $of\n");
35
36 open(IN, "<$f") || die ("$0: input file $f missing!\n");
37 if (open(OUT, ">$of")) {
38 while (<IN>) {
39 for $s (keys(%def)) {
40 s#\@$s\@#$def{$s}#;
41 } # for $s
42 print OUT;
43 } # while <IN>
44 } # if (outfile open)
45} # for $f
46
47exit 0;