summaryrefslogtreecommitdiff
path: root/ACE/bin/depgen.pl
blob: 814521f5b0bd3a04bd4976e1f570c84fb9577380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
    & eval 'exec perl -w -S $0 $argv:q'
    if 0;

# ************************************************************
# Description   : Generate dependencies for GNU Make and NMake.
# Author        : Chad Elliott
# Create Date   : 5/06/2002
#            $Id$
# ************************************************************

# ************************************************************
# Pragma Section
# ************************************************************

use strict;
use Config;
use FindBin;
use File::Spec;
use File::Basename;

my($basePath) = $FindBin::Bin;
if ($^O eq 'VMS') {
  $basePath = File::Spec->rel2abs(dirname($0)) if ($basePath eq '');
  $basePath = VMS::Filespec::unixify($basePath);
}
unshift(@INC, $basePath . '/DependencyGenerator');

require DependencyEditor;

# ************************************************************
# Data Section
# ************************************************************

my($version)  = '1.0';
my($os)       = ($^O eq 'MSWin32' ? 'Windows' : 'UNIX');
my(%types)    = ('gnu'   => 1,
                 'nmake' => 1,
                 'make'  => 1,
                );
my(%defaults) = ('UNIX'    => ['gnu'],
                 'Windows' => ['nmake'],
                );

# ************************************************************
# Subroutine Section
# ************************************************************

sub usageAndExit {
  my($opt)  = shift;
  my($base) = basename($0);

  if (defined $opt) {
    print "$opt.\n";
  }

  print "$base v$version\n" .
        "Usage: $base [-D<MACRO>[=VALUE]] [-I<include dir>] [-A] " .
        "[-R <VARNAME>]\n" .
        "       " . (" " x length($base)) .
        " [-e <file>] [-f <output file>] [-i] [-t <type>] [-n]\n" .
        "       " . (" " x length($base)) . " <files...>\n" .
        "\n" .
        "-D   This option sets a macro to an optional value.\n" .
        "-I   The -I option adds an include directory.\n" .
        "-A   Replace \$ACE_ROOT and \$TAO_ROOT paths with \$(ACE_ROOT) " .
        "and \$(TAO_ROOT)\n     respectively.\n" .
        "-R   Replace \$VARNAME paths with \$(VARNAME).\n" .
        "-e   Exclude dependencies generated by <file>, but not <file> " .
        "itself.\n" .
        "-f   Specifies the output file.  This file will be edited if it " .
        "already\n     exists.\n" .
        "-i   Do not print an error if no source files are provided.\n" .
        "-n   Do not include inline files (ending in .i or .inl) in the " .
        "dependencies.\n" .
        "-t   Use specified type (";
  my(@keys) = sort keys %types;
  for(my $i = 0; $i <= $#keys; ++$i) {
    print "$keys[$i]" .
          ($i != $#keys ? $i == $#keys - 1 ? ' or ' : ', ' : '');;
  }
  print ") instead of the default.\n" .
        "     The default is ";
  @keys = sort keys %defaults;
  for(my $i = 0; $i <= $#keys; ++$i) {
    my($def) = $keys[$i];
    print $defaults{$def}->[0] . " on $def" .
          ($i != $#keys ? $i == $#keys - 1 ? ' and ' : ', ' : '');
  }
  print ".\n";
  exit(0);
}


sub setReplace {
  my($replace) = shift;
  my($name)    = shift;
  my($value)   = shift;

  if (defined $name) {
    ## The key will be used in a regular expression.
    ## So, we need to escape some special characters.
    $name = File::Spec->canonpath($name);
    $name =~ s/([\+\-\\\$\[\]\(\)\.])/\\$1/g;

    $$replace{$name} = $value;
  }
}


# ************************************************************
# Main Section
# ************************************************************

my($type)     = $defaults{$os}->[0];
my($noinline) = undef;
my(@files)    = ();
my(%macros)   = ();
my(@ipaths)   = ();
my(%replace)  = ();
my(%exclude)  = ();
my($output)   = '-';
my($needsrc)  = 1;

if (defined $ENV{ACE_ROOT} && !defined $ENV{TAO_ROOT}) {
  $ENV{TAO_ROOT} = "$ENV{ACE_ROOT}/TAO";
}

for(my $i = 0; $i <= $#ARGV; ++$i) {
  my($arg) = $ARGV[$i];
  if ($arg =~ /^\-D(\w+)(=(.*))?/) {
    $macros{$1} = $3;
  }
  elsif ($arg =~ /^\-I(.*)/) {
    push(@ipaths, File::Spec->canonpath($1));
  }
  elsif ($arg eq '-A') {
    setReplace(\%replace, $ENV{ACE_ROOT}, '$(ACE_ROOT)');
    setReplace(\%replace, $ENV{TAO_ROOT}, '$(TAO_ROOT)');
    setReplace(\%replace, $ENV{ACE_PLATFORM_CONFIG}, '$(ACE_PLATFORM_CONFIG)');
  }
  elsif ($arg eq '-R') {
    ++$i;
    $arg = $ARGV[$i];
    if (defined $arg) {
      my($val) = $ENV{$arg};
      if (defined $val) {
        setReplace(\%replace, $val, "\$($arg)");
      }
    }
    else {
      usageAndExit('Invalid use of -R');
    }
  }
  elsif ($arg eq '-e') {
    ++$i;
    $arg = $ARGV[$i];
    if (defined $arg) {
      $exclude{$arg} = 1;
    }
    else {
      usageAndExit('Invalid use of -e');
    }
  }
  elsif ($arg eq '-f') {
    ++$i;
    $arg = $ARGV[$i];
    if (defined $arg) {
      $output = $arg;
    }
    else {
      usageAndExit('Invalid use of -f');
    }
  }
  elsif ($arg eq '-i') {
    $needsrc = undef;
  }
  elsif ($arg eq '-n') {
    $noinline = 1;
  }
  elsif ($arg eq '-h') {
    usageAndExit();
  }
  elsif ($arg eq '-t') {
    ++$i;
    $arg = $ARGV[$i];
    if (defined $arg && defined $types{$arg}) {
      $type = $arg;
    }
    else {
      usageAndExit('Invalid use of -t');
    }
  }
  elsif ($arg =~ /^[\-+]/) {
    ## We will ignore unknown options
    ## Some options for aCC start with +
  }
  else {
    push(@files, $arg);
  }
}

if (!defined $files[0]) {
  if ($needsrc) {
    usageAndExit('No files specified');
  }
}

my($editor) = new DependencyEditor();
exit($editor->process($output, $type, $noinline, \%macros,
                      \@ipaths, \%replace, \%exclude, \@files));