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