File: GNUmakefile

package info (click to toggle)
darcs 2.0.2-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,400 kB
  • ctags: 1,048
  • sloc: haskell: 24,937; perl: 9,736; sh: 3,369; ansic: 1,913; makefile: 17; xml: 14
file content (524 lines) | stat: -rw-r--r-- 17,429 bytes parent folder | download
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#
# Build darcs
#
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifneq (config,$(MAKECMDGOALS))
include autoconf.mk
endif
endif

ifneq (,$(RTSFLAGS))
GHCFLAGS += +RTS $(RTSFLAGS) -RTS
endif

GHCFLAGS += -Wall -Werror -I. -I./src -i./src
GHCFLAGS_src__Darcs__Commands__Record.o = $(filter-out -auto-all,$(GHCFLAGS))
GHCFLAGS_src__Darcs__SelectChanges.o = $(filter-out -auto-all,$(GHCFLAGS))
GHCFLAGS_src__SHA1.o = $(GHCFLAGS) -no-auto-all -funfolding-use-threshold20
ifeq ($(HAVE_CURSES),True)
GHCFLAGS_src__Darcs__External.o = $(GHCFLAGS)
ifeq ($(HAVE_TERMIO_H),True)
# This termio bit is a grim hack for Solaris 10 (at least).
# Without it, SGTTY isn't declared.  Something in the ghc C headers
# which get included before term.h in the generated C is clobbering
# it.  (If you edit that C and put the curses.h and term.h first, the
# error goes away.)
GHCFLAGS_src__Darcs__External.o += '-\#include <termio.h>'
endif
GHCFLAGS_src__Darcs__External.o += '-\#include <curses.h>' '-\#include <term.h>'
endif

SRC_DIRS:=. ./src ./src/Crypt\
		  ./src/Darcs\
		  ./src/Darcs/Commands\
		  ./src/Darcs/Repository\
		  ./src/Darcs/Patch\
		  ./src/win32\
		  ./src/win32/System\
		  ./src/win32/System/Posix\

MODULES_AUTOCONF :=\
	Autoconf.lhs \
	Context.hs \
        Workaround.hs \

MODULES_GENERAL :=\
	ThisVersion.lhs \
	CommandLine.lhs \
	URL.hs HTTP.hs DateMatcher.lhs \
	English.lhs Exec.lhs\
	FastPackedString.hs FileName.lhs FileSystem.hs IsoDate.lhs \
	Lcs.lhs OldDate.lhs OldFastPackedString.hs \
	Printer.lhs	\
	RegChars.lhs \
	SHA1.lhs Ssh.hs UTF8.lhs	\

MODULES_CRYPT := SHA256.hs

MODULES_DARCS :=\
	ArgumentDefaults.lhs \
	Arguments.lhs Bug.lhs \
	CheckFileSystem.lhs \
	ColorPrinter.lhs 	\
	Commands.lhs CommandsAux.lhs Compat.hs	\
	Diff.lhs Email.hs FilePathUtils.hs \
	FilePathMonad.lhs	\
	External.hs	\
	Flags.lhs Global.lhs 	\
	Hopefully.lhs HopefullyPrivate.lhs \
	IO.lhs Lock.lhs Patch.lhs	\
	Match.lhs \
	Population.lhs PopulationData.lhs	\
	PrintPatch.lhs Progress.lhs \
	RemoteApply.lhs	RepoPath.hs \
	Repository.lhs Resolution.lhs SignalHandler.lhs Test.lhs URL.hs \
	Sealed.lhs Show.lhs \
	SlurpDirectory.lhs \
	SelectChanges.lhs TheCommands.lhs	\
	Utils.lhs		\

MODULES_PATCH:=\
	Apply.lhs Bundle.lhs	\
	Commute.lhs Core.lhs	\
	Choices.lhs \
	Depends.lhs Info.lhs Match.lhs MatchData.lhs	\
	Non.lhs \
	Ordered.lhs \
	Patchy.lhs Permutations.lhs \
	Prim.lhs \
	Read.lhs ReadMonads.hs Real.lhs Set.lhs Show.lhs 	\
	TouchesFiles.lhs Viewing.lhs	\

MODULES_REPOSITORY:=\
	ApplyPatches.lhs \
	Checkpoint.lhs \
	HashedIO.lhs HashedRepo.lhs \
	Format.lhs Internal.lhs \
	InternalTypes.lhs \
	Motd.lhs Prefs.lhs		\
	Pristine.lhs \
	DarcsRepo.lhs	\

