1cdf0e10cSrcweir: 2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3cdf0e10cSrcweir if 0; 47e90fac2SAndrew Rist#************************************************************** 57e90fac2SAndrew Rist# 67e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 77e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 87e90fac2SAndrew Rist# distributed with this work for additional information 97e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 107e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 117e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 127e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 137e90fac2SAndrew Rist# 147e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 157e90fac2SAndrew Rist# 167e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 177e90fac2SAndrew Rist# software distributed under the License is distributed on an 187e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 197e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 207e90fac2SAndrew Rist# specific language governing permissions and limitations 217e90fac2SAndrew Rist# under the License. 227e90fac2SAndrew Rist# 237e90fac2SAndrew Rist#************************************************************** 247e90fac2SAndrew Rist 257e90fac2SAndrew 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, 66*f110f213SArrigo Marchiori 'srs' => 1, 67*f110f213SArrigo Marchiori 'tmp' => 1 68cdf0e10cSrcweir ); 69cdf0e10cSrcweir 70cdf0e10cSrcweir#### main #### 71cdf0e10cSrcweir 72cdf0e10cSrcweirparse_options(); 73cdf0e10cSrcweirinit_globals(); 74cdf0e10cSrcweircreate_dirs(); 75cdf0e10cSrcweir 76cdf0e10cSrcweirexit(0); 77cdf0e10cSrcweir 78cdf0e10cSrcweir#### subroutines ##### 79cdf0e10cSrcweir 80cdf0e10cSrcweirsub parse_options { 81cdf0e10cSrcweir my $rc; 82cdf0e10cSrcweir 83cdf0e10cSrcweir $rc = getopts('r'); 84cdf0e10cSrcweir 85cdf0e10cSrcweir if ( !$rc || $#ARGV > 0 ) { 86cdf0e10cSrcweir usage(); 87cdf0e10cSrcweir exit(1); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir $envpath = $ARGV[0] if defined($ARGV[0]); 90cdf0e10cSrcweir} 91cdf0e10cSrcweir 92cdf0e10cSrcweirsub init_globals { 93cdf0e10cSrcweir my $umask; 94cdf0e10cSrcweir $base_dir = get_base(); 95cdf0e10cSrcweir print "Base_Diri=$base_dir\n" if $is_debug; 96cdf0e10cSrcweir 97cdf0e10cSrcweir $umask = umask(); 98cdf0e10cSrcweir if ( defined($umask) ) { 99cdf0e10cSrcweir $dir_mode = 0777 - $umask; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir $envpath = $ENV{INPATH} unless $envpath; 102cdf0e10cSrcweir 103cdf0e10cSrcweir if ( !$envpath ) { 104cdf0e10cSrcweir print_error("can't determine platform/environment"); 105cdf0e10cSrcweir exit(3); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir print "Platform/Environment: $envpath\n" if $is_debug; 108cdf0e10cSrcweir} 109cdf0e10cSrcweir 110cdf0e10cSrcweirsub get_base { 111cdf0e10cSrcweir # a module base dir contains a subdir 'prj' 112cdf0e10cSrcweir # which in turn contains a file 'd.lst' 113cdf0e10cSrcweir my (@field, $base, $dlst); 114cdf0e10cSrcweir my $path = cwd(); 115cdf0e10cSrcweir 116cdf0e10cSrcweir @field = split(/\//, $path); 117cdf0e10cSrcweir 118cdf0e10cSrcweir while ( $#field != -1 ) { 119cdf0e10cSrcweir $base = join('/', @field); 120cdf0e10cSrcweir $dlst = $base . '/prj/d.lst'; 121cdf0e10cSrcweir last if -e $dlst; 122cdf0e10cSrcweir pop @field; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir if ( $#field == -1 ) { 126cdf0e10cSrcweir print_error("can't determine module"); 127cdf0e10cSrcweir exit(2); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir else { 130cdf0e10cSrcweir return $base; 131cdf0e10cSrcweir } 132cdf0e10cSrcweir} 133cdf0e10cSrcweir 134cdf0e10cSrcweirsub create_dirs { 135cdf0e10cSrcweir foreach $dir ( keys %sub_dirs ) { 136cdf0e10cSrcweir $path = $base_dir . '/' . $envpath . '/' . $dir; 137cdf0e10cSrcweir if ( $opt_r && $sub_dirs{$dir} ) { 138cdf0e10cSrcweir $path .= "/remote"; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir eval { mkpath($path, 0, $dir_mode) }; 141cdf0e10cSrcweir if ( $@ ) { 142cdf0e10cSrcweir print_error( "$@" ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir print "Create path: $path\n" if $is_debug; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir} 147cdf0e10cSrcweir 148cdf0e10cSrcweirsub print_error { 149cdf0e10cSrcweir my $message = shift; 150cdf0e10cSrcweir 151cdf0e10cSrcweir print STDERR "$script_name: ERROR: $message\n"; 152cdf0e10cSrcweir} 153cdf0e10cSrcweir 154cdf0e10cSrcweirsub usage { 155cdf0e10cSrcweir print STDERR "Usage:\n$script_name [-r] [platform/environment]\n"; 156cdf0e10cSrcweir print STDERR "Options:\n -r create 'remote' directories\n"; 157cdf0e10cSrcweir} 158cdf0e10cSrcweir 159cdf0e10cSrcweir# vim: set ts=4 shiftwidth=4 expandtab syntax=perl: 160