home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / MAKEDEF.ZIP / MAKEDE.KSH < prev   
Text File  |  1994-02-02  |  10KB  |  298 lines

  1. ##
  2. ## $Id: makedef.ksh 1.6 94/01/22 13:41:19 ETIENNE Exp Locker: ETIENNE $
  3. ############################################################################
  4. ## (c)  A.T.L.P.                         by  Etienne Rossignon
  5. ##      15 rue du Buisson aux Fraises
  6. ##      F-91741 Massy Cedex 
  7. ##      France
  8. ##      Tel : 33 - 1 - 69 30 75 75
  9. ##      Fax : 33 - 1 - 69 30 22 42 
  10. ##      CompuServe 100277,2305
  11. ##
  12. ## (please:do not remove this note)
  13. ############################################################################
  14. ##
  15. ##   DEFINING AN DLL EXPORT FILE FOR C++ 
  16. ##   see usage functions to know how to use this script
  17. ##
  18. ############################################################################
  19. ## $Log:    makedef.ksh $
  20. # Revision 1.6  94/01/22  13:41:19  ETIENNE
  21. # remove bug that make the script stop when definition do not exit.
  22. # Revision 1.5  94/01/16  18:14:28  ETIENNE
  23. # add on-line options (-d -n and -f )
  24. # Revision 1.4  94/01/16  15:24:47  ETIENNE
  25. # now handle relative pathname (thank to MKS support inquiry@mks.com)
  26. # Revision 1.3  94/01/08  14:14:39  ETIENNE
  27. # now get obj file name from a list.
  28. # add usage functions
  29. # add functions to handle MKS revision 
  30. # Revision 1.2  93/12/22  14:12:17  ETIENNE
  31. # improve numbering method
  32. # Revision 1.1  93/06/12  14:10:25  ETIENNE
  33. # Initial revision
  34.  
  35. ##
  36. ## Helper Functions
  37. ##       
  38. ##
  39. ############################################################################
  40. ##
  41. ## Awk script to handle pathname
  42. ##  usage: to  replace \ with /  :  awk -v dest="sh"  "$awk_path" 
  43. ##         to  replace / with \\ :  awk -v dest="dos" "$awk_path"
  44. ##
  45. ############################################################################
  46. ##
  47. awk_path='BEGIN { slash = "/" ; bslash = "\\\\" } 
  48. function bslash_path(path)
  49.    gsub(slash, "\\\\\\", path) 
  50.    return path 
  51. }
  52. function slash_path(path)
  53. {
  54.     gsub( bslash, "/", path)
  55.     return path 
  56. }              
  57.   if (dest=="sh") 
  58.      print slash_path($1);
  59.   else 
  60.      print bslash_path($1)
  61.   endif
  62. }
  63. '
  64. ##
  65. ######################################################################
  66. ## bslash_path : replace slash in $1 with doubled backslask
  67. ##               and echo the result to stdout
  68. ######################################################################
  69. ##
  70. function bslash_path
  71. {
  72.   echo    $1 | awk -v dest="dos" "$awk_path"
  73. }
  74. ##
  75. ######################################################################
  76. ## Usage
  77. ######################################################################
  78. ##
  79. function usage {
  80.  echo   "USAGE :"
  81.  echo   '   makedef <opts> <libname> [ [ -f <listfile> | <objectfile> ]...]'
  82.  echo  
  83.  echo   '<opts>          :'
  84.  echo   '        -d      : output some debug info '
  85.  echo   '        -n      : force to use directly the nm on object file  '
  86.  echo   '                  do not perform the MKS version test'
  87.  echo   '<libname>       : name of dll to create : this is the root name'
  88.  echo   '                  do not specify extension'
  89.  echo   '-f <listfile>   : file that contains all object files to analyse'
  90.  echo   '                  (ie : created with the command ls *.obj > listobj)'
  91.  echo   '                  *.obj can be given with a relative path'
  92.  echo   '                  (ie : ..\\foo.obj or ../bar/foo.obj are CORRECT file name)'
  93.  echo   '                  this sequence can appears any number of time'
  94.  echo   ' <objectfile>   : specify an object to analyse'
  95. }
  96. ##
  97. ############################################################################
  98. ## _GetMangledNameOldMKS 
  99. ##  Version for Old MKS : 
  100. ##  o use this function if your nm version do not recognize new .OBJ FILE
  101. ##    but can analyse correctly library file.
  102. ##  o this function create a temp. lib to old the specify .obj files ($1)
  103. ##    and extract mangled name from the .lib file. 
  104. ############################################################################
  105. ##
  106. function _GetMangledNameOldMKS  
  107. {
  108. #
  109. #  Create a dummy librairy
  110. #
  111.     dosname=`bslash_path $1`   
  112.     echo ${dosname}.lib         >  tmp.tmp
  113.     echo y                      >> tmp.tmp
  114.     echo +${dosname}.obj        >> tmp.tmp
  115.     echo                        >> tmp.tmp   
  116.     
  117.     LIB /nologo < tmp.tmp > NULL
  118. #
  119. # Extract external functions 
  120. #
  121.     nm $1.lib | grep -v 0:0000 | grep \? > $2
  122.  
  123. #
  124. # destruction de lib & tmp
  125. #
  126.    rm $1.lib tmp.tmp
  127. }
  128. ##
  129. ############################################################################
  130. ## _GetMangledNameNewMKS
  131. ##  Version for New MKS (version 4 and sup)
  132. ##  o used if the MKS toolkit recognize the .OBJ format
  133. ############################################################################
  134. ##
  135. function _GetMangledNameNewMKS
  136. {  
  137.    nm $1.obj | grep -v 0:0000 | grep \? > $2
  138. }
  139. ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  140. ## START 
  141. ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  142. ##
  143. ##  command options  analyse
  144. ##
  145. filelist=tmpflist.tmp
  146. debug=no
  147. forceNewNM=no
  148. if  test $# -lt 2
  149. then
  150.     usage
  151.     exit -2
  152. fi
  153.  
  154. nextcommand=none
  155. nb=1
  156. if test -f $filelist; then;rm $filelist;fi
  157. for i in $*
  158. do
  159.   if test "$debug" = "yes" ; then; echo CURRENT ARGUMENT  = $i ; fi
  160.   case $nextcommand in
  161.    "none"        ) {  
  162.                       case $i in  
  163.                           "-n" )  forceNewNM=yes         ;;
  164.                           "-f" )  nextcommand=getlistfile ;;
  165.                           "-d" )  debug=yes ; nextcommand=none  ;;
  166.                           *    ) { 
  167.                                       if test $nb -eq 1 ;then
  168.                                            deffileroot=$i
  169.                                       else
  170.                                            if ! ( test -f $i )
  171.                                            then
  172.                                               echo file \<$i\> not found
  173.                                               exit -2
  174.                                            else
  175.                                               echo $i >> $filelist
  176.                                            fi 
  177.                                            let nb=$nb+1 
  178.                                        fi
  179.                                  } ;;
  180.                       esac
  181.                    } ;;
  182.    "getlistfile" ) {
  183.                       file=$i 
  184.                       if ! ( test -f $file )  
  185.                       then
  186.                          echo list of object \<$file\> not found 
  187.                          exit -2
  188.                       fi
  189.                       for f in $(cat $i | awk -v dest="sh" "$awk_path" ) 
  190.                       do 
  191. if test "$debug" = "yes" ; then; echo testing $f ; fi
  192.                            if ! ( test -f $f )
  193.                            then
  194.                                echo file \<$f\> in file \<$i\> not found
  195.                                exit -2
  196.                            fi
  197.                       done
  198.                       echo $(cat $i | awk -v dest="sh" "$awk_path" )  >> $filelist
  199.                       nextcommand=none
  200.                     } ;;
  201.   esac
  202. }
  203. done
  204.  
  205.  
  206. ############################################################################
  207. # Choose Mangled Function
  208. ############################################################################
  209. MKSVER=`cat $ROOTDIR/product.cfg | grep -i Toolkit | awk '{ print $1 }'`
  210. if  ( test $[MKSVER+0] -le 3 )  && ( test $forceNewNM = "no" )
  211. then
  212.    echo ------------------------------------
  213.    echo $MKSVER : Old Version
  214.    echo ------------------------------------
  215.    GetMangledNameFunc=_GetMangledNameOldMKS
  216. else
  217.    echo ------------------------------------
  218.    echo $MKSVER : New Version
  219.    echo ------------------------------------
  220.    GetMangledNameFunc=_GetMangledNameNewMKS
  221. fi
  222. ###########################################################################
  223. ## Test Arguments
  224. ###########################################################################
  225. deffile=${deffileroot:?Must Specify Definition File}.def
  226. rm -i $deffile
  227. mangledfile=mangled.tmp
  228. ############################################################################
  229. ## write .DEF header
  230. ############################################################################
  231. #echo LIBRARY   $1                              >  $deffile
  232. echo LIBRARY                                    >  $deffile
  233. echo EXETYPE   WINDOWS                          >> $deffile
  234. echo CODE      PRELOAD MOVEABLE DISCARDABLE     >> $deffile
  235. echo DATA      PRELOAD MOVEABLE SINGLE          >> $deffile
  236. echo HEAPSIZE  1024                             >> $deffile
  237. echo EXPORTS                                    >> $deffile
  238. echo      WEP PRIVATE                           >> $deffile
  239. ###########################################################################
  240. ## debut de la numerotation
  241. nb=10                              
  242. #echo $GetMangledNameFunc
  243. for i in $(cat $filelist)
  244. do {
  245.  
  246. #    echo DOSPATH1=$i | awk -v dest="dos" "$awk_path"
  247. #    echo DOSPATH2= `bslash_path $i`
  248.     
  249.     rootname=${i%.obj}
  250.     print -n CURRENT FILE  : $i 
  251.     #
  252.     # extract mangled name
  253.     #
  254.     $GetMangledNameFunc $rootname $mangledfile
  255.     #
  256.     # Append to .DEF FILE
  257.     #
  258.     echo ";------------------------------------------------------------" $rootname >> $deffile
  259.     aww="{ print \" \" \$3 \"   @\"num \" NONAME\" ; num=num+1 }"
  260.     cat $mangledfile | awk -v num=$nb "$aww" >> $deffile
  261.     #
  262.     #  Calculate Increment
  263.     #
  264.     increment=`cat $mangledfile | wc | awk '{ print $1 }'`
  265.     print   "\t... : $increment exported func."
  266.     nb=$[nb + increment] 
  267. }
  268. done                       
  269. rm $mangledfile
  270. if test -f $filelist; then;rm $filelist;fi
  271. ###############################################################
  272. ## thank's to MKS support that gave me the method
  273. ## to convert DOS full path name to ksh name as a awk script 
  274. ###############################################################
  275. ## BEGIN { slash = "/" ; bslash = "\\\\" }
  276. ## function bslash_path(path)
  277. ## {
  278. ##    gsub(slash, "\\", path)
  279. ##    return path
  280. ##}
  281. ##
  282. ##function slash_path(path)
  283. ##{
  284. ##    gsub( bslash, "/", path)
  285. ##    return path
  286. ##}
  287. ##{ print slash_path($1); print bslash_path($1) }
  288.  
  289.