1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
5 # Drop-in replacement for "ld" that supports munching.
7 # The first three lines above let this script run without specifying the
8 # full path to perl, as long as it is in the user's PATH.
9 # Taken from perlrun man page.
12 ## Symbols that produce a warning due to size changing.
13 ## This is a harmless known bug with the version of gcc that comes with
14 ## Tornado II. Anything in this list will be suppressed unless the -w
17 my(@symbols) = ('dequeue__t17ACE_Message_Queue1Z14ACE_NULL_SYNCHRP17ACE_Message_BlockP14ACE_Time_Value',
18 'activate__t17ACE_Message_Queue1Z14ACE_NULL_SYNCH',
22 "usage: $0 [-? | [-w] [-o <VDIR>] [[-C <compile> --] [-m <munch>] [-n <nm>]] [-f]]] " .
25 #### To avoid quoting problems on the command line, all arguments
26 #### between -C and -- are combined into the single compile command.
31 #### process command line args
33 while ( $#ARGV >= 0 && $ARGV[0] =~ /^-/ ) {
34 if ( $ARGV[0] eq '-C' ) {
36 if ( $ARGV[1] !~ /^[-].+$/ ) {
37 $compile = $ARGV[1]; shift;
39 print STDERR "$0: must provide argument for -c option\n";
42 } elsif ( $ARGV[0] eq '--' ) {
44 } elsif ( $ARGV[0] eq '-m' ) {
45 if ( $ARGV[1] !~ /^[-].+$/ ) {
46 $munch = $ARGV[1]; shift;
48 print STDERR "$0: must provide argument for -m option\n";
51 } elsif ( $ARGV[0] eq '-n' ) {
52 if ( $ARGV[1] !~ /^[-].+$/ ) {
53 $nm = $ARGV[1]; shift;
55 print STDERR "$0: must provide argument for -n option\n";
58 } elsif ( $ARGV[0] eq '-o' ) {
59 if ( $ARGV[1] !~ /^[-].+$/ ) {
60 $vdir = $ARGV[1]; shift;
62 print STDERR "$0: must provide argument for -o option\n";
65 } elsif ( $ARGV[0] eq '-w' ) {
67 } elsif ( $ARGV[0] eq '-?' ) {
71 if ($compile_option) {
72 $compile .= " $ARGV[0]";
74 warn "$0: unknown option $ARGV[0]\n";
82 #### If $vdir is empty, set default object file directory (.obj)
89 #### Save link command, i.e., current @ARGV, for use below.
95 #### Find full path to each library.
98 $current_dir_in_libDirs = 0;
102 foreach $arg (@ARGV) {
103 if ($arg =~ /^['"]?-L([\S]+)/) {
104 ($dir = $1) =~ s%/+$%%; #### trim any trailing slashes
105 push (@libDirs, $dir);
106 $current_dir_in_libDirs = 1 if $dir eq '.';
107 } elsif ($arg =~ /^['"]?-l([\S]+)/) {
109 } elsif ($arg =~ /\.o$/) {
114 #### Add . to libDirs if it doesn't already have it.
115 push (@libDirs, ".") unless $current_dir_in_libDirs;
117 foreach $lib (@libs) {
118 foreach $libDir (@libDirs) {
119 if (-e "$libDir/lib$lib.a") {
120 $full_path{$lib} = "$libDir/lib$lib.a";
128 #### Set up signal handler.
131 $SIG{'HUP'} = $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'TERM'} = 'cleanup';
135 #### Munch, if $munch is non-null.
138 $munch_objs = join (' ', @objs);
139 $munch_libs = join (' ', values %full_path);
141 open (MUNCH, "$nm $munch_objs $munch_libs | $munch |") ||
142 &fail ("$0: unable to run \"$nm\" or \"$munch\"\n");
144 open (CTORDTOR, "> __ctordtor.c") ||
145 &fail ("$0: unable to open \"__ctordtor.c\"\n");
148 #### Filter out munch output that contains '.cpp'. It results from
149 #### .cpp files that have no text or data, e.g., .cpp files that
150 #### only contain template instantiations. These lines confuse g++.
151 print CTORDTOR unless /\.cpp/;
154 close CTORDTOR || &fail ("$0: unable to write \"__ctordtor.c\"\n");
157 system ("$compile -o $vdir/__ctordtor.o __ctordtor.c") &&
158 &fail ("$0: \"$compile\" failed\n");
163 #### Construct the link command from @args and perform the link.
166 #### Insert ctordtor object file before first library in link command.
168 foreach $arg (@ARGV) {
169 if ($arg =~ /^['"]?-l/) {
174 splice (@args, $arg_lib, 0, "$vdir/__ctordtor.o");
177 $link_command = join (' ', @args);
179 if (open(PP, "$link_command 2>&1 |")) {
182 if ($ss_change_warn) {
187 foreach my $symbol (@symbols) {
188 if ($line =~ /Warning: size of symbol `$symbol\'/) {
200 fail ("$0: $link_command failed\n");
204 fail ("$0: $link_command failed\n");
216 local ($message) = @_;
224 #### clean up when done or on signal
227 unlink "__ctordtor.c", "$vdir/__ctordtor.o";