|
| 1 | +--[[ |
| 2 | +Will automatically generate all files from the current sources. |
| 3 | +Takes three parameters: |
| 4 | +- The destination directory, as a relative directory. Will create it if it does not exist. |
| 5 | +- The Mercurial revision number to archive to the destination directory. |
| 6 | +- The version number of the tutorials. |
| 7 | +]]-- |
| 8 | + |
| 9 | +require("ex") |
| 10 | +require "ufs" |
| 11 | +require "lfs" |
| 12 | +require "_FindFileInPath" |
| 13 | + |
| 14 | +local baseDir, hgChangelist, versionNum = ... |
| 15 | + |
| 16 | +if(#({...}) ~= 3) then |
| 17 | + print("Not enough commandline parameters. You provided: " .. #({...})); |
| 18 | + print("Paramters:") |
| 19 | + print("\tDestination dir, relative to this path.") |
| 20 | + print("\tMercurial revision to archive.") |
| 21 | + print("\tVersion number of the SDK.") |
| 22 | + return |
| 23 | +end |
| 24 | + |
| 25 | +local buildDirname = "Tutorial " .. versionNum |
| 26 | + |
| 27 | +lfs.mkdir(baseDir); |
| 28 | +local pathDestDir = ufs.path(baseDir) / buildDirname; |
| 29 | +local destDir = tostring(pathDestDir); |
| 30 | +lfs.mkdir(destDir); |
| 31 | + |
| 32 | +local pathCurrent = ufs.current_path(); |
| 33 | +local pathDest = pathCurrent / destDir; |
| 34 | +local pathBase = pathCurrent / baseDir; |
| 35 | + |
| 36 | +------------------------------------------- |
| 37 | +-- Use the other Lua script to copy the HTML and PDFs to the destination. |
| 38 | +local CopyWebsite = assert(loadfile("CopyWebsite.lua")); |
| 39 | +CopyWebsite(destDir .. "\\html\\"); |
| 40 | + |
| 41 | +--Generate the PDF files. |
| 42 | +local pdfOutDir = "..\\..\\" .. destDir .. "\\" |
| 43 | +local cwd = lfs.currentdir(); |
| 44 | +lfs.chdir("Documents\\Build"); |
| 45 | +local BuildPrintBW = assert(loadfile("BuildPrintBWFO.lua")); |
| 46 | +BuildPrintBW(pdfOutDir); |
| 47 | +local BuildKindleFO = assert(loadfile("BuildKindleFO.lua")); |
| 48 | +BuildKindleFO(pdfOutDir); |
| 49 | +local BuildComputerFO = assert(loadfile("BuildComputerFO.lua")); |
| 50 | +BuildComputerFO(pdfOutDir); |
| 51 | +lfs.chdir(cwd); |
| 52 | + |
| 53 | +------------------------------------------ |
| 54 | +-- Use Mercurial to get a version in the destination directory. |
| 55 | +local clone = [[hg archive -r "%s" "%s"]]; |
| 56 | +clone = clone:format(hgChangelist, destDir); |
| 57 | + |
| 58 | +print(clone); |
| 59 | +os.execute(clone); |
| 60 | + |
| 61 | +--------------------------------------------------------------- |
| 62 | +-- Install the dependencies. |
| 63 | +local luaFilename = "lua.exe" |
| 64 | +local pathLua = ufs.path(FindFileInPath(luaFilename)) |
| 65 | +local luaDepScriptName = "get_externals.lua" |
| 66 | + |
| 67 | +ufs.current_path(pathDest); |
| 68 | + |
| 69 | +local depProc = ex.spawn(tostring(pathLua), |
| 70 | + {args={luaDepScriptName}}); |
| 71 | +depProc:wait(depProc); |
| 72 | + |
| 73 | +--------------------------------------------------------------- |
| 74 | +-- Apply Copyright Info |
| 75 | +local luaCopyScriptName = "make_copyright.lua" |
| 76 | + |
| 77 | +if(pathLua:empty()) then |
| 78 | + print("Could not find Lua. Since this is a Lua script, that's kinda confusing..."); |
| 79 | + return; |
| 80 | +end |
| 81 | + |
| 82 | +ufs.current_path(pathCurrent); |
| 83 | + |
| 84 | +local copyProc = ex.spawn(tostring(pathLua), |
| 85 | + {args={luaCopyScriptName, tostring(pathDest)}}); |
| 86 | +copyProc:wait(copyProc); |
| 87 | + |
| 88 | +------------------------------------------- |
| 89 | +-- Generate the ancillary files |
| 90 | + |
| 91 | +--Readme.txt |
| 92 | +local readme = io.open(destDir .. "\\readme.txt", "wt"); |
| 93 | +readme:write(string.format( |
| 94 | +[===[ |
| 95 | +OpenGL Tutorials, version %s |
| 96 | +
|
| 97 | +This is a series of tutorials on using OpenGL to do graphical rendering. |
| 98 | +The code for each tutorial is found in the "Tut *" directories. The code |
| 99 | +alone is not enough information to understand what is going on. The actual |
| 100 | +documentation is available in several forms. |
| 101 | +
|
| 102 | +The HTML form of the documentation can be found by opening the "index.html" |
| 103 | +file. There are 3 PDF forms of the documentation. TutorialsComp.pdf is a PDF |
| 104 | +that uses very thin margins; it is useful for display on computers (or |
| 105 | +tablets). TutorialsPrintBW.pdf is a PDF designed for printing on a black-and-white |
| 106 | +printer. TutorialsKindle.pdf is a PDF that is sized specifically for the screen |
| 107 | +of the Kindle 2. |
| 108 | +
|
| 109 | +The License.txt file contains the licensing information for the materials distributed in these tutorials. |
| 110 | +]===], versionNum)) |
| 111 | +readme:close() |
| 112 | + |
| 113 | +--Version.txt |
| 114 | +local version = io.open(destDir .. "\\version.txt", "wt"); |
| 115 | +version:write(string.format( |
| 116 | +[===[ |
| 117 | +OpenGL Tutorials. |
| 118 | +
|
| 119 | +Version %s |
| 120 | +]===] |
| 121 | +, versionNum)) |
| 122 | +version:close(); |
| 123 | + |
| 124 | +--Index.html |
| 125 | +local index_html = io.open(destDir .. "\\index.html", "wt"); |
| 126 | +index_html:write( |
| 127 | +[===[ |
| 128 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 129 | +<html> |
| 130 | +<head> |
| 131 | + <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| 132 | + <meta HTTP-EQUIV="REFRESH" content="0; url=html/index.html"/> |
| 133 | +</head> |
| 134 | +<body> |
| 135 | +</body> |
| 136 | +]===] |
| 137 | +) |
| 138 | +index_html:close(); |
| 139 | + |
| 140 | +------------------------------------------------------------ |
| 141 | +-- Delete select files from the destination location. |
| 142 | +local toDelete = |
| 143 | +{ |
| 144 | + --files |
| 145 | + --Distro building |
| 146 | + "BuildDistro.lua", "CopyWebsite.lua", |
| 147 | + "_FindFileInPath.lua", "file_copyright_info.lua", "make_copyright.lua", |
| 148 | + --Mercurial |
| 149 | + ".hgignore", ".hgtags", ".hg_archival.txt", |
| 150 | + --directories |
| 151 | + "glimg\\Test", "glload\\Test", "glload\\codegen", |
| 152 | + "Documents", "Meshes", |
| 153 | +} |
| 154 | + |
| 155 | + |
| 156 | +for i, filename in ipairs(toDelete) do |
| 157 | + local pathFile = pathDest / filename; |
| 158 | + print("deleting:", pathFile); |
| 159 | + ufs.remove_all(pathFile); |
| 160 | +end |
| 161 | + |
| 162 | +------------------------------------------------------------ |
| 163 | +-- Create Zip archive of the distro. |
| 164 | +local szFilename = "7z.exe" |
| 165 | +local archiveName = buildDirname .. ".7z" |
| 166 | +local pathSZ = ufs.path(FindFileInPath(szFilename)) |
| 167 | + |
| 168 | +if(pathSZ:empty()) then |
| 169 | + print("Could not find 7zip."); |
| 170 | + return; |
| 171 | +end |
| 172 | + |
| 173 | +ufs.current_path(pathBase); |
| 174 | + |
| 175 | +local zipProc = ex.spawn(tostring(pathSZ), |
| 176 | + {args={"a", "-r", archiveName, buildDirname}}); |
| 177 | +zipProc:wait(zipProc); |
| 178 | + |
| 179 | +------------------------------------------------------------ |
| 180 | +-- Destroy the directory. |
| 181 | +ufs.remove_all(pathDest); |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | + |
| 190 | + |
0 commit comments