MODULES_COMMANDS:=\
	Add.lhs AmendRecord.lhs Annotate.lhs Apply.lhs		\
	Changes.lhs Check.lhs Convert.lhs Diff.lhs Dist.lhs	\
	Get.lhs	Help.lhs Init.lhs MarkConflicts.lhs Mv.lhs Optimize.lhs 		\
	Pull.lhs Push.lhs Put.lhs	\
	Record.lhs Remove.lhs Repair.lhs Replace.lhs	\
	Revert.lhs Rollback.lhs	\
	Send.lhs SetPref.lhs \
	Show.lhs ShowAuthors.lhs ShowBug.lhs \
	ShowContents.lhs ShowFiles.lhs ShowTags.lhs ShowRepo.lhs	\
	Tag.lhs TrackDown.lhs TransferMode.lhs	\
	Unrecord.lhs Unrevert.lhs WhatsNew.lhs \

witnesses: src/Darcs/Patch/Real.hi src/Darcs/Patch/Properties.hi src/Darcs/Patch.hi \
	src/Darcs/Repository/ApplyPatches.hi src/Darcs/Patch/Bundle.hi \
	src/Darcs/Patch/Match.hi src/Darcs/Repository/HashedRepo.hi \
	src/Darcs/Resolution.hi src/Darcs/Patch/Check.hi \
	src/Darcs/Repository/Pristine.hi src/Darcs/Repository/DarcsRepo.hi

DARCS_FILES := $(DARCS_FILES_DEPS)\
	$(patsubst %,src/%,$(MODULES_AUTOCONF))\
	$(patsubst %,src/%,$(MODULES_GENERAL))\
	$(patsubst %,src/Crypt/%,$(MODULES_CRYPT))\
	$(patsubst %,src/Darcs/%,$(MODULES_DARCS))\
	$(patsubst %,src/Darcs/Patch/%,$(MODULES_PATCH))\
	$(patsubst %,src/Darcs/Repository/%,$(MODULES_REPOSITORY))\
	$(patsubst %,src/Darcs/Commands/%,$(MODULES_COMMANDS))

UNIT_FILES := $(DARCS_FILES) src/Darcs/Patch/Test.lhs src/Darcs/Patch/QuickCheck.lhs \
	 src/Darcs/Patch/Unit.lhs src/Darcs/Patch/Properties.lhs src/Darcs/Patch/Check.lhs

C_OBJS := $(patsubst %,src/%,c_compat.o maybe_relink.o atomic_create.o fpstring.o umask.o) \
	src/Crypt/sha2.o src/hscurl.o src/hslibwww.o

ifeq ($(SYS), windows)
GHCFLAGS += -isrc/win32 -Isrc/win32 -DWIN32
DARCS_FILES += src/win32/System/Posix.hs src/win32/System/Posix/Files.hs \
               src/win32/System/Posix/IO.hs src/win32/CtrlC.hs
C_OBJS += src/win32/CtrlC_stub.o src/win32/CtrlC.o
UNIT_FILES += src/win32/System/Posix.hs src/win32/System/Posix/Files.hs \
              src/win32/System/Posix/IO.hs
endif

ifeq ($(HAVE_MAPI),True)
C_OBJS += src/win32/send_email.o
CPPFLAGS += -Isrc/win32
GHCFLAGS += -DHAVE_MAPI
endif

DARCS_OBJS	:= $(patsubst %.hs,%.o,$(patsubst %.lhs,%.o,$(DARCS_FILES)))
UNIT_OBJS	:= $(patsubst %.hs,%.o,$(patsubst %.lhs,%.o,$(UNIT_FILES)))


.PHONY:		all clean distclean maintainer-clean dist deb test check install \
		test_shell test_shell_hashed test_shell_format2 \
		test_perl test_perl_hashed test_perl_format2 \
		bugs bugs_shell bugs_shell_hashed bugs_shell_format2 \
		bugs_perl bugs_perl_hashed bugs_perl_format2 \
		installserver installdocs installbin windowsinstaller \
		website slowtest witnesses\
		api-doc-dir

config: configure autoconf.mk

copy:
	$(MAKE) install prefix=$(destdir)/$(prefix) \
                        bindir=$(destdir)/$(bindir) \
                        libdir=$(destdir)/$(libdir) \
                        datadir=$(destdir)/$(datadir) \
                        libexecdir=$(destdir)/$(libexecdir)

installbin:	all
	test -d $(DESTDIR)$(bindir) || $(INSTALL) -d $(DESTDIR)$(bindir)
	$(INSTALL) darcs $(DESTDIR)$(bindir)

	test -d $(DESTDIR)$(sysconfdir)/bash_completion.d || \
		$(INSTALL) -d $(DESTDIR)$(sysconfdir)/bash_completion.d
	$(INSTALL_DATA) tools/darcs_completion $(DESTDIR)$(sysconfdir)/bash_completion.d/darcs

	test -d $(DESTDIR)$(mandir)/man1 || \
		$(INSTALL) -d $(DESTDIR)$(mandir)/man1
	$(INSTALL_DATA) doc/darcs.1 $(DESTDIR)$(mandir)/man1/

installdocs:	doc/manual/darcs.ps doc/manual/patch-theory.pdf doc/manual/index.html
	test -d $(DESTDIR)$(docdir)/manual || \
		$(INSTALL) -d $(DESTDIR)$(docdir)/manual
	$(INSTALL_DATA) doc/manual/* $(DESTDIR)$(docdir)/manual

	test -d $(DESTDIR)$(docdir)/examples || \
		$(INSTALL) -d $(DESTDIR)$(docdir)/examples
	$(INSTALL_DATA) tools/zsh_completion_new $(DESTDIR)$(docdir)/examples/
	$(INSTALL_DATA) tools/zsh_completion_old $(DESTDIR)$(docdir)/examples/

installserver:	tools/cgi/darcs.cgi
	test -d $(DESTDIR)$(libexecdir)/cgi-bin || \
		$(INSTALL) -d $(DESTDIR)$(libexecdir)/cgi-bin

	test -d $(DESTDIR)$(sysconfdir)/darcs || \
		$(INSTALL) -d $(DESTDIR)$(sysconfdir)/darcs
	test -e $(DESTDIR)$(sysconfdir)/darcs/cgi.conf || \
	    $(INSTALL_DATA) tools/cgi/cgi.conf $(DESTDIR)$(sysconfdir)/darcs/cgi.conf
	$(INSTALL) tools/cgi/darcs.cgi $(DESTDIR)$(libexecdir)/cgi-bin/darcs.cgi
	test -d $(DESTDIR)$(datadir)/darcs || \
		$(INSTALL) -d $(DESTDIR)$(datadir)/darcs
	test -d $(DESTDIR)$(datadir)/darcs/xslt || \
		$(INSTALL) -d $(DESTDIR)$(datadir)/darcs/xslt
	$(INSTALL_DATA) tools/cgi/xslt/*.xslt $(DESTDIR)$(datadir)/darcs/xslt/
	$(INSTALL_DATA) tools/cgi/xslt/errors.xml $(DESTDIR)$(datadir)/darcs/xslt/
	$(INSTALL_DATA) tools/cgi/xslt/styles.css $(DESTDIR)$(datadir)/darcs/xslt/styles.css

# Debian policy doesn't allow symlinks as configuration files.
#	test -e $(DESTDIR)$(sysconfdir)/darcs/styles.css || \
#	    ln -s $(datadir)/darcs/xslt/styles.css \
#		$(DESTDIR)$(sysconfdir)/darcs/styles.css
	$(INSTALL) -m 644 tools/cgi/xslt/styles.css $(DESTDIR)$(sysconfdir)/darcs/styles.css

PREDIST_COPY_FILES := \
	ChangeLog \
	AUTHORS \
	release/STATE \
	src/Context.hs

dist: darcs $(PREDIST_COPY_FILES)
	REPO_PATH="$$PWD" ./darcs dist --dist-name darcs-$(DARCS_VERSION)
	ln -sf darcs-$(DARCS_VERSION).tar.gz darcs-latest.tar.gz

darcs-test.tar.gz: darcs $(PREDIST_COPY_FILES)
	REPO_PATH="$$PWD" ./darcs dist --dist-name darcs-test

predist_copy:
	for F in $(PREDIST_COPY_FILES); do \
	    cp -v "$$REPO_PATH/$$F" "$$F"; \
	done

predist: predist_copy doc/manual/darcs.ps doc/darcs.1 doc/manual/index.html distclean
	rm -fr release/debian

deb:		darcs
	rm -rf /tmp/darcs-deb_temp && \
	./darcs dist --dist-name darcs-deb_temp && \
	mv darcs-deb_temp.tar.gz /tmp && \
	cd /tmp && tar zxf darcs-deb_temp.tar.gz && \
	cd darcs-deb_temp && debuild && \
	rm -rf /tmp/darcs-deb_temp

#ensure the directory exists for api documentation
api-doc-dir:
	@echo "Creating api-doc directory"
	@mkdir -p api-doc

#generate the api documentation
api-doc: api-doc-dir $(DARCS_FILES)
	@if test $(HADDOCK_VERSION) -lt 2 ; then \
	   echo "You need haddock 2.0.0 or later to build the API documentation" ; \
	   exit 1 ; \
	 else \
	   echo "Generating html" ; \
	   haddock --ignore-all-exports --optghc=-I. --optghc=-I./src --optghc=-i./src --optghc=-D__HADDOCK__ -B `$(GHC) --print-libdir` -o api-doc -h $(filter-out %api-doc-dir,$^) ; \
	 fi

windowsinstaller:	darcs doc/manual/index.html release/darcs.nsi
	echo "!define VERSION $(DARCS_VERSION)" > version.nsi
	"$(MAKENSIS)" version.nsi release/darcs.nsi
	rm -f version.nsi

darcs:		$(DARCS_OBJS) src/darcs.lhs $(C_OBJS)
	@echo Linking $@ ...
	@rm -f Main.o Main.hi
ifdef VERBOSE
	$(GHC) $(GHCFLAGS) $(OPTLLDFLAGS) -o $@ $^ $(OPTLLIBS)
else
	@$(GHC) $(GHCFLAGS) $(OPTLLDFLAGS) -o $@ $^ $(OPTLLIBS)
endif

ghci: $(DARCS_FILES) $(C_OBJS)
	ghci $(filter-out -Wall,$(GHCFLAGS)) $(OPTLLDFLAGS) src/darcs.lhs $(C_OBJS) $(OPTLLIBS)
.PHONY: ghci

darcsman:		src/darcsman.hs $(C_OBJS) $(DARCS_OBJS)
list_authors:	src/list_authors.hs $(C_OBJS) $(DARCS_OBJS)
microbench:	src/microbench.hs $(C_OBJS) $(DARCS_OBJS)
make_changelog:	src/make_changelog.hs $(C_OBJS) $(DARCS_OBJS)
unit:			src/unit.lhs $(UNIT_OBJS) $(C_OBJS)
preproc:		src/preproc.hs $(C_OBJS) $(DARCS_OBJS)

TEXSOURCES := preproc src/darcs.lhs src/features.tex \
	src/switching.tex src/configuring_darcs.tex src/gpl.tex \
	$(DARCS_FILES) src/building_darcs.tex \
	src/best_practices.tex
src/darcs.tex: $(TEXSOURCES)
	./preproc darcs.lhs $(PREPROCHTML) > src/darcs.tex
# The following is to prevent both being generated simultaneously, which
# confuses texlive:
src/darcs_print.pdf: src/darcs_print.ps
src/darcs_print.tex: $(TEXSOURCES)
	./preproc darcs.lhs > src/darcs_print.tex
src/patch-theory.tex: $(TEXSOURCES) $(UNIT_FILES)
	./preproc Darcs/Patch/Properties.lhs > src/patch-theory.tex

website: doc/manual/darcs.ps doc/manual/patch-theory.pdf doc/manual/index.html doc/manual/bigpage.html \
	darcs doc/index.html

doc/manual/index.html: src/darcs.tex src/gpl.tex doc/darcs.css
	$(MAKEMANUAL)
	cp -f doc/darcs.css doc/manual/darcs.css

doc/manual/bigpage.html: src/darcs.tex src/gpl.tex doc/darcs.css
	ln -sf darcs.tex src/bigpage.tex
	latex2html -split 0 -external_file darcs -prefix big \
		-no_auto_link -dir doc/manual src/bigpage.tex
	rm src/bigpage.tex
	cp -f doc/darcs.css doc/manual/bigpage.css

doc/manual/darcs.ps:	src/darcs_print.ps
	cp src/darcs_print.ps doc/manual/darcs.ps
doc/manual/darcs.pdf:	src/darcs_print.pdf
	cp src/darcs_print.pdf doc/manual/darcs.pdf
doc/manual/patch-theory.pdf: src/patch-theory.pdf
	cp src/patch-theory.pdf doc/manual/

doc/darcs.1:	darcsman
	./darcsman > $@

AUTHORS:	list_authors
	./list_authors > AUTHORS

ChangeLog: make_changelog changelog.in/ChangeLog.old $(wildcard changelog.in/entries/*)
	( \
	  set -e; \
	  echo; \
	  rm -f changelog.in/entries/*~; \
	  ./make_changelog $(wildcard changelog.in/entries/*); \
	  echo; \
	  sed -n '/^darcs (1\.0\.2)$$/,$$p' changelog.in/ChangeLog.old; \
	) > $@.tmp
	mv $@.tmp $@

test check:     \
		test_shell_hashed test_shell test_shell_format2 \
		test_perl test_perl_hashed test_perl_format2 \
		bugs

bugs:	bugs_shell_hashed bugs_shell bugs_shell_format2 \
	bugs_perl bugs_perl_hashed bugs_perl_format2

TEST_FILTER_FILE := tests_to_run
PERL_HARNESS := perl ../tests/bin/prove --nocolor
SHELL_HARNESS := perl ../tests/shell_harness

# $1 - description
# $2 - setup
# $3 - discard
# $4 - type
# $5 - extension
# $6 - harness
define harness
	@echo Running $4 tests on $1 repositories...
	@chmod -R u+rwx tests-$4-$1.dir || true
	@rm -rf tests-$4-$1.dir && cp -R tests tests-$4-$1.dir
	@cd tests-$4-$1.dir && rm -rf .darcs; mkdir .darcs;\
	 $2;\
	 if [ -r $(TEST_FILTER_FILE) ];\
	 then grep "\.$5" $(TEST_FILTER_FILE) | grep -v '^#' | $3 | xargs $6; \
	 else ls *.$5 | sort -r | $3 | xargs $6; fi
	@echo Done running tests on $1 repositories...
endef

define bug_harness
	@echo Demonstrating $4 bugs on $1 repositories...
	@rm -rf bugs-$4-$1.dir && cp -R bugs bugs-$4-$1.dir
	@cd bugs-$4-$1.dir && rm -rf .darcs; mkdir .darcs;\
	 $2;\
	 if [ -r $(TEST_FILTER_FILE) ];\
	 then bugs=1 grep "\.$5" $(TEST_FILTER_FILE) | grep -v '^#' | $3 | xargs $6 || true; \
	 else bugs=1 ls *.$5 | sort -r | $3 | xargs $6 || true; fi
	@echo Done demonstrating bugs on $1 repositories...
endef

# $1 - description
# $2 - setup
# $3 - discard
shell_harness=$(call harness,$1,$2,$3,shell,sh,$(SHELL_HARNESS))
perl_harness=$(call harness,$1,$2,$3,perl,pl,$(PERL_HARNESS))
shell_bugs=$(call bug_harness,$1,$2,$3,shell,sh,$(SHELL_HARNESS))
perl_bugs=$(call bug_harness,$1,$2,$3,perl,pl,$(PERL_HARNESS))

test_network: darcs
	@echo Running network tests ...
	@rm -rf tests-network.dir && cp -R tests/network tests-network.dir
	@cd tests-network.dir && rm -rf .darcs; mkdir .darcs;\
	 if [ -r $(TEST_FILTER_FILE) ];\
	 then bugs=1 grep "\.sh" $(TEST_FILTER_FILE) | grep -v '^#' | xargs $(SHELL_HARNESS); \
	 else bugs=1 ls *.sh | sort -r | xargs $(SHELL_HARNESS); fi
	@echo Passed network tests.

test_shell:     darcs
	$(call shell_harness,old-fashioned,:,cat)

# for the format2 tests, we skip the hashed_inventory.sh test, since explicitly
# creates the old-fashioned format that's incompatible with darcs-2.
test_shell_format2:     darcs
	$(call shell_harness,darcs-2,\
	 echo ALL --darcs-2 >> .darcs/defaults,\
	 grep -v hashed_inventory.sh)

test_shell_hashed:     darcs
	$(call shell_harness,hashed,\
	 echo ALL --hashed >> .darcs/defaults,cat)

# skip test known to fail on this repo format
test_perl:     darcs
	$(call perl_harness,old-fashioned,:,cat)

test_perl_format2:     darcs
	$(call perl_harness,darcs-2,\
	 echo ALL --darcs-2 >> .darcs/defaults,cat)

test_perl_hashed:     darcs
	$(call perl_harness,hashed,\
	 echo ALL --hashed >> .darcs/defaults,grep -v conflict-doppleganger.pl)

bugs_shell:     darcs
	$(call shell_bugs,old-fashioned,:,cat)

bugs_shell_format2:     darcs
	$(call shell_bugs,format-2,\
	 echo ALL --darcs-2 >> .darcs/defaults,\
	 grep -v hashed_inventory.sh)

bugs_shell_hashed:     darcs
	$(call shell_bugs,hashed,\
	 echo ALL --hashed >> .darcs/defaults,cat)

bugs_perl:     darcs
	$(call perl_bugs,old-fashioned,:,cat)

bugs_perl_format2:     darcs
	$(call perl_bugs,darcs-2,\
	 echo ALL --darcs-2 >> .darcs/defaults,cat)

bugs_perl_hashed:     darcs
	$(call perl_bugs,hashed,\
	 echo ALL --hashed >> .darcs/defaults,cat)

test_unit:     darcs unit
	./unit

register:

clean:
	rm -f $(foreach dir,$(SRC_DIRS),$(dir)/*.o $(dir)/*.hi)
	rm -f unit diff darcs darcs_cgi
	rm -f stringify
	rm -f src/darcs.tex src/darcs.dvi src/darcs.aux
	rm -f src/patch-theory.tex src/patch-theory.aux src/patch-theory.log
	rm -f src/patch-theory.aux src/patch-theory.toc
	rm -f src/darcs_print.tex src/darcs_print.log src/darcs_print.aux src/darcs_print.toc
	rm -f preproc darcsman
	rm -rf tests/temp* darcs.log darcs.toc
	rm -f conftest* .depend.bak
	rm -f src/win32/System/Posix/IO.hs src/win32/System/Posix/Files.hs
	rm -f version.nsi
	rm -f list_authors make_changelog
	rm -rf api-doc
	#only remove src/Context.hs if we have a darcs inventory to rebuild it from
	if test -f _darcs/inventory; then rm -f src/Context.hs; fi
	rm -f TAGS tags

distclean:	clean
	rm -rf config.status config.log autoconf.mk config.cache autom4te.cache
	rm -f doc/manual/darcs.ps doc/manual/darcs.pdf doc/manual/patch-theory.pdf src/Autoconf.lhs Workaround.hs darcs.idv
	rm -f src/ThisVersion.lhs tools/cgi/README tools/cgi/darcs.cgi tools/cgi/cgi.conf
	rm -f config.command

maintainer-clean: distclean
	@echo 'This command is intended for maintainers to use; it'
	@echo 'deletes files that may need special tools to rebuild.'
	rm -f configure doc/darcs.1 .depend AUTHORS ChangeLog
	rm -f src/Context.hs
	rm -f doc/manual/*.html doc/manual/darcs*.??? doc/manual/darcs.lg
	rm -f doc/manual/darcs.xref c_context.c doc/darcs_print.ps
	rm -rf tests/test_output

configure:		configure.ac aclocal.m4
	autoconf

autoconf.mk src/Autoconf.lhs tools/cgi/darcs.cgi : \
   config.status autoconf.mk.in src/Autoconf.lhs.in tools/cgi/darcs.cgi.in
	./config.status

config.status:	configure
	@if test -x config.status; then					\
	  ./config.status --recheck;					\
	else								\
	  echo >&2 "Please run ./configure to setup the build system.";	\
	  exit 1;							\
	fi

.depend:	$(DARCS_FILES) $(UNIT_FILES)
	@echo Rebuild dependencies ...
	@$(GHC) $(GHCFLAGS) -M -optdep-f -optdep.depend $^

.depend:	autoconf.mk

ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifneq (config,$(MAKECMDGOALS))
include .depend
endif
endif

ETAGS = hasktags -e
CTAGS = hasktags -c
# This follows what autoconf does.
# Fixme: Generate correct list of .c files and depend on that.
.PHONY: CTAGS ctags tags
tags: TAGS
TAGS: $(DARCS_FILES)
	$(ETAGS) $(DARCS_FILES) && etags -a src/*.c
ctags: CTAGS
CTAGS: $(DARCS_FILES)
	$(CTAGS) $(DARCS_FILES) && ctags -a src/*.c
	mv tags tags.unsorted
	sort tags.unsorted > tags