about summary refs log tree commit diff stats
path: root/Makefile
Commit message (Expand)AuthorAgeFilesLines
* thx to Toni Lainsonarg@suckless.org2007-10-191-2/+2
* removed dwm.h, just include C-files in config.h if you extend dwm, that's sim...arg@suckless.org2007-10-181-2/+2
* recreated dwm.hAnselm R. Garbe2007-10-111-1/+1
* renamed config.h into config.def.h, config.h will be created if not present, ...Anselm R. Garbe2007-09-231-1/+5
* made all stuff non-static - so you can choose wether to use dwm the static or...arg@suckless.org2007-09-171-1/+1
* micromizing dwm step 1Anselm R. Garbe2007-09-151-3/+3
* moved bar-related stuff to bar.c (merged draw.c into that)Anselm R. Garbe2007-09-151-1/+1
* renamed config.default.h into config.hAnselm R. Garbe2007-09-151-5/+1
* dist target only needs to add config.default.hAnselm R. Garbe2007-09-151-1/+1
* added screen.c, removed layout.c and tag.cAnselm R. Garbe2007-08-191-1/+1
* fififiAnselm R. Garbe2007-08-151-1/+1
* separated layout-specific stuff into separate .h and .c files which are inclu...Anselm R. Garbe2007-08-111-1/+1
* removed strip, added -s to LDFLAGSAnselm R. Garbe2007-05-151-1/+0
* yet another fix of copyright compactisitionAnselm R. Garbe2007-04-131-1/+1
* fixed quoting and a comment 3.6Anselm R. Garbe2007-02-211-1/+1
* added draw.c again (except getcolor and setfont which are helpers in main.c)Anselm R. Garbe2007-02-201-1/+1
* split screen.c into layout.c and tag.c (because the view is an implicit mixtu...Anselm R. Garbe2007-02-201-1/+1
* draw.c is useless (belongs to main.c now)Anselm R. Garbe2007-02-191-1/+1
* renamed view.c into screen.cAnselm R. Garbe2007-02-191-1/+1
* merged tag.c, view.c and tile.c to manage.cAnselm R. Garbe2007-02-191-1/+1
* introduced tile.c, some refactoring of functionsAnselm R. Garbe2007-02-191-1/+1
* fixed copyright notice in MakefileAnselm R. Garbe2007-02-081-1/+1
* got rid of LD (inspired by JGs patch to wmii)Anselm R. Garbe2007-02-051-3/+2
* next version will contain updated copyright noticearg@mig292007-01-021-1/+1
* separated several functions into view.cAnselm R. Garbe2006-08-221-1/+1
* removed finished messageAnselm R.Garbe2006-08-141-1/+0
* applied Sanders LD and resize patchesAnselm R.Garbe2006-08-141-1/+2
* applied Sanders tiny patchesAnselm R.Garbe2006-08-081-1/+1
* typo fixarg@10ksloc.org2006-08-071-1/+1
* applied Sanders man page/Makefile patcharg@10ksloc.org2006-08-071-1/+1
* added stripping to dwm target in Makefilearg@10ksloc.org2006-08-071-0/+1
* removed CONFIGarg@10ksloc.org2006-08-031-3/+2
* make config.h not a time dependencearg@10ksloc.org2006-08-031-1/+1
* removed rm config.h from cleanarg@10ksloc.org2006-08-031-1/+1
* added gmake compliancearg@10ksloc.org2006-08-031-2/+2
* applied Jukka's diffarg@10ksloc.org2006-08-031-4/+5
* applied Sanders Makefile patcharg@10ksloc.org2006-08-031-26/+20
* using SRC instead of *.carg@10ksloc.org2006-08-031-1/+1
* changed the files included in make distarg@10ksloc.org2006-08-031-1/+2
* applied Sanders doc changes, added a PHONY line and changed the output of con...arg@10ksloc.org2006-08-031-1/+4
* implemented the idea presented by Sander for dwm targetarg@10ksloc.org2006-08-021-1/+4
* applied Sanders patchesarg@10ksloc.org2006-08-011-2/+1
* makefile now sets permissions for executables and man pagesarg@10ksloc.org2006-07-201-0/+6
* simplified MakefileAnselm R. Garbe2006-07-171-2/+2
* rearranged several stuffAnselm R. Garbe2006-07-151-1/+1
* rearrangedAnselm R. Garbe2006-07-141-1/+1
* draw bar on exposure ;)Anselm R. Garbe2006-07-141-1/+1
* prep 0.1 0.1Anselm R. Garbe2006-07-141-1/+1
* implemented bar for dwm (I miss status text), I plan that status text is read...Anselm R. Garbe2006-07-141-1/+1
* changed default colorsAnselm R. Garbe2006-07-131-2/+2
fa137544ebbb915ce2ed5da9afae4375ef'>61e57cfa1 ^
1dc362dcd ^
594674797 ^
1dc362dcd ^
9b465a236 ^
1dc362dcd ^

61e57cfa1 ^
90fa64501 ^










86556ebfd ^
61e57cfa1 ^
86556ebfd ^
c98696d74 ^
61e57cfa1 ^
1dc362dcd ^




61e57cfa1 ^
1dc362dcd ^
61e57cfa1 ^
1dc362dcd ^
86556ebfd ^


010067f3c ^



bea07a2c5 ^

9b465a236 ^








3999e3be5 ^
bea07a2c5 ^
796aafe7e ^









bea07a2c5 ^
9b465a236 ^
3999e3be5 ^
9b465a236 ^
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

 
                            





                                                   
                                                                           
 
                                                                  
                      
 
                                                                    

                                         
 
    
                            
 
                                          
 
                                        






                                                          



                                          
                                              













                                                               
                                        











                                        
 






                                                                            

                                                                                
                  
                                       




                   




                                
                                

                                       
                                                                                        
                                     





                                                          
                                                        
 
                                                   
                                  
                                                        

             
                                                                 










                                                                                
                                                      
                                       
                                              
 
                                                                




                                                     
                                         
                           
                                
 


                                                                       



                                     

                  








                                                                         
                           
                           









                                                     
 
                              
                                                            
 
#
#
#           The Nim Compiler
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## Implements some helper procs for Nimble (Nim's package manager) support.

import parseutils, strutils, strtabs, os, options, msgs, sequtils,
  lineinfos, pathutils

proc addPath*(conf: ConfigRef; path: AbsoluteDir, info: TLineInfo) =
  if not conf.searchPaths.contains(path):
    conf.searchPaths.insert(path, 0)

type
  Version* = distinct string

proc `$`*(ver: Version): string {.borrow.}

proc newVersion*(ver: string): Version =
  doAssert(ver.len == 0 or ver[0] in {'#', '\0'} + Digits,
           "Wrong version: " & ver)
  return Version(ver)

proc isSpecial(ver: Version): bool =
  return ($ver).len > 0 and ($ver)[0] == '#'

proc isValidVersion(v: string): bool =
  if v.len > 0:
    if v[0] in {'#'} + Digits: return true

proc `<`*(ver: Version, ver2: Version): bool =
  ## This is synced from Nimble's version module.

  # Handling for special versions such as "#head" or "#branch".
  if ver.isSpecial or ver2.isSpecial:
    if ver2.isSpecial and ($ver2).normalize == "#head":
      return ($ver).normalize != "#head"

    if not ver2.isSpecial:
      # `#aa111 < 1.1`
      return ($ver).normalize != "#head"

  # Handling for normal versions such as "0.1.0" or "1.0".
  var sVer = string(ver).split('.')
  var sVer2 = string(ver2).split('.')
  for i in 0..<max(sVer.len, sVer2.len):
    var sVerI = 0
    if i < sVer.len:
      discard parseInt(sVer[i], sVerI)
    var sVerI2 = 0
    if i < sVer2.len:
      discard parseInt(sVer2[i], sVerI2)
    if sVerI < sVerI2:
      return true
    elif sVerI == sVerI2:
      discard
    else:
      return false

proc getPathVersion*(p: string): tuple[name, version: string] =
  ## Splits path ``p`` in the format ``/home/user/.nimble/pkgs/package-0.1``
  ## into ``(/home/user/.nimble/pkgs/package, 0.1)``
  result.name = ""
  result.version = ""

  const specialSeparator = "-#"
  let last = p.rfind(p.lastPathPart) # the index where the last path part begins
  var sepIdx = p.find(specialSeparator, start = last)
  if sepIdx == -1:
    sepIdx = p.rfind('-', start = last)

  if sepIdx == -1:
    result.name = p
    return

  for i in sepIdx..<p.len:
    if p[i] in {DirSep, AltSep}:
      result.name = p
      return

  result.name = p[0..sepIdx - 1]
  result.version = p.substr(sepIdx + 1)

proc addPackage(conf: ConfigRef; packages: StringTableRef, p: string; info: TLineInfo) =
  let (name, ver) = getPathVersion(p)
  if isValidVersion(ver):
    let version = newVersion(ver)
    if packages.getOrDefault(name).newVersion < version or
      (not packages.hasKey(name)):
      packages[name] = $version
  else:
    localError(conf, info, "invalid package name: " & p)

iterator chosen(packages: StringTableRef): string =
  for key, val in pairs(packages):
    let res = if val.len == 0: key else: key & '-' & val
    yield res

proc addNimblePath(conf: ConfigRef; p: string, info: TLineInfo) =
  var path = p
  let nimbleLinks = toSeq(walkPattern(p / "*.nimble-link"))
  if nimbleLinks.len > 0:
    # If the user has more than one .nimble-link file then... we just ignore it.
    # Spec for these files is available in Nimble's readme:
    # https://github.com/nim-lang/nimble#nimble-link
    let nimbleLinkLines = readFile(nimbleLinks[0]).splitLines()
    path = nimbleLinkLines[1]
    if not path.isAbsolute():
      path = p / path

  if not contains(conf.searchPaths, AbsoluteDir path):
    message(conf, info, hintPath, path)
    conf.lazyPaths.insert(AbsoluteDir path, 0)

proc addPathRec(conf: ConfigRef; dir: string, info: TLineInfo) =
  var packages = newStringTable(modeStyleInsensitive)
  var pos = dir.len-1
  if dir[pos] in {DirSep, AltSep}: inc(pos)
  for k,p in os.walkDir(dir):
    if k == pcDir and p[pos] != '.':
      addPackage(conf, packages, p, info)
  for p in packages.chosen:
    addNimblePath(conf, p, info)

proc nimblePath*(conf: ConfigRef; path: AbsoluteDir, info: TLineInfo) =
  addPathRec(conf, path.string, info)
  addNimblePath(conf, path.string, info)
  let i = conf.nimblePaths.find(path)
  if i != -1:
    conf.nimblePaths.delete(i)
  conf.nimblePaths.insert(path, 0)

when isMainModule:
  proc v(s: string): Version = s.newVersion
  # #head is special in the sense that it's assumed to always be newest.
  doAssert v"1.0" < v"#head"
  doAssert v"1.0" < v"1.1"
  doAssert v"1.0.1" < v"1.1"
  doAssert v"1" < v"1.1"
  doAssert v"#aaaqwe" < v"1.1" # We cannot assume that a branch is newer.
  doAssert v"#a111" < v"#head"

  let conf = newConfigRef()
  var rr = newStringTable()
  addPackage conf, rr, "irc-#a111", unknownLineInfo
  addPackage conf, rr, "irc-#head", unknownLineInfo
  addPackage conf, rr, "irc-0.1.0", unknownLineInfo
  #addPackage conf, rr, "irc", unknownLineInfo
  #addPackage conf, rr, "another", unknownLineInfo
  addPackage conf, rr, "another-0.1", unknownLineInfo

  addPackage conf, rr, "ab-0.1.3", unknownLineInfo
  addPackage conf, rr, "ab-0.1", unknownLineInfo
  addPackage conf, rr, "justone-1.0", unknownLineInfo

  doAssert toSeq(rr.chosen) ==
    @["irc-#head", "another-0.1", "ab-0.1.3", "justone-1.0"]