summary refs log tree commit diff stats
path: root/compiler/importer.nim
blob: c4861df7f43347f8e036d455402beea58d0287b9 (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
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
#
#
#           The Nim Compiler
#        (c) Copyright 2013 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# This module implements the symbol importing mechanism.

import
  intsets, strutils, os, ast, astalgo, msgs, options, idents, rodread, lookups,
  semdata, passes, renderer

proc evalImport*(c: PContext, n: PNode): PNode
proc evalFrom*(c: PContext, n: PNode): PNode

proc getModuleName*(n: PNode): string =
  # This returns a short relative module name without the nim extension
  # e.g. like "system", "importer" or "somepath/module"
  # The proc won't perform any checks that the path is actually valid
  case n.kind
  of nkStrLit, nkRStrLit, nkTripleStrLit:
    try:
      result = pathSubs(n.strVal, n.info.toFullPath().splitFile().dir)
    except ValueError:
      localError(n.info, "invalid path: " & n.strVal)
      result = n.strVal
  of nkIdent:
    result = n.ident.s
  of nkSym:
    result = n.sym.name.s
  of nkInfix, nkPrefix:
    if n.sons[0].kind == nkIdent and n.sons[0].ident.id == getIdent("as").id:
      # XXX hack ahead:
      n.kind = nkImportAs
      n.sons[0] = n.sons[1]
      n.sons[1] = n.sons[2]
      n.sons.setLen(2)
      return getModuleName(n.sons[0])
    # hacky way to implement 'x / y /../ z':
    result = renderTree(n, {renderNoComments}).replace(" ")
  of nkDotExpr:
    result = renderTree(n, {renderNoComments}).replace(".", "/")
  of nkImportAs:
    result = getModuleName(n.sons[0])
  else:
    localError(n.info, errGenerated, "invalid module name: '$1'" % n.renderTree)
    result = ""

proc checkModuleName*(n: PNode; doLocalError=true): int32 =
  # This returns the full canonical path for a given module import
  let modulename = n.getModuleName
  let fullPath = findModule(modulename, n.info.toFullPath)
  if fullPath.len == 0:
    if doLocalError:
      localError(n.info, errCannotOpenFile, modulename)
    result = InvalidFileIDX
  else:
    result = fullPath.fileInfoIdx

proc rawImportSymbol(c: PContext, s: PSym) =
  # This does not handle stubs, because otherwise loading on demand would be
  # pointless in practice. So importing stubs is fine here!
  # check if we have already a symbol of the same name:
  var check = strTableGet(c.importTable.symbols, s.name)
  if check != nil and check.id != s.id:
    if s.kind notin OverloadableSyms:
      # s and check need to be qualified:
      incl(c.ambiguousSymbols, s.id)
      incl(c.ambiguousSymbols, check.id)
  # thanks to 'export' feature, it could be we import the same symbol from
  # multiple sources, so we need to call 'StrTableAdd' here:
  strTableAdd(c.importTable.symbols, s)
  if s.kind == skType:
    var etyp = s.typ
    if etyp.kind in {tyBool, tyEnum} and sfPure notin s.flags:
      for j in countup(0, sonsLen(etyp.n) - 1):
        var e = etyp.n.sons[j].sym
        if e.kind != skEnumField:
          internalError(s.info, "rawImportSymbol")
          # BUGFIX: because of aliases for enums the symbol may already
          # have been put into the symbol table
          # BUGFIX: but only iff they are the same symbols!
        var it: TIdentIter
        check = initIdentIter(it, c.importTable.symbols, e.name)
        while check != nil:
          if check.id == e.id:
            e = nil
            break
          check = nextIdentIter(it, c.importTable.symbols)
        if e != nil:
          rawImportSymbol(c, e)
  else:
    # rodgen assures that converters and patterns are no stubs
    if s.kind == skConverter: addConverter(c, s)
    if hasPattern(s): addPattern(c, s)

proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
  let ident = lookups.considerQuotedIdent(n)
  let s = strTableGet(fromMod.tab, ident)
  if s == nil:
    errorUndeclaredIdentifier(c, n.info, ident.s)
  else:
    if s.kind == skStub: loadStub(s)
    if s.kind notin ExportableSymKinds:
      internalError(n.info, "importSymbol: 2")
    # for an enumeration we have to add all identifiers
    case s.kind
    of skProcKinds:
      # for a overloadable syms add all overloaded routines
      var it: TIdentIter
      var e = initIdentIter(it, fromMod.tab, s.name)
      while e != nil:
        if e.name.id != s.name.id: internalError(n.info, "importSymbol: 3")
        rawImportSymbol(c, e)
        e = nextIdentIter(it, fromMod.tab)
    else: rawImportSymbol(c, s)

proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: IntSet) =
  var i: TTabIter
  var s = initTabIter(i, fromMod.tab)
  while s != nil:
    if s.kind != skModule:
      if s.kind != skEnumField:
        if s.kind notin ExportableSymKinds:
          internalError(s.info, "importAllSymbols: " & $s.kind)
        if exceptSet.isNil or s.name.id notin exceptSet:
          rawImportSymbol(c, s)
    s = nextIter(i, fromMod.tab)

proc importAllSymbols*(c: PContext, fromMod: PSym) =
  var exceptSet: IntSet
  importAllSymbolsExcept(c, fromMod, exceptSet)

proc importForwarded(c: PContext, n: PNode, exceptSet: IntSet) =
  if n.isNil: return
  case n.kind
  of nkExportStmt:
    for a in n:
      assert a.kind == nkSym
      let s = a.sym
      if s.kind == skModule:
        importAllSymbolsExcept(c, s, exceptSet)
      elif exceptSet.isNil or s.name.id notin exceptSet:
        rawImportSymbol(c, s)
  of nkExportExceptStmt:
    localError(n.info, errGenerated, "'export except' not implemented")
  else:
    for i in 0..safeLen(n)-1:
      importForwarded(c, n.sons[i], exceptSet)

proc importModuleAs(n: PNode, realModule: PSym): PSym =
  result = realModule
  if n.kind != nkImportAs: discard
  elif n.len != 2 or n.sons[1].kind != nkIdent:
    localError(n.info, errGenerated, "module alias must be an identifier")
  elif n.sons[1].ident.id != realModule.name.id:
    # some misguided guy will write 'import abc.foo as foo' ...
    result = createModuleAlias(realModule, n.sons[1].ident, realModule.info)

proc myImportModule(c: PContext, n: PNode): PSym =
  var f = checkModuleName(n)
  if f != InvalidFileIDX:
    let L = c.graph.importStack.len
    let recursion = c.graph.importStack.find(f)
    c.graph.importStack.add f
    #echo "adding ", toFullPath(f), " at ", L+1
    if recursion >= 0:
      var err = ""
      for i in countup(recursion, L-1):
        if i > recursion: err.add "\n"
        err.add toFullPath(c.graph.importStack[i]) & " imports " &
                toFullPath(c.graph.importStack[i+1])
      c.recursiveDep = err
    result = importModuleAs(n, gImportModule(c.graph, c.module, f, c.cache))
    #echo "set back to ", L
    c.graph.importStack.setLen(L)
    # we cannot perform this check reliably because of
    # test: modules/import_in_config)
    when true:
      if result.info.fileIndex == c.module.info.fileIndex and
          result.info.fileIndex == n.info.fileIndex:
        localError(n.info, errGenerated, "A module cannot import itself")
    if sfDeprecated in result.flags:
      message(n.info, warnDeprecated, result.name.s)
    #suggestSym(n.info, result, false)

proc impMod(c: PContext; it: PNode) =
  let m = myImportModule(c, it)
  if m != nil:
    var emptySet: IntSet
    # ``addDecl`` needs to be done before ``importAllSymbols``!
    addDecl(c, m, it.info) # add symbol to symbol table of module
    importAllSymbolsExcept(c, m, emptySet)
    #importForwarded(c, m.ast, emptySet)

proc evalImport(c: PContext, n: PNode): PNode =
  result = n
  for i in countup(0, sonsLen(n) - 1):
    let it = n.sons[i]
    if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
      let sep = renderTree(it.sons[0], {renderNoComments})
      let dir = renderTree(it.sons[1], {renderNoComments})
      for x in it[2]:
        let f = renderTree(x, {renderNoComments})
        let a = newStrNode(nkStrLit, (dir & sep & f).replace(" "))
        a.info = it.info
        impMod(c, a)
    else:
      impMod(c, it)

proc evalFrom(c: PContext, n: PNode): PNode =
  result = n
  checkMinSonsLen(n, 2)
  var m = myImportModule(c, n.sons[0])
  if m != nil:
    n.sons[0] = newSymNode(m)
    addDecl(c, m, n.info)               # add symbol to symbol table of module
    for i in countup(1, sonsLen(n) - 1):
      if n.sons[i].kind != nkNilLit:
        importSymbol(c, n.sons[i], m)

proc evalImportExcept*(c: PContext, n: PNode): PNode =
  result = n
  checkMinSonsLen(n, 2)
  var m = myImportModule(c, n.sons[0])
  if m != nil:
    n.sons[0] = newSymNode(m)
    addDecl(c, m, n.info)               # add symbol to symbol table of module
    var exceptSet = initIntSet()
    for i in countup(1, sonsLen(n) - 1):
      let ident = lookups.considerQuotedIdent(n.sons[i])
      exceptSet.incl(ident.id)
    importAllSymbolsExcept(c, m, exceptSet)
    #importForwarded(c, m.ast, exceptSet)
re>

                                 

                       

                                 
                               
 
                                             

                                             

                                 
                                          
 

             
                                    
                          

                              
               
                                                                 
                                                                     
                                                                        
                           
 
               
        
                                          
                                                                   
                                   
                                             





                                                                             
                                                                          

                                                                               
                                                                                 
                                          






                                                                                     
                                                                                  
                                                                        
          
 
                 
          
                                           
                                   
                                               
                                                
                                               

                                                 





                                                     




                                                          
                                                           
                                             



                                   
NIMC ?= nim c
OBJDIR ?= .obj
OUTDIR ?= target
# These paths are quoted in recipes.
PREFIX ?= /usr/local
MANPREFIX ?= $(PREFIX)/share/man
MANPREFIX1 ?= $(MANPREFIX)/man1
MANPREFIX5 ?= $(MANPREFIX)/man5
TARGET ?= release
# This must be single-quoted, because it is not a real shell substitution.
# The default setting is at {the binary's path}/../libexec/chawan.
# You may override it with any path if your system does not have a libexec
# directory, but make sure to surround it with quotes if it contains spaces.
# (This way, the cha binary can be directly executed without installation.)
LIBEXECDIR ?= '$${%CHA_BIN_DIR}/../libexec/chawan'
# If overridden, take libexecdir that was specified.
# Otherwise, just install to libexec/chawan.
ifeq ($(LIBEXECDIR),'$${%CHA_BIN_DIR}/../libexec/chawan')
LIBEXECDIR_CHAWAN = "$(DESTDIR)$(PREFIX)/libexec/chawan"
else
LIBEXECDIR_CHAWAN = $(LIBEXECDIR)/chawan
endif

# These paths are quoted in recipes.
OUTDIR_TARGET = $(OUTDIR)/$(TARGET)
OUTDIR_BIN = $(OUTDIR_TARGET)/bin
OUTDIR_LIBEXEC = $(OUTDIR_TARGET)/libexec/chawan
OUTDIR_CGI_BIN = $(OUTDIR_LIBEXEC)/cgi-bin

# Nim compiler flags
ifeq ($(TARGET),debug)
FLAGS += -d:debug --debugger:native
else ifeq ($(TARGET),release)
FLAGS += -d:release -d:strip -d:lto
else ifeq ($(TARGET),release0)
FLAGS += -d:release --stacktrace:on
else ifeq ($(TARGET),release1)
FLAGS += -d:release --debugger:native
endif

.PHONY: all
all: $(OUTDIR_BIN)/cha $(OUTDIR_CGI_BIN)/http \
	$(OUTDIR_CGI_BIN)/gmifetch $(OUTDIR_LIBEXEC)/gmi2html \
	$(OUTDIR_CGI_BIN)/gopher $(OUTDIR_LIBEXEC)/gopher2html \
	$(OUTDIR_CGI_BIN)/cha-finger $(OUTDIR_CGI_BIN)/about \
	$(OUTDIR_CGI_BIN)/data $(OUTDIR_CGI_BIN)/file $(OUTDIR_CGI_BIN)/ftp

$(OUTDIR_BIN)/cha: lib/libquickjs.a src/*.nim src/**/*.nim src/**/*.c res/* res/**/*
	@mkdir -p "$(OUTDIR)/$(TARGET)/bin"
	$(NIMC) --nimcache:"$(OBJDIR)/$(TARGET)/cha" -d:libexecPath=$(LIBEXECDIR) \
		$(FLAGS) -o:"$(OUTDIR_BIN)/cha" src/main.nim
	ln -sf "$(OUTDIR)/$(TARGET)/bin/cha" cha

$(OUTDIR_LIBEXEC)/gopher2html: adapter/format/gopher2html.nim \
		src/utils/twtstr.nim adapter/gophertypes.nim
	@mkdir -p "$(OUTDIR_LIBEXEC)"
	$(NIMC) $(FLAGS) -o:"$(OUTDIR_LIBEXEC)/gopher2html" \
		adapter/format/gopher2html.nim

GMIFETCH_CFLAGS = -Wall -Wextra -std=c89 -pedantic -lcrypto -lssl -g -O3
$(OUTDIR_CGI_BIN)/gmifetch: adapter/protocol/gmifetch.c
	@mkdir -p "$(OUTDIR_CGI_BIN)"
	$(CC) $(GMIFETCH_CFLAGS) adapter/protocol/gmifetch.c -o "$(OUTDIR_CGI_BIN)/gmifetch"

GMI2HTML_CFLAGS = -Wall -Wextra -std=c89 -pedantic -g -O3
$(OUTDIR_LIBEXEC)/gmi2html: adapter/format/gmi2html.c
	@mkdir -p "$(OUTDIR_LIBEXEC)"
	$(CC) $(GMI2HTML_CFLAGS) adapter/format/gmi2html.c -o "$(OUTDIR_LIBEXEC)/gmi2html"

$(OUTDIR_CGI_BIN)/cha-finger: adapter/protocol/cha-finger
	@mkdir -p $(OUTDIR_CGI_BIN)
	cp adapter/protocol/cha-finger $(OUTDIR_CGI_BIN)

$(OUTDIR_CGI_BIN)/http: adapter/protocol/http.nim adapter/protocol/curlwrap.nim \
		adapter/protocol/curlerrors.nim adapter/protocol/curl.nim \
		src/utils/twtstr.nim
	@mkdir -p "$(OUTDIR_CGI_BIN)"
	$(NIMC) $(FLAGS) --nimcache:"$(OBJDIR)/$(TARGET)/http" -d:curlLibName:$(CURLLIBNAME) \
		-o:"$(OUTDIR_CGI_BIN)/http" adapter/protocol/http.nim

$(OUTDIR_CGI_BIN)/about: adapter/protocol/about.nim
	@mkdir -p "$(OUTDIR_CGI_BIN)"
	$(NIMC) $(FLAGS) --nimcache:"$(OBJDIR)/$(TARGET)/about" -o:"$(OUTDIR_CGI_BIN)/about" adapter/protocol/about.nim

$(OUTDIR_CGI_BIN)/data: adapter/protocol/data.nim src/utils/twtstr.nim
	@mkdir -p "$(OUTDIR_CGI_BIN)"
	$(NIMC) $(FLAGS) --nimcache:"$(OBJDIR)/$(TARGET)/data" -o:"$(OUTDIR_CGI_BIN)/data" adapter/protocol/data.nim

