richk@6878: Option Explicit
richk@6878:
richk@6878: Dim FSO
richk@6878: Set FSO = CreateObject("Scripting.FileSystemObject")
richk@6878:
richk@6878: ' openttd_vs90.sln is for MSVC 2008
richk@6878: ' openttd_vs90.vcproj is for MSVC 2008
richk@6878: ' langs_vs90.vcproj is for MSVC 2008
richk@6878: ' strgen_vs90.vcproj is for MSVC 2008
richk@6878:
richk@6878: ' openttd_vs80.sln is for MSVC 2005
richk@6878: ' openttd_vs80.vcproj is for MSVC 2005
richk@6878: ' langs_vs80.vcproj is for MSVC 2005
richk@6878: ' strgen_vs80.vcproj is for MSVC 2005
richk@6878:
richk@6878: Sub safety_check(filename)
richk@6878: Dim file, line, regexp, list
richk@6878:
richk@6878: ' Define regexp
richk@6878: Set regexp = New RegExp
richk@6878: regexp.Pattern = "#|ottdres.rc|win32.cpp|win32_v.cpp"
richk@6878: regexp.Global = True
richk@6878:
richk@6878: ' We use a dictionary to check duplicates
richk@6878: Set list = CreateObject("Scripting.Dictionary")
richk@6878:
richk@6878: Set file = FSO.OpenTextFile(filename, 1, 0, 0)
richk@6878: While Not file.AtEndOfStream
richk@6878: line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
richk@6878: If Len(line) > 0 And Not regexp.Test(line) Then
richk@6878: line = FSO.GetFileName(line)
richk@6878: if list.Exists(line) Then
richk@6878: WScript.Echo " !! ERROR !!" _
richk@6878: & vbCrLf & "" _
richk@6878: & vbCrLf & "The filename '" & line & "' is already used in this project." _
richk@6878: & vbCrLf & "Because MSVC uses one single directory for all object files, it" _
richk@6878: & vbCrLf & "cannot handle filenames with the same name inside the same project." _
richk@6878: & vbCrLf & "Please rename either one of the file and try generating again." _
richk@6878: & vbCrLf & "" _
richk@6878: & vbCrLf & " !! ERROR !!"
richk@6878: WScript.Quit(1)
richk@6878: End If
richk@6878: list.Add line, line
richk@6878: End If
richk@6878: Wend
richk@6878: file.Close
richk@6878: End Sub
richk@6878:
richk@6878: Function load_main_data(filename)
richk@6878: Dim res, file, line, deep, skip, first_time
richk@6878: res = ""
richk@6878: ' Read the source.list and process it
richk@6878: Set file = FSO.OpenTextFile(filename, 1, 0, 0)
richk@6878: While Not file.AtEndOfStream
richk@6878: line = Replace(file.ReadLine, Chr(9), "") ' Remove tabs
richk@6878: If Len(line) > 0 Then
richk@6878: Select Case Split(line, " ")(0)
richk@6878: Case "#end"
richk@6878: If deep = skip Then skip = skip - 1
richk@6878: deep = deep - 1
richk@6878: Case "#else"
richk@6878: If deep = skip Then
richk@6878: skip = skip - 1
richk@6878: ElseIf deep - 1 = skip Then
richk@6878: skip = skip + 1
richk@6878: End If
richk@6878: Case "#if"
richk@6878: line = Replace(line, "#if ", "")
richk@6878: If deep = skip And ( _
richk@6878: line = "SDL" Or _
richk@6878: line = "PNG" Or _
richk@6878: line = "WIN32" Or _
richk@6878: line = "MSVC" Or _
richk@6878: line = "DIRECTMUSIC" Or _
richk@6878: line = "NO_THREADS" _
richk@6878: ) Then skip = skip + 1
richk@6878: deep = deep + 1
richk@6878: Case "#"
richk@6878: if deep = skip Then
richk@6878: line = Replace(line, "# ", "")
richk@6878: if first_time <> 0 Then
richk@6878: res = res & " " & vbCrLf
richk@6878: Else
richk@6878: first_time = 1
richk@6878: End If
richk@6878: res = res & _
richk@6878: " " & vbCrLf
richk@6878: End If
richk@6878: Case Else
richk@6878: If deep = skip Then
richk@6878: line = Replace(line, "/" ,"\")
richk@6878: res = res & _
richk@6878: " " & vbCrLf & _
richk@6878: " " & vbCrLf
richk@6878: End If
richk@6878: End Select
richk@6878: End If
richk@6878: Wend
richk@6878: res = res & " "
richk@6878: file.Close()
richk@6878: load_main_data = res
richk@6878: End Function
richk@6878:
richk@6878: Function load_lang_data(dir)
richk@6878: Dim res, folder, file
richk@6878: res = ""
richk@6878: Set folder = FSO.GetFolder(dir)
richk@6878: For Each file In folder.Files
richk@6878: file = FSO.GetFileName(file)
richk@6878: If FSO.GetExtensionName(file) = "txt" Then
richk@6878: file = Left(file, Len(file) - 4)
richk@6878: res = res _
richk@6878: & vbCrLf & " " _
richk@6878: & vbCrLf & " " _
richk@6878: & vbCrLf & " " _
richk@6878: & vbCrLf & " " _
richk@6878: & vbCrLf & " "
richk@6878: End If
richk@6878: Next
richk@6878: load_lang_data = res
richk@6878: End Function
richk@6878:
richk@6878: Sub generate(data, dest)
richk@6878: Dim srcfile, destfile, line
richk@6878: WScript.Echo "Generating " & FSO.GetFileName(dest) & "..."
richk@6878: Set srcfile = FSO.OpenTextFile(dest & ".in", 1, 0, 0)
richk@6878: Set destfile = FSO.CreateTextFile(dest, -1, 0)
richk@6878:
richk@6878: ' Everything above the !!FILES!! marker
richk@6878: line = srcfile.ReadLine()
richk@6878: While line <> "!!FILES!!"
richk@6878: If len(line) > 0 Then destfile.WriteLine(line)
richk@6878: line = srcfile.ReadLine()
richk@6878: Wend
richk@6878:
richk@6878: ' Our generated content
richk@6878: destfile.WriteLine(data)
richk@6878:
richk@6878: ' Everything below the !!FILES!! marker
richk@6878: While Not srcfile.AtEndOfStream
richk@6878: line = srcfile.ReadLine()
richk@6878: If len(line) > 0 Then destfile.WriteLine(line)
richk@6878: Wend
richk@6878: srcfile.Close()
richk@6878: destfile.Close()
richk@6878: End Sub
richk@6878:
richk@6878: Dim ROOT_DIR
richk@6878: ROOT_DIR = FSO.GetFolder("..").Path
richk@6878: If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
richk@6878: ROOT_DIR = FSO.GetFolder(".").Path
richk@6878: End If
richk@6878: If Not FSO.FileExists(ROOT_DIR & "/source.list") Then
richk@6878: WScript.Echo "Can't find source.list, needed in order to make this run." _
richk@6878: & vbCrLf & "Please go to either the project dir, or the root dir of a clean SVN checkout."
richk@6878: WScript.Quit(1)
richk@6878: End If
richk@6878:
richk@6878: safety_check ROOT_DIR & "/source.list"
richk@6878:
richk@6878: Dim openttd
richk@6878: openttd = load_main_data(ROOT_DIR &"/source.list")
richk@6878: generate openttd, ROOT_DIR & "/projects/openttd_vs80.vcproj"
richk@6878: generate openttd, ROOT_DIR & "/projects/openttd_vs90.vcproj"
richk@6878:
richk@6878: Dim lang
richk@6878: lang = load_lang_data(ROOT_DIR & "/src/lang")
richk@6878: generate lang, ROOT_DIR & "/projects/langs_vs80.vcproj"
richk@6878: generate lang, ROOT_DIR & "/projects/langs_vs90.vcproj"