]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/dllar.sh
   3 # dllar - a tool to build both a .dll and an .a file 
   4 # from a set of object (.o) files for EMX/OS2. 
   6 #  Written by Andrew Zabolotny, bit@freya.etu.ru 
   7 #  Ported to Unix like shell by Stefan Neis, Stefan.Neis@t-online.de 
   9 #  This script will accept a set of files on the command line. 
  10 #  All the public symbols from the .o files will be exported into 
  11 #  a .DEF file, then linker will be run (through gcc) against them to 
  12 #  build a shared library consisting of all given .o files. All libraries 
  13 #  (.a) will be first decompressed into component .o files then act as 
  14 #  described above. You can optionally give a description (-d "description") 
  15 #  which will be put into .DLL. To see the list of accepted options (as well 
  16 #  as command-line format) simply run this program without options. The .DLL 
  17 #  is built to be imported by name (there is no guarantee that new versions 
  18 #  of the library you build will have same ordinals for same symbols). 
  20 #  dllar is free software; you can redistribute it and/or modify 
  21 #  it under the terms of the GNU General Public License as published by 
  22 #  the Free Software Foundation; either version 2, or (at your option) 
  25 #  dllar is distributed in the hope that it will be useful, 
  26 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  27 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  28 #  GNU General Public License for more details. 
  30 #  You should have received a copy of the GNU General Public License 
  31 #  along with dllar; see the file COPYING.  If not, write to the Free 
  32 #  Software Foundation, 59 Temple Place - Suite 330, Boston, MA 
  35 # To successfuly run this program you will need: 
  36 #  - Current drive should have LFN support (HPFS, ext2, network, etc) 
  37 #    (Sometimes dllar generates filenames which won't fit 8.3 scheme) 
  39 #    (used to build the .dll) 
  41 #    (used to create .def file from .o files) 
  43 #    (used to create .a file from .def file) 
  44 #  - GNU text utilites (cat, sort, uniq) 
  45 #    used to process emxexp output 
  46 #  - GNU file utilities (mv, rm) 
  48 #  - lxlite (optional, see flag below) 
  49 #    (used for general .dll cleanup) 
  56 # basnam, variant of basename, which does _not_ remove the path, _iff_ 
  57 #                              second argument (suffix to remove) is given 
  61         echo $1 | sed 's/.*\///' | sed 's/.*\\//' 
  64         echo $1 | sed 's/'$2'$//' 
  67         echo "error in basnam $*" 
  73 # Cleanup temporary files and output 
  76     for i 
in $inputFiles ; do 
  86     # Kill result in case of failure as there is just to many stupid make/nmake 
  87     # things out there which doesn't do this. 
  89         rm -f $arcFile $arcFile2 $defFile $dllFile 
  93 # Print usage and exit script with rc=1. 
  95  echo 'Usage: dllar [-o[utput] output_file] [-i[mport] importlib_name]' 
  96  echo '       [-d[escription] "dll descrption"] [-cc "CC"] [-f[lags] "CFLAGS"]' 
  97  echo '       [-ord[inals]] -ex[clude] "symbol(s)"' 
  98  echo '       [-libf[lags] "{INIT|TERM}{GLOBAL|INSTANCE}"] [-nocrt[dll]] [-nolxl[ite]]' 
 100  echo '*> "output_file" should have no extension.' 
 101  echo '   If it has the .o, .a or .dll extension, it is automatically removed.' 
 102  echo '   The import library name is derived from this and is set to "name".a,' 
 103  echo '   unless overridden by -import' 
 104  echo '*> "importlib_name" should have no extension.' 
 105  echo '   If it has the .o, or .a extension, it is automatically removed.' 
 106  echo '   This name is used as the import library name and may be longer and' 
 107  echo '   more descriptive than the DLL name which has to follow the old ' 
 108  echo '   8.3 convention of FAT.' 
 109  echo '*> "cc" is used to use another GCC executable.   (default: gcc.exe)' 
 110  echo '*> "flags" should be any set of valid GCC flags. (default: -s -Zcrtdll)' 
 111  echo '   These flags will be put at the start of GCC command line.' 
 112  echo '*> -ord[inals] tells dllar to export entries by ordinals. Be careful.' 
 113  echo '*> -ex[clude] defines symbols which will not be exported. You can define' 
 114  echo '   multiple symbols, for example -ex "myfunc yourfunc _GLOBAL*".' 
 115  echo '   If the last character of a symbol is "*", all symbols beginning' 
 116  echo '   with the prefix before "*" will be exclude, (see _GLOBAL* above).' 
 117  echo '*> -libf[lags] can be used to add INITGLOBAL/INITINSTANCE and/or' 
 118  echo '   TERMGLOBAL/TERMINSTANCE flags to the dynamically-linked library.' 
 119  echo '*> -nocrt[dll] switch will disable linking the library against emx''s' 
 120  echo '   C runtime DLLs.' 
 121  echo '*> -nolxl[ite] switch will disable running lxlite on the resulting DLL.' 
 122  echo '*> All other switches (for example -L./ or -lmylib) will be passed' 
 123  echo '   unchanged to GCC at the end of command line.' 
 124  echo '*> If you create a DLL from a library and you do not specify -o,' 
 125  echo '   the basename for DLL and import library will be set to library name,' 
 126  echo '   the initial library will be renamed to 'name
'_s.a (_s for static)' 
 127  echo '   i.e. "dllar gcc.a" will create gcc.dll and gcc.a, and the initial' 
 128  echo '   library will be renamed into gcc_s.a.' 
 131  echo '   dllar -o gcc290.dll libgcc.a -d "GNU C runtime library" -ord' 
 132  echo '    -ex "__main __ctordtor*" -libf "INITINSTANCE TERMINSTANCE"' 
 138 # If exit code of the commnad <> 0 CleanUp() is called and we'll exit the script. 
 139 # @Uses    Whatever CleanUp() uses. 
 145     if [ $rcCmd -ne 0 ]; then 
 146         echo "command failed, exit code="$rcCmd 
 171   curDirS
=${curDirS}"/" 
 180         EXPORT_BY_ORDINALS
=1; 
 207         exclude_symbols
=${exclude_symbols}$1" " 
 211         library_flags
=${library_flags}$1" " 
 230         EXTRA_CFLAGS
=${EXTRA_CFLAGS}" "$1 
 233         EXTRA_CFLAGS
="${EXTRA_CFLAGS} `basnam $1 .dll`" 
 234         if [ $omfLinking -eq 1 ]; then 
 235             EXTRA_CFLAGS
="${EXTRA_CFLAGS}.lib" 
 237             EXTRA_CFLAGS
="${EXTRA_CFLAGS}.a" 
 242         if [ $libsToLink -ne 0 ]; then 
 243             EXTRA_CFLAGS
=${EXTRA_CFLAGS}" "$1 
 246                 if [ -f $file ]; then 
 247                     inputFiles
="${inputFiles} $file" 
 251             if [ $found -eq 0 ]; then 
 252                 echo "ERROR: No file(s) found: "$1 
 259 done # iterate cmdline words 
 262 if [ -z "$inputFiles" ]; then 
 263     echo "dllar: no input files" 
 267 # Now extract all .o files from .a files 
 269 for file in $inputFiles ; do 
 280             EXTRA_CFLAGS
="$EXTRA_CFLAGS -Zomf" 
 285         dirname=`basnam $file $suffix`"_%" 
 287         if [ $? 
-ne 0 ]; then 
 288             echo "Failed to create subdirectory ./$dirname" 
 292         # Append '!' to indicate archive 
 293         newInputFiles
="$newInputFiles ${dirname}!" 
 294         doCommand 
"cd $dirname; $AR x ../$file" 
 297         for subfile 
in $dirname/*.o
* ; do 
 298             if [ -f $subfile ]; then 
 300                 if [ -s $subfile ]; then 
 301                     # FIXME: This should be: is file size > 32 byte, _not_ > 0! 
 302                     newInputFiles
="$newInputFiles $subfile" 
 306         if [ $found -eq 0 ]; then 
 307             echo "WARNING: there are no files in archive \'$file\'" 
 311         newInputFiles
="${newInputFiles} $file" 
 315 inputFiles
="$newInputFiles" 
 317 # Output filename(s). 
 319 if [ -z $outFile ]; then 
 321     set outFile 
$inputFiles; outFile
=$2 
 324 # If it is an archive, remove the '!' and the '_%' suffixes 
 327     outFile
=`basnam $outFile _%!` 
 334     outFile
=`basnam $outFile .dll` 
 337     outFile
=`basnam $outFile .DLL` 
 340     outFile
=`basnam $outFile .o` 
 343     outFile
=`basnam $outFile .obj` 
 346     outFile
=`basnam $outFile .a` 
 349     outFile
=`basnam $outFile .lib` 
 356     outimpFile
=`basnam $outimpFile .a` 
 359     outimpFile
=`basnam $outimpFile .lib` 
 364 if [ -z $outimpFile ]; then 
 367 defFile
="${outFile}.def" 
 368 arcFile
="${outimpFile}.a" 
 369 arcFile2
="${outimpFile}.lib" 
 371 #create $dllFile as something matching 8.3 restrictions, 
 375     dllFile
=`echo $dllFile | sed 's/base_\(...\)/b\1/'` 
 378     dllFile
=`echo $dllFile | sed 's/_\(..\)[^_]*_\(..\)[^-]*-/\1\2/'` 
 383 dllFile
="`echo $dllFile | sed 's/\.//' | sed 's/_//' | sed 's/-//'`" 
 386 if [ $do_backup -ne 0 ] ; then 
 387     if [ -f $arcFile ] ; then 
 388         doCommand 
"mv $arcFile ${outFile}_s.a" 
 390     if [ -f $arcFile2 ] ; then 
 391         doCommand 
"mv $arcFile2 ${outFile}_s.lib" 
 395 # Extract public symbols from all the object files. 
 396 tmpdefFile
=${defFile}_
% 
 398 for file in $inputFiles ; do 
 403         doCommand 
"emxexp -u $file >> $tmpdefFile" 
 408 # Create the def file. 
 410 echo "LIBRARY `basnam $dllFile` $library_flags" >> $defFile 
 411 dllFile
="$dllFile.dll" 
 412 if [ ! -z $description ]; then 
 413     echo "DESCRIPTION  \"${description}\"" >> $defFile 
 415 echo "EXPORTS" >> $defFile 
 417 doCommand 
"cat $tmpdefFile | sort.exe | uniq.exe > ${tmpdefFile}%" 
 418 grep -v "^ *;" < ${tmpdefFile}% | grep -v "^ *$" >$tmpdefFile 
 420 # Checks if the export is ok or not. 
 421 for word 
in $exclude_symbols; do 
 422     grep -v $word < $tmpdefFile >${tmpdefFile}% 
 423     mv ${tmpdefFile}% $tmpdefFile 
 427 if [ $EXPORT_BY_ORDINALS -ne 0 ]; then 
 428     sed "=" < $tmpdefFile | \
 
 432       s/^\([0-9]\+\)\([^;]*\)\(;.*\)\?/\2 @\1 NONAME/ 
 435     grep -v "^ *$" < ${tmpdefFile}% > $tmpdefFile 
 439 cat $tmpdefFile >> $defFile 
 442 # Do linking, create implib, and apply lxlite. 
 444 for file in $inputFiles ; do 
 449         gccCmdl
="$gccCmdl $file" 
 453 doCommand 
"$CC $CFLAGS -Zdll -o $dllFile $defFile $gccCmdl $EXTRA_CFLAGS" 
 454 touch "${outFile}.dll" 
 456 doCommand 
"emximp -o $arcFile $defFile" 
 457 if [ $flag_USE_LXLITE -ne 0 ]; then 
 459     if [ $EXPORT_BY_ORDINALS -ne 0 ]; then 
 462     doCommand 
"lxlite -cs -t: -mrn -mln $add_flags $dllFile" 
 464 doCommand 
"emxomf -s -l $arcFile"