diff options
Diffstat (limited to 'tools/niminst')
-rw-r--r-- | tools/niminst/buildbat.tmpl | 6 | ||||
-rw-r--r-- | tools/niminst/buildsh.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/debcreation.nim | 60 | ||||
-rw-r--r-- | tools/niminst/deinstall.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/inno.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/install.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/makefile.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/niminst.nim | 70 | ||||
-rw-r--r-- | tools/niminst/nsis.tmpl | 20 |
9 files changed, 104 insertions, 62 deletions
diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl index 3a11715bf..2a8da144d 100644 --- a/tools/niminst/buildbat.tmpl +++ b/tools/niminst/buildbat.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex: int): string = # result = "@echo off\nREM Generated by niminst\n" SET CC=gcc @@ -18,13 +18,13 @@ REM call the compiler: # for ff in items(c.cfiles[winIndex][cpuIndex]): # let f = ff.toWin ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} -%CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} +CALL %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} # linkCmd.add(" " & changeFileExt(f, "o")) IF ERRORLEVEL 1 (GOTO:END) # end for ECHO %LINKER% -o ?{"%BIN_DIR%"\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS% -%LINKER% -o ?{"%BIN_DIR%"\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS% +CALL %LINKER% -o ?{"%BIN_DIR%"\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS% # end block diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl index 52da351be..463a1ad52 100644 --- a/tools/niminst/buildsh.tmpl +++ b/tools/niminst/buildsh.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateBuildShellScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated from niminst\n" & # "# Template is in tools/niminst/buildsh.tmpl\n" & diff --git a/tools/niminst/debcreation.nim b/tools/niminst/debcreation.nim index bbd997981..36b2a29ec 100644 --- a/tools/niminst/debcreation.nim +++ b/tools/niminst/debcreation.nim @@ -38,33 +38,33 @@ proc createControl(pkgName, maintainer, shortDesc, desc: string, ## Multiple dependencies should be separated by commas. ## pkgDepends: Same as buildDepends except that this specifies the ## dependencies that the compiled application depends on. - - + + result = "" - + addN("Source: " & pkgName) addN("Maintainer: " & maintainer) addN("Section: misc") addN("Priority: optional") addN("Standards-Version: 3.9.2") - addN("Build-Depends: debhelper (>= 8)" & + addN("Build-Depends: debhelper (>= 8)" & (if buildDepends != "": ", " & buildDepends else: "")) addN("\n") addN("Package: " & pkgName) addN("Architecture: any") addN("Depends: ${shlibs:Depends}, ${misc:Depends}" & (if pkgDepends != "": ", " & pkgDepends else: "")) - + var formattedDesc = "" for line in splitLines(desc): if line == "": formattedDesc.add(" .\n") else: formattedDesc.add(" " & line & "\n") - + addN("Description: " & shortDesc & "\n" & formattedDesc) -proc createCopyright(pkgName, mtnName, mtnEmail, version: string, +proc createCopyright(pkgName, mtnName, mtnEmail, version: string, licenses: seq[tuple[files, license: string]]): string = ## pkgName: Package name ## mtnName: Maintainer name @@ -73,7 +73,7 @@ proc createCopyright(pkgName, mtnName, mtnEmail, version: string, ## licenses: files: This specifies the files that the `license` covers, ## for example, it might be ``lib/*`` to cover the whole ``lib`` dir ## license: This specifies the license, for example gpl2, or lgpl. - + result = "" addN("Maintainer name: " & mtnName) addN("Email-Address: " & mtnEmail) @@ -86,7 +86,7 @@ proc createCopyright(pkgName, mtnName, mtnEmail, version: string, proc formatDateTime(t: TimeInfo, timezone: string): string = var day = ($t.weekday)[0..2] & ", " - + return "$1$2 $3 $4 $5:$6:$7 $8" % [day, intToStr(t.monthday, 2), ($t.month)[0..2], $t.year, intToStr(t.hour, 2), intToStr(t.minute, 2), intToStr(t.second, 2), timezone] @@ -147,41 +147,41 @@ proc prepDeb*(packName, version, mtnName, mtnEmail, shortDesc, desc: string, buildDepends, pkgDepends = "") = ## binaries/config/docs/lib: files relative to nim's root, that need to ## be installed. - + let pkgName = packName.toLower() - + var workingDir = getTempDir() / "niminst" / "deb" var upstreamSource = (pkgName & "-" & version) - + echo("Making sure build.sh and install.sh are +x") - assertSuccess execCmd("chmod +x \"" & + assertSuccess execCmd("chmod +x \"" & (workingDir / upstreamSource / "build.sh") & "\"") - assertSuccess execCmd("chmod +x \"" & + assertSuccess execCmd("chmod +x \"" & (workingDir / upstreamSource / "install.sh") & "\"") - - var tarCmd = "tar pczf \"" & + + var tarCmd = "tar pczf \"" & (pkgName & "_" & version & ".orig.tar.gz") & - "\" \"" & upstreamSource & "\"" + "\" \"" & upstreamSource & "\"" echo(tarCmd) assertSuccess execCmd("cd \"" & workingDir & "\" && " & tarCmd) - + echo("Creating necessary files in debian/") createDir(workingDir / upstreamSource / "debian") - + template writeDebian(f, s: string): expr = writeFile(workingDir / upstreamSource / "debian" / f, s) - + var controlFile = createControl(pkgName, makeMtn(mtnName, mtnEmail), shortDesc, desc, buildDepends, pkgDepends) echo("debian/control") writeDebian("control", controlFile) - + var copyrightFile = createCopyright(pkgName, mtnName, mtnEmail, version, licenses) echo("debian/copyright") writeDebian("copyright", copyrightFile) - var changelogFile = createChangelog(pkgName, version, + var changelogFile = createChangelog(pkgName, version, makeMtn(mtnName, mtnEmail)) echo("debian/changelog") writeDebian("changelog", changelogFile) @@ -206,7 +206,7 @@ proc prepDeb*(packName, version, mtnName, mtnEmail, shortDesc, desc: string, createIncludeBinaries(binaries)) echo("All done, you can now build.") - echo("Before you do however, make sure the files in " & + echo("Before you do however, make sure the files in " & workingDir / upstreamSource / "debian" & " are correct.") echo("Change your directory to: " & workingDir / upstreamSource) echo("And execute `debuild -us -uc` to build the .deb") @@ -214,22 +214,22 @@ proc prepDeb*(packName, version, mtnName, mtnEmail, shortDesc, desc: string, when isMainModule: #var controlFile = createControl("nim", "Dominik Picheta <morfeusz8@gmail.com>", # "The Nim compiler", "Compiler for the Nim programming language", "gcc (>= 4:4.3.2)", "gcc (>= 4:4.3.2)") - + #echo(controlFile) - + #var copyrightFile = createCopyright("nim", "Dominik Picheta", "morfeusz8@a.b", "0.8.14", # @[("bin/nim", "gpl2"), ("lib/*", "lgpl")]) - + #echo copyrightFile - + #var changelogFile = createChangelog("nim", "0.8.14", "Dom P <m@b.c>") #echo(changelogFile) - + #echo(createRules()) - prepDeb("nim", "0.9.2", "Dominik Picheta", "morfeusz8@gmail.com", + prepDeb("nim", "0.9.2", "Dominik Picheta", "morfeusz8@gmail.com", "The Nim compiler", "Compiler for the Nim programming language", - @[("bin/nim", "MIT"), ("lib/*", "MIT")], + @[("bin/nim", "MIT"), ("lib/*", "MIT")], @["bin/nim"], @["config/*"], @["doc/*"], @["lib/*"], "gcc (>= 4:4.3.2)", "gcc (>= 4:4.3.2)") diff --git a/tools/niminst/deinstall.tmpl b/tools/niminst/deinstall.tmpl index c4717a257..7349abcb4 100644 --- a/tools/niminst/deinstall.tmpl +++ b/tools/niminst/deinstall.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateDeinstallScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated by niminst\n" # var proj = c.name.toLower diff --git a/tools/niminst/inno.tmpl b/tools/niminst/inno.tmpl index 4acf0557c..ef2da8a75 100644 --- a/tools/niminst/inno.tmpl +++ b/tools/niminst/inno.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl | standard +#? stdtmpl | standard #proc generateInnoSetup(c: ConfigData): string = # result = "" ; Default Template for NimInst diff --git a/tools/niminst/install.tmpl b/tools/niminst/install.tmpl index 3ec42c287..14d88e07d 100644 --- a/tools/niminst/install.tmpl +++ b/tools/niminst/install.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar = '?') | standard +#? stdtmpl(subsChar = '?') | standard #proc generateInstallScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated by niminst\n" # var proj = c.name.toLower diff --git a/tools/niminst/makefile.tmpl b/tools/niminst/makefile.tmpl index 8ab3b89d1..6615ddc02 100644 --- a/tools/niminst/makefile.tmpl +++ b/tools/niminst/makefile.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateMakefile(c: ConfigData): string = # result = "# Generated from niminst\n" & # "# Template is in tools/niminst/makefile.tmpl\n" & diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim index e50b251d3..d1216701f 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -8,7 +8,7 @@ # const - haveZipLib = defined(unix) + haveZipLib = false # zip not in stdlib anymore when haveZipLib: import zipfiles @@ -35,6 +35,7 @@ type actionNsis, # action: create NSIS installer actionScripts # action: create install and deinstall scripts actionZip, # action: create zip file + actionXz, # action: create xz file actionDeb # action: prepare deb package FileCategory = enum @@ -171,6 +172,7 @@ proc parseCmdLine(c: var ConfigData) = of "csource": incl(c.actions, actionCSource) of "scripts": incl(c.actions, actionScripts) of "zip": incl(c.actions, actionZip) + of "xz": incl(c.actions, actionXz) of "inno": incl(c.actions, actionInno) of "nsis": incl(c.actions, actionNsis) of "deb": incl(c.actions, actionDeb) @@ -181,10 +183,10 @@ proc parseCmdLine(c: var ConfigData) = break of cmdLongoption, cmdShortOption: case normalize(key.string) - of "help", "h": + of "help", "h": stdout.write(Usage) quit(0) - of "version", "v": + of "version", "v": stdout.write(Version & "\n") quit(0) of "o", "output": c.outdir = val @@ -240,7 +242,7 @@ proc incl(s: var seq[string], x: string): int = for i in 0.. <s.len: if cmpIgnoreStyle(s[i], x) == 0: return i s.add(x) - result = s.len-1 + result = s.len-1 proc platforms(c: var ConfigData, v: string) = for line in splitLines(v): @@ -277,17 +279,17 @@ proc parseIniFile(c: var ConfigData) = of "name": c.name = v of "displayname": c.displayName = v of "version": c.version = v - of "os": + of "os": c.oses = split(v, {';'}) hasCpuOs = true if c.explicitPlatforms: quit(errorStr(p, "you cannot have both 'platforms' and 'os'")) - of "cpu": + of "cpu": c.cpus = split(v, {';'}) hasCpuOs = true if c.explicitPlatforms: quit(errorStr(p, "you cannot have both 'platforms' and 'cpu'")) - of "platforms": + of "platforms": platforms(c, v) c.explicitPlatforms = true if hasCpuOs: @@ -389,7 +391,7 @@ proc readCFiles(c: var ConfigData, osA, cpuA: int) = of cfgKeyValuePair: case section of "ccompiler": pathFlags(p, k.key, k.value, c.ccompiler) - of "linker": + of "linker": pathFlags(p, k.key, k.value, c.linker) # HACK: we conditionally add ``-lm -ldl``, so remove them from the # linker flags: @@ -536,7 +538,7 @@ when haveZipLib: var n = "$#.zip" % proj if c.outdir.len == 0: n = "build" / n else: n = c.outdir / n - var z: TZipArchive + var z: ZipArchive if open(z, n, fmWrite): addFile(z, proj / buildBatFile32, "build" / buildBatFile32) addFile(z, proj / buildBatFile64, "build" / buildBatFile64) @@ -558,28 +560,66 @@ when haveZipLib: else: quit("Cannot open for writing: " & n) +proc xzDist(c: var ConfigData) = + let proj = toLower(c.name) & "-" & c.version + var n = "$#.tar.xz" % proj + let tmpDir = if c.outdir.len == 0: "build" else: c.outdir + + template processFile(z, dest, src) = + let s = src + let d = dest + echo "Copying ", s, " to ", tmpDir / d + let destdir = tmpdir / d.splitFile.dir + if not dirExists(destdir): createDir(destdir) + copyFileWithPermissions(s, tmpDir / d) + + processFile(z, proj / buildBatFile32, "build" / buildBatFile32) + processFile(z, proj / buildBatFile64, "build" / buildBatFile64) + processFile(z, proj / buildShFile, "build" / buildShFile) + processFile(z, proj / makeFile, "build" / makeFile) + processFile(z, proj / installShFile, installShFile) + processFile(z, proj / deinstallShFile, deinstallShFile) + for f in walkFiles(c.libpath / "lib/*.h"): + processFile(z, proj / "c_code" / extractFilename(f), f) + for osA in 1..c.oses.len: + for cpuA in 1..c.cpus.len: + var dir = buildDir(osA, cpuA) + for k, f in walkDir("build" / dir): + if k == pcFile: processFile(z, proj / dir / extractFilename(f), f) + + for cat in items({fcConfig..fcOther, fcUnix}): + for f in items(c.cat[cat]): processFile(z, proj / f, f) + + let oldDir = getCurrentDir() + setCurrentDir(tmpDir) + try: + if execShellCmd("XZ_OPT=-9 tar Jcf $1.tar.xz $1" % proj) != 0: + echo("External program failed") + finally: + setCurrentDir(oldDir) + # -- prepare build files for .deb creation proc debDist(c: var ConfigData) = if not existsFile(getOutputDir(c) / "build.sh"): quit("No build.sh found.") if not existsFile(getOutputDir(c) / "install.sh"): quit("No install.sh found.") - + if c.debOpts.shortDesc == "": quit("shortDesc must be set in the .ini file.") if c.debOpts.licenses.len == 0: echo("[Warning] No licenses specified for .deb creation.") - + # -- Copy files into /tmp/.. echo("Copying source to tmp/niminst/deb/") var currentSource = getCurrentDir() var workingDir = getTempDir() / "niminst" / "deb" var upstreamSource = (c.name.toLower() & "-" & c.version) - + createDir(workingDir / upstreamSource) - + template copyNimDist(f, dest: string): stmt = createDir((workingDir / upstreamSource / dest).splitFile.dir) copyFile(currentSource / f, workingDir / upstreamSource / dest) - + # Don't copy all files, only the ones specified in the config: copyNimDist(buildShFile, buildShFile) copyNimDist(makeFile, makeFile) @@ -624,5 +664,7 @@ if actionZip in c.actions: zipDist(c) else: quit("libzip is not installed") +if actionXz in c.actions: + xzDist(c) if actionDeb in c.actions: debDist(c) diff --git a/tools/niminst/nsis.tmpl b/tools/niminst/nsis.tmpl index c21bfb9d5..abf462388 100644 --- a/tools/niminst/nsis.tmpl +++ b/tools/niminst/nsis.tmpl @@ -1,5 +1,5 @@ -#! stdtmpl(subsChar='?') | standard -#proc generateNsisSetup(c: ConfigData): string = +#? stdtmpl(subsChar='?') | standard +#proc generateNsisSetup(c: ConfigData): string = # result = "; NSIS script generated by niminst\n" & # "; To regenerate run ``niminst nsis`` or ``koch nsis``\n" @@ -35,8 +35,8 @@ ; Default installation folder ; This is changed later (in .onInit) to the root directory, if possible. - InstallDir "$LOCALAPPDATA\?{c.name}" - + InstallDir "$LOCALAPPDATA\?{c.name}-?{c.version}" + ; Get installation folder from registry if available InstallDirRegKey HKCU "Software\c.name\c.version" "" @@ -86,14 +86,14 @@ !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH - + ; Setup the uninstaller pages !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES - + ;-------------------------------- ;Languages - + !insertmacro MUI_LANGUAGE "English" ;-------------------------------- @@ -104,7 +104,7 @@ ; Nim binary. Section "Core Files" CoreSection ; This is a mandotory section - SectionIn RO + SectionIn RO ; Output files to the base installation directory SetOutPath "$INSTDIR" @@ -164,7 +164,7 @@ ; The downloadable sections. These sections are automatically generated by ; niminst and the template filters. - #var i = 0 + #var i = 0 #for download in c.downloads: # inc i # let d = download.split('|') @@ -207,7 +207,7 @@ CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\?{e}.lnk" "$INSTDIR\?dir\?{startMenuEntry.toWin}" !insertmacro MUI_STARTMENU_WRITE_END # end if - + ignore: SectionEnd #end |