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