| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
require 5.004; |
|---|
| 50 |
|
|---|
| 51 |
use Cwd; |
|---|
| 52 |
use File::Basename; |
|---|
| 53 |
use File::Copy; |
|---|
| 54 |
use Getopt::Long; |
|---|
| 55 |
|
|---|
| 56 |
sub generateFile($$); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
BEGIN { |
|---|
| 60 |
$path = (fileparse("$0"))[1]; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
use lib("$path"); |
|---|
| 64 |
use InstallOps; |
|---|
| 65 |
|
|---|
| 66 |
$InstallOps::pass_rec_func_cur_file_dir = 1; |
|---|
| 67 |
|
|---|
| 68 |
$Win32 = 1 if $ENV{'OS'} =~ /Windows/; |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
$Getopt::Long::ignorecase = 0; |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
%VARS = (); |
|---|
| 75 |
@files = (); |
|---|
| 76 |
($var_file, $startdir, $prefix) = ('', '', ''); |
|---|
| 77 |
($uname, $gname, $mode) = ('', '', ''); |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
GetOptions("vars=s", \$var_file, "srcdir=s" => \$VARS{'srcdir'}, |
|---|
| 82 |
"prefix=s" => \$prefix, "startdir=s" => \$startdir, |
|---|
| 83 |
'files=s' => \@files, |
|---|
| 84 |
"uname=s" => \$uname, "gname=s" => \$gname, "mode=s" => \$mode); |
|---|
| 85 |
|
|---|
| 86 |
if ( ! ($var_file && exists($VARS{'srcdir'}) && $prefix) ) |
|---|
| 87 |
{ |
|---|
| 88 |
die <<USAGE_EOF; |
|---|
| 89 |
Usage: |
|---|
| 90 |
$0 |
|---|
| 91 |
--vars=<Path to a Perl file containing @..@ substitution values> |
|---|
| 92 |
--srcdir=<Location of source code> |
|---|
| 93 |
--prefix=<Base directory where Makefile will go> |
|---|
| 94 |
[ --startdir=<Directory where search begins> |
|---|
| 95 |
--uname=<Owner's user name> --gname=<Group name> --mode=<Mode bits> ] |
|---|
| 96 |
USAGE_EOF |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
die "ERROR: Cannot specify file and directory recursion together!\n" |
|---|
| 100 |
if $#files != -1 && $startdir; |
|---|
| 101 |
|
|---|
| 102 |
# Import the extra settings for %VARS found in $var_file if it was given |
|---|
| 103 |
# on the command line. |
|---|
| 104 |
if ( $var_file ) |
|---|
| 105 |
{ |
|---|
| 106 |
my @path_info = fileparse("$var_file"); |
|---|
| 107 |
push(@INC, "$path_info[1]"); |
|---|
| 108 |
require "$path_info[0]"; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
umask(002); |
|---|
| 112 |
|
|---|
| 113 |
# Defaults. |
|---|
| 114 |
my($uid, $gid, $mode_bits) = ($<, (getpwuid($<))[3], "0644") unless $Win32; |
|---|
| 115 |
|
|---|
| 116 |
if ( $uname ) |
|---|
| 117 |
{ |
|---|
| 118 |
my(@user_info) = getpwnam("$uname") or die "getpwnam($uname): $!\n"; |
|---|
| 119 |
$uid = $user_info[2]; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
if ( $gname && ! $Win32 ) |
|---|
| 123 |
{ |
|---|
| 124 |
my(@group_info) = getgrnam("$gname") or die "getgrnam($gname): $!\n"; |
|---|
| 125 |
$gid = $group_info[2]; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
$mode_bits = "$mode" if $mode; |
|---|
| 129 |
|
|---|
| 130 |
if ( $startdir ) |
|---|
| 131 |
{ |
|---|
| 132 |
chdir("$startdir") or die "ERROR: Cannot chdir to $startdir: $!\n"; |
|---|
| 133 |
recurseDir(".", "$prefix"); |
|---|
| 134 |
} |
|---|
| 135 |
else |
|---|
| 136 |
{ |
|---|
| 137 |
my $cwd = getcwd(); |
|---|
| 138 |
foreach ( @files ) |
|---|
| 139 |
{ |
|---|
| 140 |
my @full_path = split(/\//); |
|---|
| 141 |
my $file = pop(@full_path); |
|---|
| 142 |
my $new_dir = join("/", @full_path); |
|---|
| 143 |
|
|---|
| 144 |
if ( chdir("$new_dir") ) |
|---|
| 145 |
{ |
|---|
| 146 |
generateFile("$file", ""); |
|---|
| 147 |
chdir("$cwd"); |
|---|
| 148 |
} |
|---|
| 149 |
else |
|---|
| 150 |
{ |
|---|
| 151 |
warn "WARNING: Could not chdir to $new_dir: $!\n"; |
|---|
| 152 |
} |
|---|
| 153 |
} |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
exit 0; |
|---|
| 157 |
|
|---|
| 158 |
# ----------------------------------------------------------------------------- |
|---|
| 159 |
# If the given file is named Makefile.in, use it as a template to generate a |
|---|
| 160 |
# makefile that will be installed. |
|---|
| 161 |
# |
|---|
| 162 |
# Syntax: |
|---|
| 163 |
# recurseAction($curfile, $curpath); |
|---|
| 164 |
# |
|---|
| 165 |
# Arguments: |
|---|
| 166 |
# $curfile - The name of the current file in the recursion process. |
|---|
| 167 |
# $curpath - The current directory stack. |
|---|
| 168 |
# ----------------------------------------------------------------------------- |
|---|
| 169 |
sub recurseAction |
|---|
| 170 |
{ |
|---|
| 171 |
my $curfile = shift; |
|---|
| 172 |
my $curpath = shift; |
|---|
| 173 |
|
|---|
| 174 |
generateFile("$curfile", "$curpath") if "$curfile" eq "Makefile.in"; |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
sub generateFile ($$) |
|---|
| 178 |
{ |
|---|
| 179 |
my $infile = shift; |
|---|
| 180 |
my $curpath = shift; |
|---|
| 181 |
|
|---|
| 182 |
my $outfile = "$prefix/$curpath/$infile"; |
|---|
| 183 |
$outfile =~ s/\.in$//; |
|---|
| 184 |
|
|---|
| 185 |
print "Generating $outfile ...\n"; |
|---|
| 186 |
|
|---|
| 187 |
my $workfile = "working.in-$$"; |
|---|
| 188 |
|
|---|
| 189 |
# Make a working copy of the input file to be safe. |
|---|
| 190 |
copy("$infile", "$workfile") unless "$infile" eq "$workfile"; |
|---|
| 191 |
|
|---|
| 192 |
# Replace the tags in $workfile with the values in %VARS. |
|---|
| 193 |
next if replaceTags("$workfile", %VARS) < 0; |
|---|
| 194 |
|
|---|
| 195 |
# Move $workfile to its final destination. |
|---|
| 196 |
copy("$workfile", "$outfile"); |
|---|
| 197 |
|
|---|
| 198 |
if ( ! $Win32 ) |
|---|
| 199 |
{ |
|---|
| 200 |
chown($uid, $gid, "$outfile") or die "chown: $!\n"; |
|---|
| 201 |
} |
|---|
| 202 |
|
|---|
| 203 |
chmod(oct($mode_bits), "$outfile") or die "chmod: $!\n"; |
|---|
| 204 |
unlink("$workfile"); |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|