$(OUTDIR_CGI_BIN)/file: adapter/protocol/file.nim adapter/protocol/dirlist.nim \
		src/utils/twtstr.nim src/utils/strwidth.nim src/data/charwidth.nim \
		res/map/EastAsianWidth.txt src/loader/connecterror.nim
	@mkdir -p "$(OUTDIR_CGI_BIN)"
	$(NIMC) $(FLAGS) --nimcache:"$(OBJDIR)/$(TARGET)/file" -o:"$(OUTDIR_CGI_BIN)/file" adapter/protocol/file.nim

$(OUTDIR_CGI_BIN)/ftp: adapter/protocol/ftp.nim adapter/protocol/dirlist.nim \
		src/utils/twtstr.nim src/utils/strwidth.nim src/data/charwidth.nim \
		res/map/EastAsianWidth.txt src/loader/connecterror.nim \
		src/types/opt.nim adapter/protocol/curl.nim
	@mkdir -p "$(OUTDIR_CGI_BIN)"
	$(NIMC) $(FLAGS) -d:curlLibName:$(CURLLIBNAME) --nimcache:"$(OBJDIR)/$(TARGET)/ftp" \
		-o:"$(OUTDIR_CGI_BIN)/ftp" adapter/protocol/ftp.nim

$(OUTDIR_CGI_BIN)/gopher: adapter/protocol/gopher.nim adapter/protocol/curlwrap.nim \
		adapter/protocol/curlerrors.nim adapter/gophertypes.nim \
		adapter/protocol/curl.nim src/loader/connecterror.nim \
		src/utils/twtstr.nim
	@mkdir -p "$(OUTDIR_CGI_BIN)"
	$(NIMC) $(FLAGS) -d:curlLibName:$(CURLLIBNAME) --nimcache:"$(OBJDIR)/$(TARGET)/gopher" \
		-o:"$(OUTDIR_CGI_BIN)/gopher" adapter/protocol/gopher.nim

CFLAGS = -fwrapv -g -Wall -O2 -DCONFIG_VERSION=\"$(shell cat lib/quickjs/VERSION)\"
QJSOBJ = $(OBJDIR)/quickjs

# Dependencies
$(QJSOBJ)/cutils.o: lib/quickjs/cutils.h
$(QJSOBJ)/libbf.o: lib/quickjs/cutils.h lib/quickjs/libbf.h
$(QJSOBJ)/libregexp.o: lib/quickjs/cutils.h lib/quickjs/libregexp.h \
	lib/quickjs/libunicode.h lib/quickjs/libregexp-opcode.h
$(QJSOBJ)/libunicode.o: lib/quickjs/cutils.h lib/quickjs/libunicode.h \
	lib/quickjs/libunicode-table.h
$(QJSOBJ)/quickjs.o: lib/quickjs/cutils.h lib/quickjs/list.h \
	lib/quickjs/quickjs.h lib/quickjs/libregexp.h \
	lib/quickjs/libunicode.h lib/quickjs/libbf.h \
	lib/quickjs/quickjs-atom.h lib/quickjs/quickjs-opcode.h

$(QJSOBJ)/%.o: lib/quickjs/%.c
	@mkdir -p "$(QJSOBJ)"
	$(CC) $(CFLAGS) -c -o $@ $<

lib/libquickjs.a: $(QJSOBJ)/quickjs.o $(QJSOBJ)/libregexp.o \
		$(QJSOBJ)/libunicode.o $(QJSOBJ)/cutils.o \
		$(QJSOBJ)/libbf.o
	@mkdir -p "$(QJSOBJ)"
	$(AR) rcs $@ $^

$(OBJDIR)/man/cha-%.md: doc/%.md
	@mkdir -p "$(OBJDIR)/man"
	./md2manpreproc $< > $@

$(OBJDIR)/man/cha-%.5: $(OBJDIR)/man/cha-%.md
	pandoc --standalone --to man $< -o $@

