Advertisement
Guest User

BlitzMax makedll.bmx

a guest
Jan 5th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Strict
  2.  
  3. Local bmaxpath:String = BlitzMaxPath()+"\"
  4. Local source:String
  5.  
  6. If AppArgs.length > 1
  7.     source = AppArgs[1]
  8. Else
  9.     End
  10. End If
  11.  
  12. If FileType(bmaxpath+"bin\bmk.exe") <> 1
  13.     Print "Invalid bmax root path"
  14.     End
  15. EndIf
  16.    
  17. source = RealPath(source)
  18. If FileType(source) <> 1
  19.     Print "Can't find bmax source file"
  20.     End
  21. EndIf
  22.  
  23. Local sourcepath:String = ExtractDir(source)
  24. If Not(Right(sourcepath,1)="/") Then sourcepath :+ "\"
  25. Local sourcename:String = StripExt(StripDir(source))
  26.  
  27. If FileType(sourcepath+sourcename+".exe") = 1
  28.     DeleteFile(sourcepath+sourcename+".exe")
  29. End If
  30. If FileType(sourcepath+sourcename+".dll") = 1
  31.     DeleteFile(sourcepath+sourcename+".dll")
  32. End If
  33.  
  34. system_(bmaxpath+"bin\bmk.exe makeapp -r -d -t console ~q"+source+"~q")
  35.  
  36. Print "Parsing sourcefile..."
  37. Local sfile:TStream = ReadFile(source)
  38. Local dfile:TStream = WriteFile(sourcepath+"makedll.def")
  39. WriteLine dfile,"EXPORTS"
  40.  
  41. Local tmpline:String = sfile.ReadLine()
  42. Local indx:Int
  43. Print "Exported functions:"
  44. While Not sfile.Eof()
  45.     If tmpline.Find("Function") > -1 And tmpline.Find("'EXPORT") > -1 Then
  46.         Local expfunc$
  47.         indx = tmpline.Find("Function")+10
  48.        
  49.         While Mid(tmpline,indx,1)<>"(" And Mid(tmpline,indx,1)<>":"
  50.             expfunc :+ Mid(tmpline,indx,1)
  51.             indx :+ 1
  52.         Wend   
  53.         Print " "+expfunc
  54.         WriteLine dfile, Chr(9)+expfunc + " = bb_" + expfunc
  55.     ElseIf tmpline.Find("'FUNC") > -1 Then
  56.         Local expfunc$
  57.         indx = tmpline.Find("'FUNC")+7
  58.         expfunc = Mid(tmpline, indx)
  59.        
  60.         Print " "+expfunc
  61.         WriteLine dfile, Chr(9)+expfunc + " = bb_" + expfunc
  62.     EndIf
  63.     tmpline = sfile.ReadLine()
  64. Wend
  65. CloseStream(dfile)
  66. CloseStream(sfile)
  67.  
  68. system_(bmaxpath+"bin\ld.exe --dll -o ~q"+sourcepath+sourcename+".dll~q -L ~q"+bmaxpath+"lib~q -e _bb_DllMain ~q"+sourcepath+"makedll.def~q ~q"+bmaxpath+"tmp\ld.tmp~q")
  69. If FileType(sourcepath+sourcename+".dll") <> 1
  70.  Print "Creation of "+sourcename+".dll failed"
  71. Else
  72.  Print "Creation of "+sourcename+".dll successful"
  73. End If
  74.  
  75. If FileType(sourcepath+sourcename+".exe") = 1
  76.     DeleteFile(sourcepath+sourcename+".exe")
  77. End If
  78. If FileType(sourcepath+"makedll.def") = 1
  79.     DeleteFile(sourcepath+"makedll.def")
  80. EndIf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement