diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/nimgrep.nim | 4 | ||||
-rw-r--r-- | tools/niminst/buildbat.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/buildsh.tmpl | 14 | ||||
-rw-r--r-- | tools/niminst/debcreation.nim | 2 | ||||
-rw-r--r-- | tools/niminst/deinstall.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/inno.tmpl | 4 | ||||
-rw-r--r-- | tools/niminst/install.tmpl | 2 | ||||
-rw-r--r-- | tools/niminst/makefile.tmpl | 168 | ||||
-rw-r--r-- | tools/niminst/niminst.nim | 90 | ||||
-rw-r--r-- | tools/niminst/nsis.tmpl | 10 | ||||
-rw-r--r-- | tools/nimrepl.nim | 2 | ||||
-rw-r--r-- | tools/nimweb.nim | 65 | ||||
-rw-r--r-- | tools/website.tmpl | 250 |
13 files changed, 472 insertions, 143 deletions
diff --git a/tools/nimgrep.nim b/tools/nimgrep.nim index a38f2a88f..72e4adc07 100644 --- a/tools/nimgrep.nim +++ b/tools/nimgrep.nim @@ -24,7 +24,7 @@ Options: --re pattern is a regular expression (default); extended syntax for the regular expression is always turned on --recursive process directories recursively - --confirm confirm each occurence/replacement; there is a chance + --confirm confirm each occurrence/replacement; there is a chance to abort any time without touching the file --stdin read pattern from stdin (to avoid the shell's confusing quoting rules) @@ -109,7 +109,7 @@ proc highlight(s, match, repl: string, t: tuple[first, last: int], for i in t.last+1 .. y: stdout.write(s[i]) stdout.write("\n") if showRepl: - stdout.write(repeatChar(alignment-1), "-> ") + stdout.write(spaces(alignment-1), "-> ") for i in x .. t.first-1: stdout.write(s[i]) writeColored(repl) for i in t.last+1 .. y: stdout.write(s[i]) diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl index 415574273..3a11715bf 100644 --- a/tools/niminst/buildbat.tmpl +++ b/tools/niminst/buildbat.tmpl @@ -1,5 +1,5 @@ #! stdtmpl(subsChar='?') | standard -#proc generateBuildBatchScript(c: TConfigData, winIndex, cpuIndex: int): string = +#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex: int): string = # result = "@echo off\nREM Generated by niminst\n" SET CC=gcc SET LINKER=gcc diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl index 4966af07a..52da351be 100644 --- a/tools/niminst/buildsh.tmpl +++ b/tools/niminst/buildsh.tmpl @@ -1,7 +1,7 @@ #! stdtmpl(subsChar='?') | standard -#proc generateBuildShellScript(c: TConfigData): string = +#proc generateBuildShellScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated from niminst\n" & -# "# Template is in tools/buildsh.tmpl\n" & +# "# Template is in tools/niminst/buildsh.tmpl\n" & # "# To regenerate run ``niminst csource`` or ``koch csource``\n" set -e @@ -54,10 +54,16 @@ case $uos in myos="linux" LINK_FLAGS="$LINK_FLAGS -ldl -lm" ;; - *freebsd* | *dragonfly* ) + *dragonfly* ) myos="freebsd" LINK_FLAGS="$LINK_FLAGS -lm" ;; + *freebsd* ) + myos="freebsd" + CC="clang" + LINKER="clang" + LINK_FLAGS="$LINK_FLAGS -lm" + ;; *openbsd* ) myos="openbsd" LINK_FLAGS="$LINK_FLAGS -lm" @@ -105,7 +111,7 @@ case $ucpu in LINK_FLAGS="$LINK_FLAGS -m64" fi mycpu="powerpc64" ;; - *power*|*Power*|*ppc* ) + *power*|*ppc* ) mycpu="powerpc" ;; *mips* ) mycpu="mips" ;; diff --git a/tools/niminst/debcreation.nim b/tools/niminst/debcreation.nim index 574f7ea6b..bbd997981 100644 --- a/tools/niminst/debcreation.nim +++ b/tools/niminst/debcreation.nim @@ -84,7 +84,7 @@ proc createCopyright(pkgName, mtnName, mtnEmail, version: string, addN("Files: " & f) addN("License: " & license) -proc formatDateTime(t: TTimeInfo, timezone: string): 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), diff --git a/tools/niminst/deinstall.tmpl b/tools/niminst/deinstall.tmpl index 15f912af6..c4717a257 100644 --- a/tools/niminst/deinstall.tmpl +++ b/tools/niminst/deinstall.tmpl @@ -1,5 +1,5 @@ #! stdtmpl(subsChar='?') | standard -#proc generateDeinstallScript(c: TConfigData): string = +#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 3460c22a2..4acf0557c 100644 --- a/tools/niminst/inno.tmpl +++ b/tools/niminst/inno.tmpl @@ -1,5 +1,5 @@ #! stdtmpl | standard -#proc generateInnoSetup(c: TConfigData): string = +#proc generateInnoSetup(c: ConfigData): string = # result = "" ; Default Template for NimInst [Setup] @@ -19,7 +19,7 @@ ChangesEnvironment=yes Name: english; MessagesFile: compiler:Default.isl [Files] - #for i in low(TFileCategory)..fcWindows: + #for i in low(FileCategory)..fcWindows: # for f in items(c.cat[i]): Source: ${expandFilename(f).toWin}; DestDir: {app}\${splitFile(f).dir.toWin}; Flags: ignoreversion # end for diff --git a/tools/niminst/install.tmpl b/tools/niminst/install.tmpl index 437e13dfb..3ec42c287 100644 --- a/tools/niminst/install.tmpl +++ b/tools/niminst/install.tmpl @@ -1,5 +1,5 @@ #! stdtmpl(subsChar = '?') | standard -#proc generateInstallScript(c: TConfigData): string = +#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 new file mode 100644 index 000000000..8ab3b89d1 --- /dev/null +++ b/tools/niminst/makefile.tmpl @@ -0,0 +1,168 @@ +#! stdtmpl(subsChar='?') | standard +#proc generateMakefile(c: ConfigData): string = +# result = "# Generated from niminst\n" & +# "# Template is in tools/niminst/makefile.tmpl\n" & +# "# To regenerate run ``niminst csource`` or ``koch csource``\n" + +CC = gcc +LINKER = gcc +COMP_FLAGS = ?{c.ccompiler.flags} +LINK_FLAGS = ?{c.linker.flags} +binDir = ?{firstBinPath(c).toUnix} + +koch := $(shell sh -c 'test -s ../koch.nim && echo "yes"') +ifeq ($(koch),yes) + binDir = ../bin +endif + +ucpu := $(shell sh -c 'uname -m | tr "[:upper:]" "[:lower:]"') +uos := $(shell sh -c 'uname | tr "[:upper:]" "[:lower:]"') + +ifeq ($(uos),linux) + myos = linux + LINK_FLAGS += -ldl -lm +endif +ifeq ($(uos),dragonfly) + myos = freebsd + LINK_FLAGS += -lm +endif +ifeq ($(uos),freebsd) + myos= freebsd + CC = clang + LINKER = clang + LINK_FLAGS += -lm +endif +ifeq ($(uos),openbsd) + myos = openbsd + LINK_FLAGS += -lm +endif +ifeq ($(uos),netbsd) + myos = netbsd + LINK_FLAGS += -lm +endif +ifeq ($(uos),darwin) + myos = macosx + CC = clang + LINKER = clang + LINK_FLAGS += -ldl -lm + ifeq ($HOSTTYPE,x86_64) + ucpu = amd64 + endif +endif +ifeq ($(uos),aix) + myos = aix + LINK_FLAGS += -dl -lm +endif +ifeq ($(uos),solaris) + myos = solaris + LINK_FLAGS += -ldl -lm -lsocket -lnsl +endif +ifeq ($(uos),sun) + myos = solaris + LINK_FLAGS += -ldl -lm -lsocket -lnsl +endif +ifeq ($(uos),haiku) + myos = haiku +endif +ifndef uos + @echo "Error: unknown operating system: $(uos)" + @exit 1 +endif + +ifeq ($(ucpu),i386) + mycpu = i386 +endif +ifeq ($(ucpu),i486) + mycpu = i386 +endif +ifeq ($(ucpu),i586) + mycpu = i386 +endif +ifeq ($(ucpu),i686) + mycpu = i386 +endif +ifeq ($(ucpu),bepc) + mycpu = i386 +endif +ifeq ($(ucpu),i86pc) + mycpu = i386 +endif +ifeq ($(ucpu),amd64) + mycpu = amd64 +endif +ifeq ($(ucpu),x86-64) + mycpu = amd64 +endif +ifeq ($(ucpu),x86_64) + mycpu = amd64 +endif +ifeq ($(ucpu),sparc) + mycpu = sparc +endif +ifeq ($(ucpu),sun) + mycpu = sparc +endif +ifeq ($(ucpu),ppc64) + mycpu = powerpc64 + ifeq ($(myos),linux) + COMP_FLAGS += -m64 + LINK_FLAGS += -m64 + endif +endif +ifeq ($(ucpu),powerpc) + mycpu = powerpc +endif +ifeq ($(ucpu),ppc) + mycpu = ppc +endif +ifeq ($(ucpu),mips) + mycpu = mips +endif +ifeq ($(ucpu),arm) + mycpu = arm +endif +ifeq ($(ucpu),armeb) + mycpu = arm +endif +ifeq ($(ucpu),armel) + mycpu = arm +endif +ifeq ($(ucpu),armv6l) + mycpu = arm +endif +ifndef ucpu + @echo "Error: unknown processor : $(ucpu)" + @exit 1 +endif + +# for osA in 1..c.oses.len: +ifeq ($(myos),?{c.oses[osA-1]}) +# for cpuA in 1..c.cpus.len: + ifeq ($(mycpu),?{c.cpus[cpuA-1]}) +# var oFiles = "" +# for ff in c.cfiles[osA][cpuA].items: +# oFiles.add(" " & changeFileExt(ff.toUnix, "o")) +# end for + oFiles =?oFiles + endif +# end for +endif +# end for + +ifeq ($(strip $(oFiles)),) + @echo "Error: no C code generated for: [$(myos): $(mycpu)]" + @exit 1 +endif + +%.o: %.c + $(CC) $(COMP_FLAGS) -Ic_code -c $< -o $@ + +?{"$(binDir)/" & toLower(c.name)}: $(oFiles) + @mkdir -p $(binDir) + $(LINKER) -o $@ $^ $(LINK_FLAGS) + @echo "SUCCESS" + +.PHONY: clean + +clean: + rm -f $(oFiles) ?{"$(binDir)/" & toLower(c.name)} diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim index 9ee3eb9b9..e50b251d3 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -1,7 +1,7 @@ # # # The Nim Installation Generator -# (c) Copyright 2014 Andreas Rumpf +# (c) Copyright 2015 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -22,12 +22,13 @@ const buildShFile = "build.sh" buildBatFile32 = "build.bat" buildBatFile64 = "build64.bat" + makeFile = "makefile" installShFile = "install.sh" deinstallShFile = "deinstall.sh" type - TAppType = enum appConsole, appGUI - TAction = enum + AppType = enum appConsole, appGUI + Action = enum actionNone, # action not yet known actionCSource # action: create C sources actionInno, # action: create Inno Setup installer @@ -36,7 +37,7 @@ type actionZip, # action: create zip file actionDeb # action: prepare deb package - TFileCategory = enum + FileCategory = enum fcWinBin, # binaries for Windows fcConfig, # configuration files fcData, # data files @@ -48,19 +49,19 @@ type fcUnixBin, # binaries for Unix fcDocStart # links to documentation for Windows installer - TConfigData = object of TObject - actions: set[TAction] - cat: array[TFileCategory, seq[string]] + ConfigData = object of RootObj + actions: set[Action] + cat: array[FileCategory, seq[string]] binPaths, authors, oses, cpus, downloads: seq[string] cfiles: array[1..maxOS, array[1..maxCPU, seq[string]]] platforms: array[1..maxOS, array[1..maxCPU, bool]] ccompiler, linker, innosetup, nsisSetup: tuple[path, flags: string] name, displayName, version, description, license, infile, outdir: string - libpath: string + mainfile, libpath: string innoSetupFlag, installScript, uninstallScript: bool explicitPlatforms: bool - vars: PStringTable - app: TAppType + vars: StringTableRef + app: AppType nimArgs: string debOpts: TDebOptions @@ -69,9 +70,9 @@ const "$configdir", "$datadir", "$docdir", "$libdir" ] -proc initConfigData(c: var TConfigData) = +proc iniConfigData(c: var ConfigData) = c.actions = {} - for i in low(TFileCategory)..high(TFileCategory): c.cat[i] = @[] + for i in low(FileCategory)..high(FileCategory): c.cat[i] = @[] c.binPaths = @[] c.authors = @[] c.oses = @[] @@ -87,6 +88,7 @@ proc initConfigData(c: var TConfigData) = c.description = "" c.license = "" c.infile = "" + c.mainfile = "" c.outdir = "" c.nimArgs = "" c.libpath = "" @@ -100,7 +102,7 @@ proc initConfigData(c: var TConfigData) = c.debOpts.shortDesc = "" c.debOpts.licenses = @[] -proc firstBinPath(c: TConfigData): string = +proc firstBinPath(c: ConfigData): string = if c.binPaths.len > 0: result = c.binPaths[0] else: result = "" @@ -122,6 +124,7 @@ proc skipRoot(f: string): string = include "inno.tmpl" include "nsis.tmpl" include "buildsh.tmpl" +include "makefile.tmpl" include "buildbat.tmpl" include "install.tmpl" include "deinstall.tmpl" @@ -132,7 +135,7 @@ const Version = "1.0" Usage = "niminst - Nim Installation Generator Version " & Version & """ - (c) 2014 Andreas Rumpf + (c) 2015 Andreas Rumpf Usage: niminst [options] command[;command2...] ini-file[.ini] [compile_options] Command: @@ -144,6 +147,8 @@ Command: deb create files for debhelper Options: -o, --output:dir set the output directory + -m, --main:file set the main nim file, by default ini-file with .nim + extension --var:name=value set the value of a variable -h, --help shows this help -v, --version shows the version @@ -151,7 +156,7 @@ Compile_options: will be passed to the Nim compiler """ -proc parseCmdLine(c: var TConfigData) = +proc parseCmdLine(c: var ConfigData) = var p = initOptParser() while true: next(p) @@ -183,6 +188,7 @@ proc parseCmdLine(c: var TConfigData) = stdout.write(Version & "\n") quit(0) of "o", "output": c.outdir = val + of "m", "main": c.mainfile = changeFileExt(val, "nim") of "var": var idx = val.find('=') if idx < 0: quit("invalid command line") @@ -190,6 +196,7 @@ proc parseCmdLine(c: var TConfigData) = else: quit(Usage) of cmdEnd: break if c.infile.len == 0: quit(Usage) + if c.mainfile.len == 0: c.mainfile = changeFileExt(c.infile, "nim") proc walkDirRecursively(s: var seq[string], root: string) = for k, f in walkDir(root): @@ -209,19 +216,19 @@ proc addFiles(s: var seq[string], patterns: seq[string]) = inc(i) if i == 0: echo("[Warning] No file found that matches: " & p) -proc pathFlags(p: var TCfgParser, k, v: string, +proc pathFlags(p: var CfgParser, k, v: string, t: var tuple[path, flags: string]) = case normalize(k) of "path": t.path = v of "flags": t.flags = v else: quit(errorStr(p, "unknown variable: " & k)) -proc filesOnly(p: var TCfgParser, k, v: string, dest: var seq[string]) = +proc filesOnly(p: var CfgParser, k, v: string, dest: var seq[string]) = case normalize(k) of "files": addFiles(dest, split(v, {';'})) else: quit(errorStr(p, "unknown variable: " & k)) -proc yesno(p: var TCfgParser, v: string): bool = +proc yesno(p: var CfgParser, v: string): bool = case normalize(v) of "yes", "y", "on", "true": result = true @@ -235,7 +242,7 @@ proc incl(s: var seq[string], x: string): int = s.add(x) result = s.len-1 -proc platforms(c: var TConfigData, v: string) = +proc platforms(c: var ConfigData, v: string) = for line in splitLines(v): let p = line.find(": ") if p <= 1: continue @@ -246,9 +253,9 @@ proc platforms(c: var TConfigData, v: string) = let cpuIdx = c.cpus.incl(cpu) c.platforms[c.oses.len][cpuIdx+1] = true -proc parseIniFile(c: var TConfigData) = +proc parseIniFile(c: var ConfigData) = var - p: TCfgParser + p: CfgParser section = "" hasCpuOs = false var input = newFileStream(c.infile, fmRead) @@ -358,15 +365,15 @@ proc parseIniFile(c: var TConfigData) = of cfgOption: quit(errorStr(p, "syntax error")) of cfgError: quit(errorStr(p, k.msg)) close(p) - if c.name.len == 0: c.name = changeFileExt(extractFilename(c.infile), "") + if c.name.len == 0: c.name = changeFileExt(extractFilename(c.mainfile), "") if c.displayName.len == 0: c.displayName = c.name else: quit("cannot open: " & c.infile) # ------------------------- generate source based installation --------------- -proc readCFiles(c: var TConfigData, osA, cpuA: int) = - var p: TCfgParser +proc readCFiles(c: var ConfigData, osA, cpuA: int) = + var p: CfgParser var f = splitFile(c.infile).dir / "mapping.txt" c.cfiles[osA][cpuA] = @[] var input = newFileStream(f, fmRead) @@ -402,11 +409,11 @@ proc readCFiles(c: var TConfigData, osA, cpuA: int) = proc buildDir(os, cpu: int): string = return "c_code" / ($os & "_" & $cpu) -proc getOutputDir(c: var TConfigData): string = +proc getOutputDir(c: var ConfigData): string = if c.outdir.len > 0: c.outdir else: "build" proc writeFile(filename, content, newline: string) = - var f: TFile + var f: File if open(f, filename, fmWrite): for x in splitLines(content): write(f, x) @@ -415,7 +422,7 @@ proc writeFile(filename, content, newline: string) = else: quit("Cannot open for writing: " & filename) -proc removeDuplicateFiles(c: var TConfigData) = +proc removeDuplicateFiles(c: var ConfigData) = for osA in countdown(c.oses.len, 1): for cpuA in countdown(c.cpus.len, 1): if c.cfiles[osA][cpuA].isNil: c.cfiles[osA][cpuA] = @[] @@ -433,13 +440,15 @@ proc removeDuplicateFiles(c: var TConfigData) = removeFile(dup) c.cfiles[osA][cpuA][i] = orig -proc writeInstallScripts(c: var TConfigData) = +proc writeInstallScripts(c: var ConfigData) = if c.installScript: writeFile(installShFile, generateInstallScript(c), "\10") + inclFilePermissions(installShFile, {fpUserExec, fpGroupExec, fpOthersExec}) if c.uninstallScript: writeFile(deinstallShFile, generateDeinstallScript(c), "\10") + inclFilePermissions(deinstallShFile, {fpUserExec, fpGroupExec, fpOthersExec}) -proc srcdist(c: var TConfigData) = +proc srcdist(c: var ConfigData) = if not existsDir(getOutputDir(c) / "c_code"): createDir(getOutputDir(c) / "c_code") for x in walkFiles(c.libpath / "lib/*.h"): @@ -462,8 +471,7 @@ proc srcdist(c: var TConfigData) = var cmd = ("nim compile -f --symbolfiles:off --compileonly " & "--gen_mapping --cc:gcc --skipUserCfg" & " --os:$# --cpu:$# $# $#") % - [osname, cpuname, c.nimArgs, - changeFileExt(c.infile, "nim")] + [osname, cpuname, c.nimArgs, c.mainfile] echo(cmd) if execShellCmd(cmd) != 0: quit("Error: call to nim compiler failed") @@ -476,6 +484,8 @@ proc srcdist(c: var TConfigData) = # second pass: remove duplicate files removeDuplicateFiles(c) writeFile(getOutputDir(c) / buildShFile, generateBuildShellScript(c), "\10") + inclFilePermissions(getOutputDir(c) / buildShFile, {fpUserExec, fpGroupExec, fpOthersExec}) + writeFile(getOutputDir(c) / makeFile, generateMakefile(c), "\10") if winIndex >= 0: if intel32Index >= 0: writeFile(getOutputDir(c) / buildBatFile32, @@ -486,7 +496,7 @@ proc srcdist(c: var TConfigData) = writeInstallScripts(c) # --------------------- generate inno setup ----------------------------------- -proc setupDist(c: var TConfigData) = +proc setupDist(c: var ConfigData) = let scrpt = generateInnoSetup(c) let n = "build" / "install_$#_$#.iss" % [toLower(c.name), c.version] writeFile(n, scrpt, "\13\10") @@ -503,7 +513,7 @@ proc setupDist(c: var TConfigData) = quit("External program failed") # --------------------- generate NSIS setup ----------------------------------- -proc setupDist2(c: var TConfigData) = +proc setupDist2(c: var ConfigData) = let scrpt = generateNsisSetup(c) let n = "build" / "install_$#_$#.nsi" % [toLower(c.name), c.version] writeFile(n, scrpt, "\13\10") @@ -521,9 +531,9 @@ proc setupDist2(c: var TConfigData) = # ------------------ generate ZIP file --------------------------------------- when haveZipLib: - proc zipDist(c: var TConfigData) = - var proj = toLower(c.name) - var n = "$#_$#.zip" % [proj, c.version] + proc zipDist(c: var ConfigData) = + var proj = toLower(c.name) & "-" & c.version + var n = "$#.zip" % proj if c.outdir.len == 0: n = "build" / n else: n = c.outdir / n var z: TZipArchive @@ -531,6 +541,7 @@ when haveZipLib: addFile(z, proj / buildBatFile32, "build" / buildBatFile32) addFile(z, proj / buildBatFile64, "build" / buildBatFile64) addFile(z, proj / buildShFile, "build" / buildShFile) + addFile(z, proj / makeFile, "build" / makeFile) addFile(z, proj / installShFile, installShFile) addFile(z, proj / deinstallShFile, deinstallShFile) for f in walkFiles(c.libpath / "lib/*.h"): @@ -549,7 +560,7 @@ when haveZipLib: # -- prepare build files for .deb creation -proc debDist(c: var TConfigData) = +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.") @@ -571,6 +582,7 @@ proc debDist(c: var TConfigData) = # Don't copy all files, only the ones specified in the config: copyNimDist(buildShFile, buildShFile) + copyNimDist(makeFile, makeFile) copyNimDist(installShFile, installShFile) createDir(workingDir / upstreamSource / "build") for f in walkFiles(c.libpath / "lib/*.h"): @@ -595,8 +607,8 @@ proc debDist(c: var TConfigData) = # ------------------- main ---------------------------------------------------- -var c: TConfigData -initConfigData(c) +var c: ConfigData +iniConfigData(c) parseCmdLine(c) parseIniFile(c) if actionInno in c.actions: diff --git a/tools/niminst/nsis.tmpl b/tools/niminst/nsis.tmpl index 40e171d41..c21bfb9d5 100644 --- a/tools/niminst/nsis.tmpl +++ b/tools/niminst/nsis.tmpl @@ -1,5 +1,5 @@ #! stdtmpl(subsChar='?') | standard -#proc generateNsisSetup(c: TConfigData): string = +#proc generateNsisSetup(c: ConfigData): string = # result = "; NSIS script generated by niminst\n" & # "; To regenerate run ``niminst nsis`` or ``koch nsis``\n" @@ -50,8 +50,8 @@ SetCompressor /SOLID /FINAL lzma ; Installer and Uninstaller Icons - ; Icon "nimrod.ico" - ; UninstallIcon "nimrod.ico" + ; Icon "nim.ico" + ; UninstallIcon "nim.ico" ; Set installation details to be shown by default ShowInstDetails show @@ -113,7 +113,7 @@ SetOverwrite ifnewer ; Write all the files to the output directory. - #for i in low(TFileCategory)..fcWindows: + #for i in low(FileCategory)..fcWindows: # for f in items(c.cat[i]): SetOutPath "$INSTDIR\?{splitFile(f).dir.toWin}" File "?{expandFilename(f).toWin}" @@ -128,7 +128,7 @@ ; Write application registry keys WriteRegStr HKCU "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\?{c.name}.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)" - WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe" + WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstaller.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\bin\?{c.name}.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}" diff --git a/tools/nimrepl.nim b/tools/nimrepl.nim index 0c9f94616..3d818a556 100644 --- a/tools/nimrepl.nim +++ b/tools/nimrepl.nim @@ -130,7 +130,7 @@ proc initControls() = pack_start(MainBox, TopMenu, False, False, 0) - # VPaned - Seperates the InputTextView and the OutputTextView + # VPaned - Separates the InputTextView and the OutputTextView var paned = vpaned_new() set_position(paned, 450) pack_start(MainBox, paned, True, True, 0) diff --git a/tools/nimweb.nim b/tools/nimweb.nim index 46c1d0d85..a7301195e 100644 --- a/tools/nimweb.nim +++ b/tools/nimweb.nim @@ -1,7 +1,7 @@ # # # Nim Website Generator -# (c) Copyright 2014 Andreas Rumpf +# (c) Copyright 2015 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -19,11 +19,17 @@ type authors, projectName, projectTitle, logo, infile, outdir, ticker: string vars: StringTableRef nimArgs: string + gitRepo: string gitCommit: string quotations: Table[string, tuple[quote, author: string]] numProcessors: int # Set by parallelBuild:n, only works for values > 0. + gaId: string # google analytics ID, nil means analytics are disabled TRssItem = object year, month, day, title: string + TAction = enum + actAll, actOnlyWebsite, actPdf + +var action: TAction proc initConfigData(c: var TConfigData) = c.tabs = @[] @@ -42,6 +48,7 @@ proc initConfigData(c: var TConfigData) = c.logo = "" c.ticker = "" c.vars = newStringTable(modeStyleInsensitive) + c.gitRepo = "https://github.com/Araq/Nim/tree" c.gitCommit = "master" c.numProcessors = countProcessors() # Attempts to obtain the git current commit. @@ -59,7 +66,7 @@ const version = "0.7" usage = "nimweb - Nim Website Generator Version " & version & """ - (c) 2014 Andreas Rumpf + (c) 2015 Andreas Rumpf Usage: nimweb [options] ini-file[.ini] [compile_options] Options: @@ -67,6 +74,8 @@ Options: --var:name=value set the value of a variable -h, --help shows this help -v, --version shows the version + --website only build the website, not the full documentation + --pdf build the PDF version of the documentation Compile_options: will be passed to the Nim compiler """ @@ -90,8 +99,8 @@ macro updated(e: expr): expr {.immediate.} = proc updatedDate(year, month, day: string): string = ## wrapper around the update macro with easy input. result = updated("$1-$2-$3T00:00:00Z" % [year, - repeatStr(2 - len(month), "0") & month, - repeatStr(2 - len(day), "0") & day]) + repeat("0", 2 - len(month)) & month, + repeat("0", 2 - len(day)) & day]) macro entry(e: expr): expr {.immediate.} = ## generates the rss xml ``entry`` element. @@ -134,7 +143,14 @@ proc parseCmdLine(c: var TConfigData) = var idx = val.find('=') if idx < 0: quit("invalid command line") c.vars[substr(val, 0, idx-1)] = substr(val, idx+1) - else: quit(usage) + of "website": action = actOnlyWebsite + of "pdf": action = actPdf + of "googleanalytics": + c.gaId = val + c.nimArgs.add("--doc.googleAnalytics:" & val & " ") + else: + echo("Invalid argument $1" % [key]) + quit(usage) of cmdEnd: break if c.infile.len == 0: quit(usage) @@ -252,24 +268,26 @@ proc buildDocSamples(c: var TConfigData, destPath: string) = exec("nim doc2 $# -o:$# $#" % [c.nimArgs, destPath / "docgen_sample2.html", src]) +proc pathPart(d: string): string = splitFile(d).dir.replace('\\', '/') + proc buildDoc(c: var TConfigData, destPath: string) = # call nim for the documentation: var commands = newSeq[string](len(c.doc) + len(c.srcdoc) + len(c.srcdoc2)) i = 0 for d in items(c.doc): - commands[i] = "nim rst2html $# --docSeeSrcUrl:$# -o:$# --index:on $#" % - [c.nimArgs, c.gitCommit, + commands[i] = "nim rst2html $# --docSeeSrcUrl:$#/$#/$# -o:$# --index:on $#" % + [c.nimArgs, c.gitRepo, c.gitCommit, d.pathPart, destPath / changeFileExt(splitFile(d).name, "html"), d] i.inc for d in items(c.srcdoc): - commands[i] = "nim doc $# --docSeeSrcUrl:$# -o:$# --index:on $#" % - [c.nimArgs, c.gitCommit, + commands[i] = "nim doc $# --docSeeSrcUrl:$#/$#/$# -o:$# --index:on $#" % + [c.nimArgs, c.gitRepo, c.gitCommit, d.pathPart, destPath / changeFileExt(splitFile(d).name, "html"), d] i.inc for d in items(c.srcdoc2): - commands[i] = "nim doc2 $# --docSeeSrcUrl:$# -o:$# --index:on $#" % - [c.nimArgs, c.gitCommit, + commands[i] = "nim doc2 $# --docSeeSrcUrl:$#/$#/$# -o:$# --index:on $#" % + [c.nimArgs, c.gitRepo, c.gitCommit, d.pathPart, destPath / changeFileExt(splitFile(d).name, "html"), d] i.inc @@ -301,8 +319,8 @@ proc buildAddDoc(c: var TConfigData, destPath: string) = # build additional documentation (without the index): var commands = newSeq[string](c.webdoc.len) for i, doc in pairs(c.webdoc): - commands[i] = "nim doc $# --docSeeSrcUrl:$# -o:$# $#" % - [c.nimArgs, c.gitCommit, + commands[i] = "nim doc2 $# --docSeeSrcUrl:$#/$#/$# -o:$# $#" % + [c.nimArgs, c.gitRepo, c.gitCommit, doc.pathPart, destPath / changeFileExt(splitFile(doc).name, "html"), doc] mexec(commands, c.numProcessors) @@ -386,10 +404,10 @@ proc buildNewsRss(c: var TConfigData, destPath: string) = generateRss(destFilename, parseNewsTitles(srcFilename)) proc buildJS(destPath: string) = - exec("nim js -d:release --out:$1 web/babelpkglist.nim" % - [destPath / "babelpkglist.js"]) + exec("nim js -d:release --out:$1 web/nimblepkglist.nim" % + [destPath / "nimblepkglist.js"]) -proc main(c: var TConfigData) = +proc buildWebsite(c: var TConfigData) = const cmd = "nim rst2html --compileonly $1 -o:web/$2.temp web/$2.txt" if c.ticker.len > 0: @@ -400,6 +418,7 @@ proc main(c: var TConfigData) = for i in 0..c.tabs.len-1: var file = c.tabs[i].val let rss = if file in ["news", "index"]: extractFilename(rssUrl) else: "" + if '.' in file: continue exec(cmd % [c.nimArgs, file]) var temp = "web" / changeFileExt(file, "temp") var content: string @@ -418,20 +437,22 @@ proc main(c: var TConfigData) = quit("[Error] cannot write file: " & outfile) removeFile(temp) copyDir("web/assets", "web/upload/assets") - buildJS("web/upload") buildNewsRss(c, "web/upload") + +proc main(c: var TConfigData) = + buildWebsite(c) + buildJS("web/upload") buildAddDoc(c, "web/upload") buildDocSamples(c, "web/upload") buildDoc(c, "web/upload") buildDocSamples(c, "doc") buildDoc(c, "doc") - buildPdfDoc(c, "doc") var c: TConfigData initConfigData(c) parseCmdLine(c) parseIniFile(c) -when false: - buildPdfDoc(c, "doc") -else: - main(c) +case action +of actOnlyWebsite: buildWebsite(c) +of actPdf: buildPdfDoc(c, "doc") +of actAll: main(c) diff --git a/tools/website.tmpl b/tools/website.tmpl index f3cacdb64..bc3ed8e2c 100644 --- a/tools/website.tmpl +++ b/tools/website.tmpl @@ -1,88 +1,210 @@ #! stdtmpl | standard #proc generateHTMLPage(c: var TConfigData, currentTab, content, rss: string): string = # result = "" -<!doctype html> +<!DOCTYPE html> <html> - -<head> - <title>$c.projectTitle</title> - <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <link rel="stylesheet" type="text/css" href="assets/style.css" /> + <head> + <meta http-equiv="content-type" content="text/html; charset=utf-8"> + <title>$c.projectTitle</title> + <link rel="stylesheet" type="text/css" href="assets/style.css" /> + <link rel="shortcut icon" href="assets/images/favicon.ico"> #if len(rss) > 0: - <link href="$rss" title="Recent changes" type="application/atom+xml" rel="alternate"> - #end fi -</head> - -<body> - <div id="site"> - <!-- site_head --> - <div id="site_head"> - <div id="logo"></div> - </div> - - <!-- site_neck --> - <div id="site_neck"> + <link href="$rss" title="Recent changes" type="application/atom+xml" rel="alternate"> + #end if + </head> + <body> + <header id="head"> + <div class="page-layout tall"> + <div id="head-logo"></div> + <a id="head-logo-link" href="index.html"></a> + <nav id="head-links"> #for i in 0.. c.tabs.len-1: - # var name = c.tabs[i].key - # var t = c.tabs[i].val - #if currentTab == t: - <a class="active" - #else: - <a - #end if - href="${t}.html" title = "$c.projectName - $name">$name</a> + # let t = c.tabs[i].val + # if t != "index" and t != "community" and t != "news": + # let name = c.tabs[i].key + # if currentTab == t: + <a class="active" + # else: + <a + # end if + # if t.contains('.'): + href="${t}" title = "$c.projectName - $name">$name</a> + # else: + href="${t}.html" title = "$c.projectName - $name">$name</a> + # end if + # end if #end for - </div> + </nav> + </div> + </header> - <!-- site_body --> - <div id="site_body"> +# if currentTab == "index": + <section id="neck" class="home"> +# else: + <section id="neck"> +# end + <div class="page-layout tall"> + <div id="glow-arrow"></div> - <!-- sidebar_wrapper --> - <div id="sidebar_wrap"> - <div id="sidebar"> - <div id="sidebar_head"></div> - <h2>Latest News</h2> -# if len(c.ticker) > 0: - $c.ticker -# end if +# if currentTab == "index": + <div id="slideshow"> + <!-- slides --> + <div id="slide0" class="active"> + <h2><a name="why-should-i-be-excited">Why should I be excited?</a></h2> + <span class="desc">Nim is the only language that leverages automated proof technology to perform a <i>disjoint check</i> for your parallel code. Working on disjoint data means no locking is required and yet data races are impossible:</span><br><br> +<pre> +<span class="kwd">parallel</span>: +<span class="tab"> </span><span class="kwd">var</span> i = <span class="val">0</span> +<span class="tab"> </span><span class="kwd">while</span> i <= a.high: +<span class="tab"> <span class="tab"> </span></span></span><span class="kwd">spawn</span> f(a[i]) +<span class="tab"> <span class="tab"> </span></span></span><span class="kwd">spawn</span> f(a[i+<span class="val">1</span>]) +<span class="tab"> <span class="tab"> </span></span></span><span class="cmt"># ERROR: cannot prove a[i] is disjoint from a[i+1]</span> +<span class="tab"> <span class="tab"> </span></span></span><span class="cmt"># BUT: replace 'i += 1' with 'i += 2' and the code compiles!</span> +<span class="tab end"> <span class="tab end"> </span></span>i += <span class="val">1</span> +</pre> + </div> + <div id="slide1"> + <div> + <h2>Nim is simple..</h2> +<pre> +<span class="cmt"># compute average line length</span> +<span class="kwd">var</span> +<span class="tab"> </span>sum = <span class="val">0</span> +<span class="tab end"> </span>count = <span class="val">0</span> + +<span class="kwd">for</span> line <span class="kwd">in</span> stdin.lines: +<span class="tab"> </span>sum += line.len +<span class="tab end"> </span>count += <span class="val">1</span> + +echo(<span class="val">"Average line length: "</span>, + <span class="kwd">if</span> count > <span class="val">0</span>: sum / count <span class="kwd">else</span>: <span class="val">0</span>) +</pre> + </div> + <div> + <h2>..and type safe...</h2> +<pre> +<span class="cmt"># create and greet someone</span> +<span class="kwd">type</span> <span class="def">Person</span> = <span class="kwd">object</span> +<span class="tab"> </span>name: <span class="typ">string</span> +<span class="tab end"> </span>age: <span class="typ">int</span> + +<span class="kwd">proc</span> <span class="def">greet</span>(p: <span class="typ">Person</span>) = +<span class="tab"> </span>echo <span class="val">"Hi, I'm "</span>, p.name, <span class="val">"."</span> +<span class="tab end"> </span>echo <span class="val">"I am "</span>, p.age, <span class="val">" years old."</span> + +<span class="kwd">let</span> p = <span class="typ">Person</span>(name:<span class="val">"Jon"</span>, age:<span class="val">18</span>) +p.greet() <span class="cmt"># or greet(p)</span> +</pre> + </div> + </div> + <div id="slide2" class=""> + <div> + <h2>C FFI is easy in Nim..</h2> +<pre> +<span class="cmt"># declare a C procedure..</span> +<span class="kwd">proc</span> <span class="def">unsafeScanf</span>(f: <span class="typ">File</span>, s: <span class="typ">cstring</span>) +<span class="tab"> </span>{.varargs, +<span class="tab"> </span>importc: <span class="val">"fscanf"</span>, +<span class="tab end"> </span>header: <span class="val">"<stdio.h>"</span>.} + +<span class="cmt"># ..and use it...</span> +<span class="kwd">var</span> x: <span class="typ">cint</span> +stdin.unsafeScanf(<span class="val">"%d"</span>, <span class="kwd">addr</span> x) +</pre> + <p><span class="desc"><b>Compile and run with:</b><br> $ nim c -r example.nim</span></p> + </div> + <div> + <h2>..and DSLs are too...</h2> +<pre> +<span class="cmt"># a simple html server</span> +<span class="kwd">import</span> + jester, asyncdispatch, htmlgen + +<span class="kwd">routes</span>: +<span class="tab"> </span><span class="kwd">get</span> <span class="val">"/"</span>: +<span class="tab end"> <span class="tab end"> </span></span><span class="kwd">resp</span> h1(<span class="val">"Hello world"</span>) + +runForever() +</pre> + <p><span class="desc"><b>View in browser at:</b><br> localhost:5000</span></p> + </div> + </div> + </div> + <div id="slideshow-nav"> + <div id="slideControl0" onclick="slideshow_click(0)" class="active"></div> + <div id="slideControl1" onclick="slideshow_click(1)"></div> + <div id="slideControl2" onclick="slideshow_click(2)"></div> + </div> +# end + <aside id="sidebar"> # if len(c.links) > 0: - <h2>More Links</h2> + <h3>More Links</h3> + <div id="sidebar-links"> # for i in 0..c.links.len-1: - <a class="link" href="${c.links[i].val}" id="${c.links[i].id}">${c.links[i].key}</a> + <a href="${c.links[i].val}" id="${c.links[i].id}">${c.links[i].key}</a> # end for + </div> # end if - </div> - </div> - <!-- page --> - <div id="page"> - #if c.quotations.hasKey(currentTab): - <div class="quote-image"></div> - <p class="quote"> - ${c.quotations[currentTab].quote} - <br> - <b style="float: right">-- ${c.quotations[currentTab].author}</b> - </p> - <br/> - #end if - - $content - </div> - </div> - <!-- site_foot --> - <div id="site_foot"> - <div id="legal">Copyright © 2014 - Andreas Rumpf & Contributors - All rights reserved - <a href="http://reign-studios.com/philipwitte/">Design by Philip Witte</a></div> - </div> - </div> +# if len(c.ticker) > 0: + <h3 class="blue">Latest News</h3> + <div id="sidebar-news"> + $c.ticker + </div> +# end if + </aside> + </div> + </section> + + <section id="body"> + <div id="body-border"></div> + <div id="glow-line"></div> + <div class="page-layout"> + <article id="content" class="page"> + $content + </article> + </div> + </section> + + <!--- #foot ---> + <footer id="foot" class="home"> + <div class="page-layout tall"> + <div id="foot-links"> + <div> + <h4>Documentation</h4> + <a href="documentation.html">Stable Documentation</a> + <a href="learn.html">Learning Resources</a> + <!-- <a href="">Development Documentation</a> --> + <a href="https://github.com/Araq/Nimrod">Issues & Requests</a> + </div> + <div> + <h4>Community</h4> + <a href="http://forum.nim-lang.org">User Forum</a> + <a href="http://webchat.freenode.net/?channels=nim">Online IRC</a> + <a href="http://irclogs.nim-lang.org/">IRC Logs</a> + </div> + </div> + <div id="foot-legal"> + <h4>Written in Nim - Powered by <a href="https://github.com/dom96/jester">Jester</a></h4> + Web Design by <a href="http://reign-studios.net/philipwitte/">Philip Witte</a> & <a href="http://picheta.me/">Dominik Picheta</a><br> + Copyright © 2015 - <a href="http://nim-lang.org/blog/">Andreas Rumpf</a> & <a href="https://github.com/Araq/Nimrod/graphs/contributors">Contributors</a> + </div> + </div> + </footer> + +# if currentTab == "index": + <script src="assets/index.js"></script> +# end if +# if c.gaId != nil: <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - ga('create', 'UA-48159761-1', 'nim-lang.org'); + ga('create', '${c.gaId}', 'nim-lang.org'); ga('send', 'pageview'); - </script> +# end if </body> </html> |