$(OBJDIR)/man/cha.1: doc/cha.1
	@mkdir -p "$(OBJDIR)/man"
	cp doc/cha.1 "$(OBJDIR)/man/cha.1"

.PHONY: clean
clean:
	rm -rf "$(OBJDIR)/$(TARGET)"
	rm -rf "$(QJSOBJ)"
	rm -f lib/libquickjs.a

.PHONY: manpage
manpage: $(OBJDIR)/man/cha-config.5 $(OBJDIR)/man/cha-mailcap.5 \
	$(OBJDIR)/man/cha-mime.types.5 $(OBJDIR)/man/cha-localcgi.5 \
	$(OBJDIR)/man/cha-urimethodmap.5 $(OBJDIR)/man/cha-protocols.5 \
	$(OBJDIR)/man/cha.1

.PHONY: install
install:
	mkdir -p "$(DESTDIR)$(PREFIX)/bin"
	install -m755 "$(OUTDIR_BIN)/cha" "$(DESTDIR)$(PREFIX)/bin"
	@# intentionally not quoted
	mkdir -p $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_CGI_BIN)/http" $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_CGI_BIN)/about" $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_CGI_BIN)/data" $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_CGI_BIN)/file" $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_CGI_BIN)/ftp" $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_CGI_BIN)/gopher" $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_LIBEXEC)/gopher2html" $(LIBEXECDIR_CHAWAN)
	install -m755 "$(OUTDIR_LIBEXEC)/gmi2html" $(LIBEXECDIR_CHAWAN)
	install -m755 "$(OUTDIR_CGI_BIN)/gmifetch" $(LIBEXECDIR_CHAWAN)/cgi-bin
	install -m755 "$(OUTDIR_CGI_BIN)/cha-finger" $(LIBEXECDIR_CHAWAN)/cgi-bin
	if test -d "$(OBJDIR)/man"; then \
	mkdir -p "$(DESTDIR)$(MANPREFIX5)"; \
	mkdir -p "$(DESTDIR)$(MANPREFIX1)"; \
	install -m644 "$(OBJDIR)/man/cha-config.5" "$(DESTDIR)$(MANPREFIX5)"; \
	install -m644 "$(OBJDIR)/man/cha-mailcap.5" "$(DESTDIR)$(MANPREFIX5)"; \
	install -m644 "$(OBJDIR)/man/cha-mime.types.5" "$(DESTDIR)$(MANPREFIX5)"; \
	install -m644 "$(OBJDIR)/man/cha-localcgi.5" "$(DESTDIR)$(MANPREFIX5)"; \
	install -m644 "$(OBJDIR)/man/cha-urimethodmap.5" "$(DESTDIR)$(MANPREFIX5)"; \
	install -m644 "$(OBJDIR)/man/cha-protocols.5" "$(DESTDIR)$(MANPREFIX5)"; \
	install -m644 "$(OBJDIR)/man/cha.1" "$(DESTDIR)$(MANPREFIX1)"; \
	fi

.PHONY: uninstall
uninstall:
	rm -f "$(DESTDIR)$(PREFIX)/bin/cha"
	@# intentionally not quoted
	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/http
	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/about
	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/data
	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/ftp
	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/gopher
	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/gmifetch
	rm -f $(LIBEXECDIR_CHAWAN)/cgi-bin/cha-finger
	rmdir $(LIBEXECDIR_CHAWAN)/cgi-bin || true
	rm -f $(LIBEXECDIR_CHAWAN)/gopher2html
	rm -f $(LIBEXECDIR_CHAWAN)/gmi2html
	rmdir $(LIBEXECDIR_CHAWAN) || true
	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-config.5"
	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-mailcap.5"
	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-mime.types.5"
	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-localcgi.5"
	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-urimethodmap.5"
	rm -f "$(DESTDIR)$(MANPREFIX5)/cha-cha-protocols.5"
	rm -f "$(DESTDIR)$(MANPREFIX1)/cha.1"

.PHONY: submodule
submodule:
	git submodule update --init