1 AC_DEFUN([AC_BAKEFILE_CREATE_FILE_DLLAR_SH],
3 dnl ===================== dllar.sh begins here =====================
4 dnl (Created by merge-scripts.py from dllar.sh
5 dnl file do not edit here!)
10 # dllar - a tool to build both a .dll and an .a file
11 # from a set of object (.o) files for EMX/OS2.
13 # Written by Andrew Zabolotny, bit@freya.etu.ru
14 # Ported to Unix like shell by Stefan Neis, Stefan.Neis@t-online.de
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).
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)
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.
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
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)
46 # (used to build the .dll)
48 # (used to create .def file from .o files)
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)
55 # - lxlite (optional, see flag below)
56 # (used for general .dll cleanup)
63 # basnam, variant of basename, which does _not_ remove the path, _iff_
64 # second argument (suffix to remove) is given
68 echo ${D}1 | sed 's/.*\\///' | sed 's/.*\\\\//'
71 echo ${D}1 | sed 's/'${D}2'${D}//'
74 echo "error in basnam ${D}*"
80 # Cleanup temporary files and output
83 for i in ${D}inputFiles ; do
86 rm -rf \`basnam ${D}i !\`
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
100 # Print usage and exit script with rc=1.
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.'
146 echo ' dllar -o gcc290.dll libgcc.a -d "GNU C runtime library" -ord'
147 echo ' -ex "__main __ctordtor*" -libf "INITINSTANCE TERMINSTANCE"'
153 # If exit code of the commnad <> 0 CleanUp() is called and we'll exit the script.
154 # @Uses Whatever CleanUp() uses.
160 if @<:@ ${D}rcCmd -ne 0 @:>@; then
161 echo "command failed, exit code="${D}rcCmd
187 curDirS=${D}{curDirS}"/"
193 while @<:@ ${D}1 @:>@; do
196 EXPORT_BY_ORDINALS=1;
206 -name-mangler-script)
227 exclude_symbols=${D}{exclude_symbols}${D}1" "
231 library_flags=${D}{library_flags}${D}1" "
250 EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
253 EXTRA_CFLAGS="${D}{EXTRA_CFLAGS} \`basnam ${D}1 .dll\`"
254 if @<:@ ${D}omfLinking -eq 1 @:>@; then
255 EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.lib"
257 EXTRA_CFLAGS="${D}{EXTRA_CFLAGS}.a"
262 if @<:@ ${D}libsToLink -ne 0 @:>@; then
263 EXTRA_CFLAGS=${D}{EXTRA_CFLAGS}" "${D}1
265 for file in ${D}1 ; do
266 if @<:@ -f ${D}file @:>@; then
267 inputFiles="${D}{inputFiles} ${D}file"
271 if @<:@ ${D}found -eq 0 @:>@; then
272 echo "ERROR: No file(s) found: "${D}1
279 done # iterate cmdline words
282 if @<:@ -z "${D}inputFiles" @:>@; then
283 echo "dllar: no input files"
287 # Now extract all .o files from .a files
289 for file in ${D}inputFiles ; do
300 EXTRA_CFLAGS="${D}EXTRA_CFLAGS -Zomf"
305 dirname=\`basnam ${D}file ${D}suffix\`"_%"
307 if @<:@ ${D}? -ne 0 @:>@; then
308 echo "Failed to create subdirectory ./${D}dirname"
312 # Append '!' to indicate archive
313 newInputFiles="${D}newInputFiles ${D}{dirname}!"
314 doCommand "cd ${D}dirname; ${D}AR x ../${D}file"
317 for subfile in ${D}dirname/*.o* ; do
318 if @<:@ -f ${D}subfile @:>@; then
320 if @<:@ -s ${D}subfile @:>@; then
321 # FIXME: This should be: is file size > 32 byte, _not_ > 0!
322 newInputFiles="${D}newInputFiles ${D}subfile"
326 if @<:@ ${D}found -eq 0 @:>@; then
327 echo "WARNING: there are no files in archive \\'${D}file\\'"
331 newInputFiles="${D}{newInputFiles} ${D}file"
335 inputFiles="${D}newInputFiles"
337 # Output filename(s).
339 if @<:@ -z ${D}outFile @:>@; then
341 set outFile ${D}inputFiles; outFile=${D}2
344 # If it is an archive, remove the '!' and the '_%' suffixes
347 outFile=\`basnam ${D}outFile _%!\`
354 outFile=\`basnam ${D}outFile .dll\`
357 outFile=\`basnam ${D}outFile .DLL\`
360 outFile=\`basnam ${D}outFile .o\`
363 outFile=\`basnam ${D}outFile .obj\`
366 outFile=\`basnam ${D}outFile .a\`
369 outFile=\`basnam ${D}outFile .lib\`
374 case ${D}outimpFile in
376 outimpFile=\`basnam ${D}outimpFile .a\`
379 outimpFile=\`basnam ${D}outimpFile .lib\`
384 if @<:@ -z ${D}outimpFile @:>@; then
385 outimpFile=${D}outFile
387 defFile="${D}{outFile}.def"
388 arcFile="${D}{outimpFile}.a"
389 arcFile2="${D}{outimpFile}.lib"
391 #create ${D}dllFile as something matching 8.3 restrictions,
392 if @<:@ -z ${D}renameScript @:>@ ; then
393 dllFile="${D}outFile"
395 dllFile=\`${D}renameScript ${D}outimpFile\`
398 if @<:@ ${D}do_backup -ne 0 @:>@ ; then
399 if @<:@ -f ${D}arcFile @:>@ ; then
400 doCommand "mv ${D}arcFile ${D}{outFile}_s.a"
402 if @<:@ -f ${D}arcFile2 @:>@ ; then
403 doCommand "mv ${D}arcFile2 ${D}{outFile}_s.lib"
407 # Extract public symbols from all the object files.
408 tmpdefFile=${D}{defFile}_%
410 for file in ${D}inputFiles ; do
415 doCommand "emxexp -u ${D}file >> ${D}tmpdefFile"
420 # Create the def file.
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
427 echo "EXPORTS" >> ${D}defFile
429 doCommand "cat ${D}tmpdefFile | sort.exe | uniq.exe > ${D}{tmpdefFile}%"
430 grep -v "^ *;" < ${D}{tmpdefFile}% | grep -v "^ *${D}" >${D}tmpdefFile
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
439 if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
440 sed "=" < ${D}tmpdefFile | \\
444 s/^\\(@<:@0-9@:>@\\+\\)\\(@<:@^;@:>@*\\)\\(;.*\\)\\?/\\2 @\\1 NONAME/
446 ' > ${D}{tmpdefFile}%
447 grep -v "^ *${D}" < ${D}{tmpdefFile}% > ${D}tmpdefFile
449 rm -f ${D}{tmpdefFile}%
451 cat ${D}tmpdefFile >> ${D}defFile
454 # Do linking, create implib, and apply lxlite.
456 for file in ${D}inputFiles ; do
461 gccCmdl="${D}gccCmdl ${D}file"
465 doCommand "${D}CC ${D}CFLAGS -Zdll -o ${D}dllFile ${D}defFile ${D}gccCmdl ${D}EXTRA_CFLAGS"
466 touch "${D}{outFile}.dll"
468 doCommand "emximp -o ${D}arcFile ${D}defFile"
469 if @<:@ ${D}flag_USE_LXLITE -ne 0 @:>@; then
471 if @<:@ ${D}EXPORT_BY_ORDINALS -ne 0 @:>@; then
474 doCommand "lxlite -cs -t: -mrn -mln ${D}add_flags ${D}dllFile"
476 doCommand "emxomf -s -l ${D}arcFile"
482 dnl ===================== dllar.sh ends here =====================