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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
#
#
# The Nim Installation Generator
# (c) Copyright 2012 Dominik Picheta
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
import osproc, times, os, strutils
when defined(nimPreviewSlimSystem):
import std/[assertions, syncio]
# http://www.debian.org/doc/manuals/maint-guide/
# Required files for debhelper.
# -- control
# -- copyright
# -- changelog
# -- rules
type
TDebOptions* = object
buildDepends*, pkgDepends*, shortDesc*: string
licenses*: seq[tuple[files, license: string]]
template addN(r: string) =
result.add(r)
result.add("\n")
proc createControl(pkgName, maintainer, shortDesc, desc: string,
buildDepends, pkgDepends: string = ""): string =
## pkgName: Should be the package name, no spaces.
## maintainer: firstName lastName <email>
## shortDesc: short description of the application
## desc: long description of the application
## buildDepends: what the build depends on (compiling from source),
## this needs to be in the format deb accepts. For example,
## for gcc: ``gcc (>= 4:4.3.2)``
## 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)" &
(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,
licenses: seq[tuple[files, license: string]]): string =
## pkgName: Package name
## mtnName: Maintainer name
## mtnEmail: Maintainer email
## version: package version
## 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)
addN("Date: " & $getTime())
addN("Package Name: " & pkgName)
addN("Version: " & version)
for f, license in items(licenses):
addN("Files: " & f)
addN("License: " & license)
proc formatDateTime(t: DateTime, 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]
proc createChangelog(pkgName, version, maintainer: string): string =
## pkgName: package name
## version: package version
## maintainer: firstName lastName <email>
result = ""
addN(pkgName & " (" & version & "-1) unstable; urgency=low")
addN("")
addN(" * Initial release.")
addN("")
addN(" -- " & maintainer & " " &
formatDateTime(utc(getTime()), "+0000"))
proc createRules(): string =
## Creates a nim application-agnostic rules file for building deb packages.
## Please note: this assumes the c sources have been built and the
## ``build.sh`` and ``install.sh`` files are available.
result = ""
addN("#!/usr/bin/make -f")
addN("%:")
addN("\tdh $@\n")
addN("dh_install:")
addN("\tdh_install --sourcedir=debian/tmp")
addN("override_dh_auto_clean:")
addN("\tfind . -name *.o -exec rm {} \\;")
addN("override_dh_auto_build:")
addN("\t./build.sh")
addN("override_dh_auto_install:")
addN("\t./install.sh debian/tmp")
proc createIncludeBinaries(binaries: seq[string]): string =
return join(binaries, "\n")
proc createDotInstall(pkgName: string, binaries, config, docs,
lib: seq[string]): string =
result = ""
for b in binaries:
addN(pkgName / b & " " & "usr/bin/")
for c in config:
addN(pkgName / c & " " & "etc/")
for d in docs:
addN(pkgName / d & " " & "usr/share/doc/nim/")
for l1 in lib:
addN(pkgName / l1 & " " & "usr/lib/nim")
proc makeMtn(name, email: string): string =
return name & " <" & email & ">"
proc assertSuccess(exitCode: int) =
doAssert(exitCode == QuitSuccess)
proc prepDeb*(packName, version, mtnName, mtnEmail, shortDesc, desc: string,
licenses: seq[tuple[files, license: string]], binaries,
config, docs, lib: seq[string],
buildDepends, pkgDepends = "") =
## binaries/config/docs/lib: files relative to nim's root, that need to
## be installed.
let pkgName = packName.toLowerAscii()
var workingDir = getTempDir() / "niminst" / "deb"
var upstreamSource = (pkgName & "-" & version)
echo("Making sure build.sh and install.sh are +x")
assertSuccess execCmd("chmod +x \"" &
(workingDir / upstreamSource / "build.sh") & "\"")
assertSuccess execCmd("chmod +x \"" &
(workingDir / upstreamSource / "install.sh") & "\"")
var tarCmd = "tar pczf \"" &
(pkgName & "_" & version & ".orig.tar.gz") &
"\" \"" & upstreamSource & "\""
echo(tarCmd)
assertSuccess execCmd("cd \"" & workingDir & "\" && " & tarCmd)
echo("Creating necessary files in debian/")
createDir(workingDir / upstreamSource / "debian")
template writeDebian(f, s: string) =
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,
makeMtn(mtnName, mtnEmail))
echo("debian/changelog")
writeDebian("changelog", changelogFile)
echo("debian/rules")
writeDebian("rules", createRules())
echo("debian/compat")
writeDebian("compat", "8")
echo("debian/" & pkgName & ".install")
writeDebian(pkgName & ".install",
createDotInstall(pkgName, binaries, config, docs, lib))
# Other things..
createDir(workingDir / upstreamSource / "debian" / "source")
echo("debian/source/format")
writeDebian("source" / "format",
"3.0 (quilt)")
echo("debian/source/include-binaries")
writeFile(workingDir / upstreamSource / "debian" / "source" / "include-binaries",
createIncludeBinaries(binaries))
echo("All done, you can now build.")
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")
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",
"The Nim compiler", "Compiler for the Nim programming language",
@[("bin/nim", "MIT"), ("lib/*", "MIT")],
@["bin/nim"], @["config/*"], @["doc/*"], @["lib/*"],
"gcc (>= 4:4.3.2)", "gcc (>= 4:4.3.2)")
|