2 # Perl script be a wrapper around the gnu ld. When a dll is specified to
3 # to be built, special processing is done, else the standard ld is called.
5 # Modified 3/14/97 to include the impure_ptr setup routine in init.cc
6 # Modified to make dll in current directory then copy to another dir if
7 # a path name specified on the command name with the -o parm.
10 my $args = join(" ",@ARGV); # get args
25 if( $args=~/\-o (.+?)\.dll/i){
27 # print "libname = <$libname>\n";
29 if( $libname =~ /($\.+?\/)(\w+$)/){
32 # print "<$path> <$libname>\n";
40 if( $arg =~/\-o/ or $arg =~ /.+?\.dll/i ){
48 $command = "gcc -c $fixup.c\n";
50 system($command) == 0 or die "system() failed.\n";
51 $command = "gcc -c $init.cc\n";
53 system($command) == 0 or die "system() failed.\n";
55 $command = "echo EXPORTS > $libname.def\n";
57 system($command) == 0 or die "system() failed.\n";
58 $command = "nm ".join(" ",@objs)." $init.o $fixup.o | grep '^........ [TCD] _' | sed 's/[^_]*_//' >> $libname.def\n";
60 system($command) == 0 or die "system() failed.\n";
62 $command = "ld --base-file $libname.base --dll -o $libname.dll ".join(" ",@objs)." $init.o $fixup.o ";
63 $command .= join(" ",@flags)." -e _dll_entry\@12 \n";
65 system($command) == 0 or die "system() failed.\n";
67 $command = "dlltool --as=as --dllname $libname.dll --def $libname.def --base-file $libname.base --output-exp $libname.exp\n";
69 system($command) == 0 or die "system() failed.\n";
71 $command = "ld --base-file $libname.base $libname.exp --dll -o $libname.dll ".join(" ",@objs)." $init.o $fixup.o ";
72 $command .= join(" ",@flags)." -e _dll_entry\@12 \n";
74 system($command) == 0 or die "system() failed.\n";
76 $command = "dlltool --as=as --dllname $libname.dll --def $libname.def --base-file $libname.base --output-exp $libname.exp\n";
78 system($command) == 0 or die "system() failed.\n";
80 $command = "ld $libname.exp --dll -o $libname.dll ".join(" ",@objs)." $init.o $fixup.o ";
81 $command .= join(" ",@flags)." -e _dll_entry\@12 \n";
83 system($command) == 0 or die "system() failed.\n";
85 print "Build the import lib\n";
86 $command = "dlltool --as=as --dllname $libname.dll --def $libname.def --output-lib $libname.a\n";
88 system($command) == 0 or die "system() failed.\n";
90 # if there was originally a path, copy the dll and a to that location:
91 if($path && $path ne "./" && $path."\n" ne "`pwd`"){
92 $command = "mv $libname.dll $path".$libname.".dll\n";
94 system($command) == 0 or die "system() failed.\n";
95 $command = "mv $libname.a $path".$libname.".a\n";
97 system($command) == 0 or die "system() failed.\n";
102 else{ # no special processing, just call ld
103 $command = "ld $args\n";
105 system($command) == 0 or die "system() failed.\n";
108 #---------------------------------------------------------------------------
111 open(OUTFILE,">$init.cc") or die("Can't open $init.cc\n");
113 print OUTFILE <<'EOF';
114 /* init.cc for WIN32.
116 Copyright 1996 Cygnus Solutions
118 This program is free software; you can redistribute it and/or modify
119 it under the terms of the GNU General Public License as published by
120 the Free Software Foundation; either version 2 of the License, or
121 (at your option) any later version.
123 This program is distributed in the hope that it will be useful,
124 but WITHOUT ANY WARRANTY; without even the implied warranty of
125 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
126 GNU General Public License for more details.
128 You should have received a copy of the GNU General Public License
129 along with this program; if not, write to the Free Software
130 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
132 // Added impure_ptr initialization routine. This is needed for any DLL that needs
133 // to output to the main (calling) executable's stdout, stderr, etc. This routine
134 // needs to be called from the executable using the DLL before any other DLL
135 // routines are called. jc 3/14/97
141 int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr);
142 void impure_setup(struct _reent *_impure_ptrMain);
145 struct _reent *_impure_ptr; // this will be the Dlls local copy of impure ptr
147 int WINAPI dll_entry (HANDLE ,
153 case DLL_PROCESS_ATTACH:
155 case DLL_PROCESS_DETACH:
157 case DLL_THREAD_ATTACH:
159 case DLL_THREAD_DETACH:
166 //********************************************
167 // Function to set our local (in this dll) copy of impure_ptr to the
168 // main's (calling executable's) impure_ptr
169 void impure_setup(struct _reent *_impure_ptrMain){
171 _impure_ptr = _impure_ptrMain;
180 #---------------------------------------------------------------------------
183 open(OUTFILE,">$fixup.c") or die("Can't open $fixup.c\n");
185 print OUTFILE <<'EOF';
186 /* This is needed to terminate the list of inport stuff */
187 /* Copied from winsup/dcrt0.cc in the cygwin32 source distribution. */
188 asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0");