DLL creation, second attempt

BlitzMax Forums/BlitzMax Programming/DLL creation, second attempt

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This version works with spaces in filepaths/names:
Strict

' ***********************************
' * MakeDLL                         *
' * By Sven-Bertil Blom AKA Sweenie *
' * 2005-08-12                      *
' ***********************************
'
' Commandlinearguments-code borrowed from skn3[ac]
'
Local file:TStream
Local bmaxpath:String
Local source:String

If appargs.length > 2
	file = WriteFile("bmaxpath.txt")
	If Not(Right(AppArgs[2],1)="") Then AppArgs[2] :+ ""
	file.WriteLine(AppArgs[2])
	file.close()
	bmaxpath = AppArgs[2]
	source = AppArgs[1]
ElseIf appargs.length > 1
	If FileType("bmaxpath.txt") <> 1
		Print "You didn't supply a blitzmax path. MakeDll will save the path when you supply it, and reuse it next time if left out of the commandline"
		End
	End If
	file = ReadFile("bmaxpath.txt")
	bmaxpath = file.ReadLine()
	file.Close()
	source = AppArgs[1]
Else
	Print "*** MakeDLL ***"
	Print "How To Use:"
	Print ""
	Print "  MakeDll.exe sourcepath bmaxpath"
	Print ""
	Print "[bmaxpath]"
	Print "This param is optional, you must use it the first time you call makedll, or anytime you want to modify the bmaxpath. The path will be saved and reused when no bmaxpath is specified"
	End
End If

'check correct bmax path
If FileType(bmaxpath+"bin\bmk.exe") <> 1
	Print "Invalid bmax root path"
	End
End If
	
'check correct source path
source = RealPath(source)
If FileType(source) <> 1
	Print "Can't find bmax source file"
	End
End If

Local sourcepath:String = ExtractDir(source)
If Not(Right(sourcepath,1)="/") Then sourcepath :+ ""
Local sourcename:String = StripExt(StripDir(source))

If FileType(sourcepath+sourcename+".exe") = 1
	DeleteFile(sourcepath+sourcename+".exe")
End If
If FileType(sourcepath+sourcename+".dll") = 1
	DeleteFile(sourcepath+sourcename+".dll")
End If

system_(bmaxpath+"bin\bmk.exe makeapp -r -t console ~q"+source+"~q")

'Parse sourcefile for exported functions...
Print "Parsing sourcefile..."
Local sfile:TStream = ReadFile(source)
Local dfile:TStream = WriteFile(sourcepath+"makedll.def")
WriteLine(dfile,"EXPORTS")
Local tmpline:String
Local indx:Int
Local expfunc:String
tmpline = sfile.ReadLine()
Print "Exported functions:"
While Not sfile.Eof()
	If tmpline.Find("'EXPORT")>-1 And tmpline.Find("Function")>-1 Then
		expfunc=""
		indx = tmpline.Find("Function")+10
		'Print tmpline
		While Mid(tmpline,indx,1)<>"(" And Mid(tmpline,indx,1)<>":"
		 expfunc :+ Mid(tmpline,indx,1)
		 indx :+ 1
		Wend	
		Print " "+expfunc
		WriteLine(dfile,Chr(9)+expfunc + " = bb_" + expfunc)
	EndIf
	tmpline = sfile.ReadLine()
Wend
dfile.Close()
sfile.Close()
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")
If FileType(sourcepath+sourcename+".dll") <> 1
 Print "Creation of "+sourcename+".dll failed"
Else
 Print "Creation of "+sourcename+".dll successful"
End If

If FileType(sourcepath+sourcename+".exe") = 1
	DeleteFile(sourcepath+sourcename+".exe")
End If
If FileType(sourcepath+"makedll.def") = 1
	DeleteFile(sourcepath+"makedll.def")
End If
Oh, and top job it seems to work perfectly!