summary refs log tree commit diff stats
path: root/tools/trimcc.nim
blob: 6271d2b9a6cf5c9310100b1b8368ea773d068512 (plain) (blame)
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
# Trim C compiler installation to a minimum

import strutils, os

proc newName(f: string): string =
  var (dir, name, ext) = splitFile(f)
  return dir / "trim_" & name & ext

proc walker(dir: string) = 
  for kind, path in walkDir(dir):
    case kind
    of pcFile:
      moveFile(dest=newName(path), source=path)
      # test if installation still works:
      if execShellCmd(r"nimrod c --force_build koch") == 0:
        echo "Optional: ", path
        removeFile(newName(path))
      else:
        echo "Required: ", path
        # copy back:
        moveFile(dest=path, sourc=newName(path))
    of pcDir:
      walker(path)
    else: discard

if paramCount() == 1:
  walker(paramStr(1))
else:
  quit "Usage: trimcc c_compiler_directory"