root/juggler/trunk/release/scripts/makefiles-gen.pl

Revision 20974, 5.7 kB (checked in by patrick, 1 year ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env perl
2
3 # ************** <auto-copyright.pl BEGIN do not edit this line> **************
4 #
5 # VR Juggler is (C) Copyright 1998-2008 by Iowa State University
6 #
7 # Original Authors:
8 #   Allen Bierbaum, Christopher Just,
9 #   Patrick Hartling, Kevin Meinert,
10 #   Carolina Cruz-Neira, Albert Baker
11 #
12 # This library is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU Library General Public
14 # License as published by the Free Software Foundation; either
15 # version 2 of the License, or (at your option) any later version.
16 #
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 # Library General Public License for more details.
21 #
22 # You should have received a copy of the GNU Library General Public
23 # License along with this library; if not, write to the
24 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 # Boston, MA 02111-1307, USA.
26 #
27 # *************** <auto-copyright.pl END do not edit this line> ***************
28
29 # -----------------------------------------------------------------------------
30 # Generate Makefiles in the subdirectories of the installation directory
31 # (prefix) from Makefile.in's found in the source directory (startdir).  All
32 # command-line options shown here are required.
33 #
34 # Usage:
35 #     makefiles-gen.pl
36 #         --vars=<Path to a Perl file containing @..@ substitution values>
37 #         --srcdir=<Location of source code>
38 #         --prefix=<Base directory where Makefile will go>
39 #         --startdir=<Directory where search begins>
40 #         --uname=<Owner's user name>
41 #         --gname=<Group name>
42 #         --mode=<Mode bits>
43 #
44 # NOTE:
45 #    In almost every situation, the --srcdir option should be passed the
46 #    value "." so that the source in the installation directory will be used.
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 # Do this to include the path to the script in @INC.
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 # Turn off case insensitivity when parsing command-line options.
71 $Getopt::Long::ignorecase = 0;
72
73 # Initialize variables passed (by reference) to GetOptions();
74 %VARS = ();
75 @files = ();
76 ($var_file, $startdir, $prefix) = ('', '', '');
77 ($uname, $gname, $mode) = ('', '', '');
78
79 # Parse the command-line options and store the given values in %VARS which
80 # is indexed by the tag name to be replaced (e.g., 'CXX').
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
Note: See TracBrowser for help on using the browser.