xref: /aoo4110/main/solenv/bin/mkout.pl (revision b1cdbd2c)
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            );
68
69#### main ####
70
71parse_options();
72init_globals();
73create_dirs();
74
75exit(0);
76
77#### subroutines #####
78
79sub parse_options {
80    my $rc;
81
82    $rc = getopts('r');
83
84    if ( !$rc || $#ARGV > 0 ) {
85        usage();
86        exit(1);
87    }
88    $envpath = $ARGV[0] if defined($ARGV[0]);
89}
90
91sub init_globals {
92    my $umask;
93    $base_dir =  get_base();
94    print "Base_Diri=$base_dir\n" if $is_debug;
95
96    $umask = umask();
97    if ( defined($umask) ) {
98        $dir_mode = 0777 - $umask;
99    }
100    $envpath = $ENV{INPATH} unless $envpath;
101
102    if ( !$envpath ) {
103        print_error("can't determine platform/environment");
104        exit(3);
105    }
106    print "Platform/Environment: $envpath\n" if $is_debug;
107}
108
109sub get_base {
110    # a module base dir contains a subdir 'prj'
111    # which in turn contains a file 'd.lst'
112    my (@field, $base, $dlst);
113    my $path = cwd();
114
115    @field = split(/\//, $path);
116
117    while ( $#field != -1 ) {
118        $base = join('/', @field);
119        $dlst = $base . '/prj/d.lst';
120        last if -e $dlst;
121        pop @field;
122    }
123
124    if ( $#field == -1 ) {
125        print_error("can't determine module");
126        exit(2);
127    }
128    else {
129        return $base;
130    }
131}
132
133sub create_dirs {
134    foreach $dir ( keys %sub_dirs ) {
135        $path = $base_dir . '/' . $envpath . '/' . $dir;
136        if ( $opt_r && $sub_dirs{$dir} ) {
137            $path .= "/remote";
138        }
139        eval { mkpath($path, 0, $dir_mode) };
140        if ( $@ ) {
141            print_error( "$@" );
142        }
143        print "Create path: $path\n" if $is_debug;
144    }
145}
146
147sub print_error {
148    my $message = shift;
149
150    print STDERR "$script_name: ERROR: $message\n";
151}
152
153sub usage {
154    print STDERR "Usage:\n$script_name [-r] [platform/environment]\n";
155    print STDERR "Options:\n  -r create 'remote' directories\n";
156}
157
158# vim: set ts=4 shiftwidth=4 expandtab syntax=perl:
159