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