update dev300-m58
[ooovba.git] / solenv / bin / mkout.pl
blob6d7cc7104ddffbad86c39ceaa025720995b99f80
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: mkout.pl,v $
14 # $Revision: 1.8 $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
36 # mkout.pl - create output tree
39 use Cwd;
40 use Getopt::Std;
41 use File::Path;
43 #### script id #####
45 ( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
47 $id_str = ' $Revision: 1.8 $ ';
48 $id_str =~ /Revision:\s+(\S+)\s+\$/
49 ? ($script_rev = $1) : ($script_rev = "-");
51 print "$script_name -- version: $script_rev\n";
53 #### globals ####
55 $is_debug = 0;
57 $base_dir = 0; # path to module base directory
58 $dir_mode = 0755; # default directory creation mode
60 $envpath = 0; # platform/product combination
61 $opt_r = 0; # create 'remote' subdirs
63 %sub_dirs = (
64 # dirname remote(yes/no)
65 'bin' => 1,
66 'class' => 0,
67 'inc' => 0,
68 'lib' => 1,
69 'misc/logs' => 1,
70 'obj' => 1,
71 'res' => 1,
72 'slb' => 1,
73 'slo' => 1,
74 'srs' => 1
77 #### main ####
79 parse_options();
80 init_globals();
81 create_dirs();
83 exit(0);
85 #### subroutines #####
87 sub parse_options {
88 my $rc;
90 $rc = getopts('r');
92 if ( !$rc || $#ARGV > 0 ) {
93 usage();
94 exit(1);
96 $envpath = $ARGV[0] if defined($ARGV[0]);
99 sub init_globals {
100 my $umask;
101 $base_dir = get_base();
102 print "Base_Diri=$base_dir\n" if $is_debug;
104 $umask = umask();
105 if ( defined($umask) ) {
106 $dir_mode = 0777 - $umask;
108 $envpath = $ENV{INPATH} unless $envpath;
110 if ( !$envpath ) {
111 print_error("can't determine platform/environment");
112 exit(3);
114 print "Platform/Environment: $envpath\n" if $is_debug;
117 sub get_base {
118 # a module base dir contains a subdir 'prj'
119 # which in turn contains a file 'd.lst'
120 my (@field, $base, $dlst);
121 my $path = cwd();
123 @field = split(/\//, $path);
125 while ( $#field != -1 ) {
126 $base = join('/', @field);
127 $dlst = $base . '/prj/d.lst';
128 last if -e $dlst;
129 pop @field;
132 if ( $#field == -1 ) {
133 print_error("can't determine module");
134 exit(2);
136 else {
137 return $base;
141 sub create_dirs {
142 foreach $dir ( keys %sub_dirs ) {
143 $path = $base_dir . '/' . $envpath . '/' . $dir;
144 if ( $opt_r && $sub_dirs{$dir} ) {
145 $path .= "/remote";
147 eval { mkpath($path, 0, $dir_mode) };
148 if ( $@ ) {
149 print_error( "$@" );
151 print "Create path: $path\n" if $is_debug;
155 sub print_error {
156 my $message = shift;
158 print STDERR "$script_name: ERROR: $message\n";
161 sub usage {
162 print STDERR "Usage:\n$script_name [-r] [platform/environment]\n";
163 print STDERR "Options:\n -r create 'remote' directories\n";
166 # vim: set ts=4 shiftwidth=4 expandtab syntax=perl: