]> git.saurik.com Git - wxWidgets.git/blob - build/aclocal/bakefile-dllar.m4
catch exceptions when sending menu events
[wxWidgets.git] / build / aclocal / bakefile-dllar.m4
1 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_DLLAR_SH],
2 [
3 dnl ===================== dllar.sh begins here =====================
4 dnl (Created by merge-scripts.py from dllar.sh
5 dnl file do not edit here!)
6 D='$'
7 cat <<EOF >dllar.sh
8 #!/bin/sh
9 #
10 # dllar - a tool to build both a .dll and an .a file
11 # from a set of object (.o) files for EMX/OS2.
12 #
13 # Written by Andrew Zabolotny, bit@freya.etu.ru
14 # Ported to Unix like shell by Stefan Neis, Stefan.Neis@t-online.de
15 #
16 # This script will accept a set of files on the command line.
17 # All the public symbols from the .o files will be exported into
18 # a .DEF file, then linker will be run (through gcc) against them to
19 # build a shared library consisting of all given .o files. All libraries
20 # (.a) will be first decompressed into component .o files then act as
21 # described above. You can optionally give a description (-d "description")
22 # which will be put into .DLL. To see the list of accepted options (as well
23 # as command-line format) simply run this program without options. The .DLL
24 # is built to be imported by name (there is no guarantee that new versions
25 # of the library you build will have same ordinals for same symbols).
26 #
27 # dllar is free software; you can redistribute it and/or modify
28 # it under the terms of the GNU General Public License as published by
29 # the Free Software Foundation; either version 2, or (at your option)
30 # any later version.
31 #
32 # dllar is distributed in the hope that it will be useful,
33 # but WITHOUT ANY WARRANTY; without even the implied warranty of
34 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 # GNU General Public License for more details.
36 #
37 # You should have received a copy of the GNU General Public License
38 # along with dllar; see the file COPYING. If not, write to the Free
39 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA
40 # 02111-1307, USA.
41
42 # To successfuly run this program you will need:
43 # - Current drive should have LFN support (HPFS, ext2, network, etc)
44 # (Sometimes dllar generates filenames which won't fit 8.3 scheme)
45 # - gcc
46 # (used to build the .dll)
47 # - emxexp
48 # (used to create .def file from .o files)
49 # - emximp
50 # (used to create .a file from .def file)
51 # - GNU text utilites (cat, sort, uniq)
52 # used to process emxexp output
53 # - GNU file utilities (mv, rm)
54 # - GNU sed
55 # - lxlite (optional, see flag below)
56 # (used for general .dll cleanup)
57 #
58
59 flag_USE_LXLITE=1;
60
61 #
62 # helper functions
63 # basnam, variant of basename, which does _not_ remove the path, _iff_
64 # second argument (suffix to remove) is given
65 basnam(){
66 case ${D}# in
67 1)
68 echo ${D}1 | sed 's/.*\\///' | sed 's/.*\\\\//'
69 ;;
70 2)
71 echo ${D}1 | sed 's/'${D}2'${D}//'
72 ;;
73 *)
74 echo "error in basnam ${D}*"
75 exit 8
76 ;;
77 esac
78 }
79
80 # Cleanup temporary files and output
81 CleanUp() {
82 cd ${D}curDir
83 for i in ${D}inputFiles ; do
84 case ${D}i in
85 *!)
86 rm -rf \`basnam ${D}i !\`
87 ;;
88 *)
89 ;;
90 esac
91 done
92
93 # Kill result in case of failure as there is just to many stupid make/nmake
94 # things out there which doesn't do this.
95 if @<:@ ${D}# -eq 0 @:>@; then
96 rm -f ${D}arcFile ${D}arcFile2 ${D}defFile ${D}dllFile
97 fi
98 }
99
100 # Print usage and exit script with rc=1.
101 PrintHelp() {
102 echo 'Usage: dllar.sh @<:@-o@<:@utput@:>@ output_file@:>@ @<:@-i@<:@mport@:>@ importlib_name@:>@'
103 echo ' @<:@-name-mangler-script script.sh@:>@'
104 echo ' @<:@-d@<:@escription@:>@ "dll descrption"@:>@ @<:@-cc "CC"@:>@ @<:@-f@<:@lags@:>@ "CFLAGS"@:>@'
105 echo ' @<:@-ord@<:@inals@:>@@:>@ -ex@<:@clude@:>@ "symbol(s)"'
106 echo ' @<:@-libf@<:@lags@:>@ "{INIT|TERM}{GLOBAL|INSTANCE}"@:>@ @<:@-nocrt@<:@dll@:>@@:>@ @<:@-nolxl@<:@ite@:>@@:>@'
107 echo ' @<:@*.o@:>@ @<:@*.a@:>@'
108 echo '*> "output_file" should have no extension.'
109 echo ' If it has the .o, .a or .dll extension, it is automatically removed.'
110 echo ' The import library name is derived from this and is set to "name".a,'
111 echo ' unless overridden by -import'
112 echo '*> "importlib_name" should have no extension.'
113 echo ' If it has the .o, or .a extension, it is automatically removed.'
114 echo ' This name is used as the import library name and may be longer and'
115 echo ' more descriptive than the DLL name which has to follow the old '
116 echo ' 8.3 convention of FAT.'
117 echo '*> "script.sh may be given to override the output_file name by a'
118 echo ' different name. It is mainly useful if the regular make process'
119 echo ' of some package does not take into account OS/2 restriction of'
120 echo ' DLL name lengths. It takes the importlib name as input and is'
121 echo ' supposed to procude a shorter name as output. The script should'
122 echo ' expect to get importlib_name without extension and should produce'
123 echo ' a (max.) 8 letter name without extension.'
124 echo '*> "cc" is used to use another GCC executable. (default: gcc.exe)'
125 echo '*> "flags" should be any set of valid GCC flags. (default: -s -Zcrtdll)'
126 echo ' These flags will be put at the start of GCC command line.'
127 echo '*> -ord@<:@inals@:>@ tells dllar to export entries by ordinals. Be careful.'
128 echo '*> -ex@<:@clude@:>@ defines symbols which will not be exported. You can define'
129 echo ' multiple symbols, for example -ex "myfunc yourfunc _GLOBAL*".'
130 echo ' If the last character of a symbol is "*", all symbols beginning'
131 echo ' with the prefix before "*" will be exclude, (see _GLOBAL* above).'
132 echo '*> -libf@<:@lags@:>@ can be used to add INITGLOBAL/INITINSTANCE and/or'
133 echo ' TERMGLOBAL/TERMINSTANCE flags to the dynamically-linked library.'
134 echo '*> -nocrt@<:@dll@:>@ switch will disable linking the library against emx''s'
135 echo ' C runtime DLLs.'
136 echo '*> -nolxl@<:@ite@:>@ switch will disable running lxlite on the resulting DLL.'
137 echo '*> All other switches (for example -L./ or -lmylib) will be passed'
138 echo ' unchanged to GCC at the end of command line.'
139 echo '*> If you create a DLL from a library and you do not specify -o,'
140 echo ' the basename for DLL and import library will be set to library name,'
141 echo ' the initial library will be renamed to 'name'_s.a (_s for static)'
142 echo ' i.e. "dllar gcc.a" will create gcc.dll and gcc.a, and the initial'
143 echo ' library will be renamed into gcc_s.a.'
144 echo '--------'
145 echo 'Example:'
146 echo ' dllar -o gcc290.dll libgcc.a -d "GNU C runtime library" -ord'
147 echo ' -ex "__main __ctordtor*" -libf "INITINSTANCE TERMINSTANCE"'
148 CleanUp
149 exit 1
150 }
151
152 # Execute a command.
153 # If exit code of the commnad <> 0 CleanUp() is called and we'll exit the script.
154 # @Uses Whatever CleanUp() uses.
155 doCommand() {
156 echo "${D}*"
157 eval ${D}*
158 rcCmd=${D}?
159
160 if @<:@ ${D}rcCmd -ne 0 @:>@; then
161 echo "command failed, exit code="${D}rcCmd
162 CleanUp
163 exit ${D}rcCmd
164 fi
165 }
166
167 # main routine
168 # setup globals
169 cmdLine=${D}*
170 outFile=""
171 outimpFile=""
172 inputFiles=""
173 renameScript=""
174 description=""
175 CC=gcc.exe
176 CFLAGS="-s -Zcrtdll"
177 EXTRA_CFLAGS=""
178 EXPORT_BY_ORDINALS=0
179 exclude_symbols=""
180 library_flags=""
181 curDir=\`pwd\`
182 curDirS=curDir
183 case ${D}curDirS in
184 */)
185 ;;
186 *)
187 curDirS=${D}{curDirS}"/"
188 ;;
189 esac
190 # Parse commandline
191 libsToLink=0
192 omfLinking=0
193 while @<:@ ${D}1 @:>@; do
194 case ${D}1 in
195 -ord*)
196 EXPORT_BY_ORDINALS=1;
197 ;;
198 -o*)
199 shift
200 outFile=${D}1
201 ;;
202 -i*)
203 shift
204 outimpFile=${D}1
205 ;;
206 -name-mangler-script)
207 shift
208 renameScript=${D}1
209 ;;
210 -d*)
211 shift
212 description=${D}1
213 ;;
214 -f*)
215 shift
216 CFLAGS=${D}1
217 ;;
218 -c*)
219 shift
220 CC=${D}1
221 ;;
222 -h*)
223 PrintHelp
224 ;;
225 -ex*)
226 shift
227 exclude_symbols=${D}{exclude_symbols}${D}1" "
228 ;;
229 -libf*)
230 shift
231 library_flags=${D}{library_flags}${D}1" "
232 ;;
233 -nocrt*)
234 CFLAGS="-s"
235 ;;
236 -nolxl*)
237 flag_USE_LXLITE=0
238 ;;
239 -* | /*)
240 case ${D}1 in
241 -L* | -l*)
242 libsToLink=1
243 ;;
244 -Zomf)
245 omfLinking=1
246 ;;
247 *)
248 ;;
249 esac
250 EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
251 ;;
252 *.dll)
253 EXTRA_CFLAGS="${D}{EXTRA_CFLAGS} \`basnam ${D}1 .dll\`"
254 if @<:@ ${D}omfLinking -eq 1 @:>@; then
255 EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.lib"
256 else
257 EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.a"
258 fi
259 ;;
260 *)
261 found=0;
262 if @<:@ ${D}libsToLink -ne 0 @:>@; then
263 EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
264 else
265 for file in ${D}1 ; do
266 if @<:@ -f ${D}file @:>@; then
267 inputFiles="${D}{inputFiles} ${D}file"
268 found=1
269 fi
270 done
271 if @<:@ ${D}found -eq 0 @:>@; then
272 echo "ERROR: No file(s) found: "${D}1
273 exit 8
274 fi
275 fi
276 ;;
277 esac
278 shift
279 done # iterate cmdline words
280
281 #
282 if @<:@ -z "${D}inputFiles" @:>@; then
283 echo "dllar: no input files"
284 PrintHelp
285 fi
286
287 # Now extract all .o files from .a files
288 newInputFiles=""
289 for file in ${D}inputFiles ; do
290 case ${D}file in
291 *.a | *.lib)
292 case ${D}file in
293 *.a)
294 suffix=".a"
295 AR="ar"
296 ;;
297 *.lib)
298 suffix=".lib"
299 AR="emxomfar"
300 EXTRA_CFLAGS="${D}EXTRA_CFLAGS -Zomf"
301 ;;
302 *)
303 ;;
304 esac
305 dirname=\`basnam ${D}file ${D}suffix\`"_%"
306 mkdir ${D}dirname
307 if @<:@ ${D}? -ne 0 @:>@; then
308 echo "Failed to create subdirectory ./${D}dirname"
309 CleanUp
310 exit 8;
311 fi
312 # Append '!' to indicate archive
313 newInputFiles="${D}newInputFiles ${D}{dirname}!"
314 doCommand "cd ${D}dirname; ${D}AR x ../${D}file"
315 cd ${D}curDir
316 found=0;
317 for subfile in ${D}dirname/*.o* ; do
318 if @<:@ -f ${D}subfile @:>@; then
319 found=1
320 if @<:@ -s ${D}subfile @:>@; then
321 # FIXME: This should be: is file size > 32 byte, _not_ > 0!
322 newInputFiles="${D}newInputFiles ${D}subfile"
323 fi
324 fi
325 done
326 if @<:@ ${D}found -eq 0 @:>@; then
327 echo "WARNING: there are no files in archive \\'${D}file\\'"
328 fi
329 ;;
330 *)
331 newInputFiles="${D}{newInputFiles} ${D}file"
332 ;;
333 esac
334 done
335 inputFiles="${D}newInputFiles"
336
337 # Output filename(s).
338 do_backup=0;
339 if @<:@ -z ${D}outFile @:>@; then
340 do_backup=1;
341 set outFile ${D}inputFiles; outFile=${D}2
342 fi
343
344 # If it is an archive, remove the '!' and the '_%' suffixes
345 case ${D}outFile in
346 *_%!)
347 outFile=\`basnam ${D}outFile _%!\`
348 ;;
349 *)
350 ;;
351 esac
352 case ${D}outFile in
353 *.dll)
354 outFile=\`basnam ${D}outFile .dll\`
355 ;;
356 *.DLL)
357 outFile=\`basnam ${D}outFile .DLL\`
358 ;;
359 *.o)
360 outFile=\`basnam ${D}outFile .o\`
361 ;;
362 *.obj)
363 outFile=\`basnam ${D}outFile .obj\`
364 ;;
365 *.a)
366 outFile=\`basnam ${D}outFile .a\`
367 ;;
368 *.lib)
369 outFile=\`basnam ${D}outFile .lib\`
370 ;;
371 *)
372 ;;
373 esac
374 case ${D}outimpFile in
375 *.a)
376 outimpFile=\`basnam ${D}outimpFile .a\`
377 ;;
378 *.lib)
379 outimpFile=\`basnam ${D}outimpFile .lib\`
380 ;;
381 *)
382 ;;
383 esac
384 if @<:@ -z ${D}outimpFile @:>@; then
385 outimpFile=${D}outFile
386 fi
387 defFile="${D}{outFile}.def"
388 arcFile="${D}{outimpFile}.a"
389 arcFile2="${D}{outimpFile}.lib"
390
391 #create ${D}dllFile as something matching 8.3 restrictions,
392 if @<:@ -z ${D}renameScript @:>@ ; then
393 dllFile="${D}outFile"
394 else
395 dllFile=\`${D}renameScript ${D}outimpFile\`
396 fi
397
398 if @<:@ ${D}do_backup -ne 0 @:>@ ; then
399 if @<:@ -f ${D}arcFile @:>@ ; then
400 doCommand "mv ${D}arcFile ${D}{outFile}_s.a"
401 fi
402 if @<:@ -f ${D}arcFile2 @:>@ ; then
403 doCommand "mv ${D}arcFile2 ${D}{outFile}_s.lib"
404 fi
405 fi
406
407 # Extract public symbols from all the object files.
408 tmpdefFile=${D}{defFile}_%
409 rm -f ${D}tmpdefFile
410 for file in ${D}inputFiles ; do
411 case ${D}file in
412 *!)
413 ;;
414 *)
415 doCommand "emxexp -u ${D}file >> ${D}tmpdefFile"
416 ;;
417 esac
418 done
419
420 # Create the def file.
421 rm -f ${D}defFile
422 echo "LIBRARY \`basnam ${D}dllFile\` ${D}library_flags" >> ${D}defFile
423 dllFile="${D}{dllFile}.dll"
424 if @<:@ ! -z ${D}description @:>@; then
425 echo "DESCRIPTION \\"${D}{description}\\"" >> ${D}defFile
426 fi
427 echo "EXPORTS" >> ${D}defFile
428
429 doCommand "cat ${D}tmpdefFile | sort.exe | uniq.exe > ${D}{tmpdefFile}%"
430 grep -v "^ *;" < ${D}{tmpdefFile}% | grep -v "^ *${D}" >${D}tmpdefFile
431
432 # Checks if the export is ok or not.
433 for word in ${D}exclude_symbols; do
434 grep -v ${D}word < ${D}tmpdefFile >${D}{tmpdefFile}%
435 mv ${D}{tmpdefFile}% ${D}tmpdefFile
436 done
437
438
439 if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
440 sed "=" < ${D}tmpdefFile | \\
441 sed '
442 N
443 : loop
444 s/^\\(@<:@0-9@:>@\\+\\)\\(@<:@^;@:>@*\\)\\(;.*\\)\\?/\\2 @\\1 NONAME/
445 t loop
446 ' > ${D}{tmpdefFile}%
447 grep -v "^ *${D}" < ${D}{tmpdefFile}% > ${D}tmpdefFile
448 else
449 rm -f ${D}{tmpdefFile}%
450 fi
451 cat ${D}tmpdefFile >> ${D}defFile
452 rm -f ${D}tmpdefFile
453
454 # Do linking, create implib, and apply lxlite.
455 gccCmdl="";
456 for file in ${D}inputFiles ; do
457 case ${D}file in
458 *!)
459 ;;
460 *)
461 gccCmdl="${D}gccCmdl ${D}file"
462 ;;
463 esac
464 done
465 doCommand "${D}CC ${D}CFLAGS -Zdll -o ${D}dllFile ${D}defFile ${D}gccCmdl ${D}EXTRA_CFLAGS"
466 touch "${D}{outFile}.dll"
467
468 doCommand "emximp -o ${D}arcFile ${D}defFile"
469 if @<:@ ${D}flag_USE_LXLITE -ne 0 @:>@; then
470 add_flags="";
471 if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
472 add_flags="-ynd"
473 fi
474 doCommand "lxlite -cs -t: -mrn -mln ${D}add_flags ${D}dllFile"
475 fi
476 doCommand "emxomf -s -l ${D}arcFile"
477
478 # Successful exit.
479 CleanUp 1
480 exit 0
481 EOF
482 dnl ===================== dllar.sh ends here =====================
483 ])