1cdf0e10cSrcweir: 2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3cdf0e10cSrcweir if 0; 4*7e90fac2SAndrew Rist#************************************************************** 5*7e90fac2SAndrew Rist# 6*7e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 7*7e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 8*7e90fac2SAndrew Rist# distributed with this work for additional information 9*7e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 10*7e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 11*7e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 12*7e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 13*7e90fac2SAndrew Rist# 14*7e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 15*7e90fac2SAndrew Rist# 16*7e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 17*7e90fac2SAndrew Rist# software distributed under the License is distributed on an 18*7e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19*7e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 20*7e90fac2SAndrew Rist# specific language governing permissions and limitations 21*7e90fac2SAndrew Rist# under the License. 22*7e90fac2SAndrew Rist# 23*7e90fac2SAndrew Rist#************************************************************** 24*7e90fac2SAndrew Rist 25*7e90fac2SAndrew Rist 26cdf0e10cSrcweir 27cdf0e10cSrcweir# 28cdf0e10cSrcweir# mkout.pl - create output tree 29cdf0e10cSrcweir# 30cdf0e10cSrcweir 31cdf0e10cSrcweiruse Cwd; 32cdf0e10cSrcweiruse Getopt::Std; 33cdf0e10cSrcweiruse File::Path; 34cdf0e10cSrcweir 35cdf0e10cSrcweir#### script id ##### 36cdf0e10cSrcweir 37cdf0e10cSrcweir( $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/; 38cdf0e10cSrcweir 39cdf0e10cSrcweir$id_str = ' $Revision: 1.8 $ '; 40cdf0e10cSrcweir$id_str =~ /Revision:\s+(\S+)\s+\$/ 41cdf0e10cSrcweir ? ($script_rev = $1) : ($script_rev = "-"); 42cdf0e10cSrcweir 43cdf0e10cSrcweirprint "$script_name -- version: $script_rev\n"; 44cdf0e10cSrcweir 45cdf0e10cSrcweir#### globals #### 46cdf0e10cSrcweir 47cdf0e10cSrcweir$is_debug = 0; 48cdf0e10cSrcweir 49cdf0e10cSrcweir$base_dir = 0; # path to module base directory 50cdf0e10cSrcweir$dir_mode = 0755; # default directory creation mode 51cdf0e10cSrcweir 52cdf0e10cSrcweir$envpath = 0; # platform/product combination 53cdf0e10cSrcweir$opt_r = 0; # create 'remote' subdirs 54cdf0e10cSrcweir 55cdf0e10cSrcweir%sub_dirs = ( 56cdf0e10cSrcweir# dirname remote(yes/no) 57cdf0e10cSrcweir 'bin' => 1, 58cdf0e10cSrcweir 'class' => 0, 59cdf0e10cSrcweir 'inc' => 0, 60cdf0e10cSrcweir 'lib' => 1, 61cdf0e10cSrcweir 'misc/logs' => 1, 62cdf0e10cSrcweir 'obj' => 1, 63cdf0e10cSrcweir 'res' => 1, 64cdf0e10cSrcweir 'slb' => 1, 65cdf0e10cSrcweir 'slo' => 1, 66cdf0e10cSrcweir 'srs' => 1 67cdf0e10cSrcweir ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir#### main #### 70cdf0e10cSrcweir 71cdf0e10cSrcweirparse_options(); 72cdf0e10cSrcweirinit_globals(); 73cdf0e10cSrcweircreate_dirs(); 74cdf0e10cSrcweir 75cdf0e10cSrcweirexit(0); 76cdf0e10cSrcweir 77cdf0e10cSrcweir#### subroutines ##### 78cdf0e10cSrcweir 79cdf0e10cSrcweirsub parse_options { 80cdf0e10cSrcweir my $rc; 81cdf0e10cSrcweir 82cdf0e10cSrcweir $rc = getopts('r'); 83cdf0e10cSrcweir 84cdf0e10cSrcweir if ( !$rc || $#ARGV > 0 ) { 85cdf0e10cSrcweir usage(); 86cdf0e10cSrcweir exit(1); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir $envpath = $ARGV[0] if defined($ARGV[0]); 89cdf0e10cSrcweir} 90cdf0e10cSrcweir 91cdf0e10cSrcweirsub init_globals { 92cdf0e10cSrcweir my $umask; 93cdf0e10cSrcweir $base_dir = get_base(); 94cdf0e10cSrcweir print "Base_Diri=$base_dir\n" if $is_debug; 95cdf0e10cSrcweir 96cdf0e10cSrcweir $umask = umask(); 97cdf0e10cSrcweir if ( defined($umask) ) { 98cdf0e10cSrcweir $dir_mode = 0777 - $umask; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir $envpath = $ENV{INPATH} unless $envpath; 101cdf0e10cSrcweir 102cdf0e10cSrcweir if ( !$envpath ) { 103cdf0e10cSrcweir print_error("can't determine platform/environment"); 104cdf0e10cSrcweir exit(3); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir print "Platform/Environment: $envpath\n" if $is_debug; 107cdf0e10cSrcweir} 108cdf0e10cSrcweir 109cdf0e10cSrcweirsub get_base { 110cdf0e10cSrcweir # a module base dir contains a subdir 'prj' 111cdf0e10cSrcweir # which in turn contains a file 'd.lst' 112cdf0e10cSrcweir my (@field, $base, $dlst); 113cdf0e10cSrcweir my $path = cwd(); 114cdf0e10cSrcweir 115cdf0e10cSrcweir @field = split(/\//, $path); 116cdf0e10cSrcweir 117cdf0e10cSrcweir while ( $#field != -1 ) { 118cdf0e10cSrcweir $base = join('/', @field); 119cdf0e10cSrcweir $dlst = $base . '/prj/d.lst'; 120cdf0e10cSrcweir last if -e $dlst; 121cdf0e10cSrcweir pop @field; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir if ( $#field == -1 ) { 125cdf0e10cSrcweir print_error("can't determine module"); 126cdf0e10cSrcweir exit(2); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir else { 129cdf0e10cSrcweir return $base; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir} 132cdf0e10cSrcweir 133cdf0e10cSrcweirsub create_dirs { 134cdf0e10cSrcweir foreach $dir ( keys %sub_dirs ) { 135cdf0e10cSrcweir $path = $base_dir . '/' . $envpath . '/' . $dir; 136cdf0e10cSrcweir if ( $opt_r && $sub_dirs{$dir} ) { 137cdf0e10cSrcweir $path .= "/remote"; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir eval { mkpath($path, 0, $dir_mode) }; 140cdf0e10cSrcweir if ( $@ ) { 141cdf0e10cSrcweir print_error( "$@" ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir print "Create path: $path\n" if $is_debug; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir} 146cdf0e10cSrcweir 147cdf0e10cSrcweirsub print_error { 148cdf0e10cSrcweir my $message = shift; 149cdf0e10cSrcweir 150cdf0e10cSrcweir print STDERR "$script_name: ERROR: $message\n"; 151cdf0e10cSrcweir} 152cdf0e10cSrcweir 153cdf0e10cSrcweirsub usage { 154cdf0e10cSrcweir print STDERR "Usage:\n$script_name [-r] [platform/environment]\n"; 155cdf0e10cSrcweir print STDERR "Options:\n -r create 'remote' directories\n"; 156cdf0e10cSrcweir} 157cdf0e10cSrcweir 158cdf0e10cSrcweir# vim: set ts=4 shiftwidth=4 expandtab syntax=perl: 159