summaryrefslogtreecommitdiffstats
path: root/boiler-monster/original-pic-4.2.5/build.vbs
blob: 989fbf1a2142b829775fc9a691013b58800ca009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'Build.vbs
'Generate MPLAB include script
'-----------------------------
'
Option Explicit

Dim sh, fso, src, fd
Dim ts, name, timestr
Dim proj, regpath, build

Const incfile = "build.asm"

Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

'Make sure to be working in the project directory
sh.CurrentDirectory = fso.GetParentFolderName(Wscript.ScriptFullName)

'Determine the last modification time of the sources
ts = DateValue("1/1/1970")
For Each name In fso.GetFolder(".").Files
  If LCase(fso.GetExtensionName(name)) = "asm" Then
    If fso.GetFileName(name) <> incfile Then
      Set src = fso.GetFile(name)
      If DateDiff("S", ts, src.DateLastModified) > 0 Then
        ts = src.DateLastModified
      End If
    End If
  End If
Next

'Check if the include file needs to be regenerated
If fso.FileExists(incfile) Then
  Set src = fso.GetFile(incfile)
  If DateDiff("S", ts, src.DateLastModified) >= 0 Then
    Wscript.StdOut.WriteLine "Source was not changed"
    Wscript.Quit
  End If
End If

'Format the last modification time
timestr = right("0" & hour(ts), 2) & ":" & _
	right("0" & minute(ts), 2) & " " & _
	right("0" & day(ts), 2) & "-" & _
	right("0" & month(ts), 2) & "-" & year(ts)

'Determine the project name
If WScript.Arguments.Count > 0 Then
  'The project name was specified on the command line
  proj = WScript.Arguments.item(0)
Else
  'Derive the project name from the current directory
  proj = fso.GetFileName(fso.GetAbsolutePathName("."))
End If

'Get the build revision from the registry
regpath = "HKLM\SOFTWARE\Microchip\MPLAB IDE\Projects\" & proj & "\Revision"
On Error Resume Next
build = sh.RegRead(regpath)
If Hex(Err.number) = "80070002" Then
  build = 1
Else
  build = build + 1
End If
On Error GoTo 0
'Update the registry
sh.RegWrite regpath, build, "REG_DWORD"

'Create the build.asm file
Set fd = fso.CreateTextFile(incfile)
fd.WriteLine "#define		build		""" & build & """"
fd.WriteLine "#define		tstamp		""" & timestr & """"
fd.Close

'Report the build revision to standard output as well
Wscript.StdOut.WriteLine "Build revision: " & build
Wscript.StdOut.WriteLine "Build time & date: " & timestr