Add heuristic to take shortcut when too slow.
[wiggle/upstream.git] / Makefile
blob231106740eab07fba2f0866c271bdc0242dba377
2 # Note on my Mobile Pentium II, -march=pentium2 delivers twice the performance of i386
3 #OptDbg=-O3
4 #OptDbg=-O3 -march=pentium2
5 OptDbg=-ggdb
6 ifndef CWFLAGS
7 CWFLAGS=-Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
8 endif
9 CFLAGS=$(OptDbg) -I. $(CWFLAGS)
11 PREFIX = /usr
12 # STRIP = -s
13 INSTALL = /usr/bin/install
14 DESTDIR =
15 BINDIR = $(PREFIX)/bin
16 MANDIR = $(PREFIX)/share/man
17 MAN1DIR = $(MANDIR)/man1
18 MAN5DIR = $(MANDIR)/man5
19 LDLIBS = -lncurses
21 # Where to place intermediate objects
22 O=O
23 # Where to place final objects
24 BIN=.
25 DOC=.
27 LIBOBJ= load.o parse.o split.o extract.o diff.o bestmatch.o merge2.o ccan/hash/hash.o
28 OBJ=wiggle.o ReadMe.o vpatch.o
30 BOBJ=$(patsubst %.o,$(O)/%.o,$(OBJ))
31 BLIBOBJ=$(patsubst %.o,$(O)/%.o,$(LIBOBJ))
33 all: $(BIN)/wiggle $(DOC)/wiggle.man test
34 lib : $(O)/libwiggle.a
37 # Pretty print
39 V = @
40 Q = $(V:1=)
41 QUIET_CC = $(Q:@=@echo ' CC '$@;)
42 QUIET_AR = $(Q:@=@echo ' AR '$@;)
43 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
44 QUIET_MAN = $(Q:@=@echo ' MAN '$@;)
45 QUIET_CLEAN = $(Q:@=@echo ' CLEAN '$@;)
48 $(BIN)/wiggle : $(BOBJ) $(O)/libwiggle.a
49 $(QUIET_LINK)$(CC) $(CFLAGS) $^ $(LDLIBS) -o $@
51 $(O)/libwiggle.a : $(BLIBOBJ)
52 $(QUIET_AR)ar cr $@ $^
54 $(BOBJ) :: wiggle.h
56 $(O)/split.o :: ccan/hash/hash.h config.h
58 $(BOBJ) $(BLIBOBJ) :: $(O)/%.o : %.c
59 @mkdir -p $(dir $@)
60 $(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
62 VERSION = $(shell [ -d .git ] && git 2> /dev/null describe HEAD)
63 VERS_DATE = $(shell [ -d .git ] && git 2> /dev/null log -n1 --format=format:%cd --date=short)
64 DVERS = $(if $(VERSION),-DVERSION=\"$(VERSION)\",)
65 DDATE = $(if $(VERS_DATE),-DVERS_DATE=\"$(VERS_DATE)\",)
66 CFLAGS += $(DVERS) $(DDATE)
68 test: wiggle dotest
69 ./dotest
71 valgrind: wiggle dotest
72 ./dotest valgrind
74 vtest: wiggle dovtest
75 ./dovtest
77 $(DOC)/wiggle.man : wiggle.1
78 $(QUIET_MAN)nroff -man wiggle.1 > $@
80 clean: targets artifacts dirs
81 targets:
82 $(QUIET_CLEAN)rm -f $(O)/*.[ao] $(O)/ccan/hash/*.o $(DOC)/*.man $(BIN)/wiggle .version* demo.patch version
83 artifacts:
84 $(QUIET_CLEAN)find . -name core -o -name '*.tmp*' -o -name .tmp -o -name .time | xargs rm -f
85 dirs : targets artifacts
86 $(QUIET_CLEAN)[ -d $(O)/ccan/hash ] && rmdir -p $(O)/ccan/hash || true
87 $(QUIET_CLEAN)[ -d $(O) ] && rmdir -p $(O) || true
89 install : $(BIN)/wiggle wiggle.1
90 $(INSTALL) -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(MAN1DIR)
91 $(INSTALL) $(STRIP) -m 755 $(BIN)/wiggle $(DESTDIR)$(BINDIR)
92 $(INSTALL) -m 644 wiggle.1 $(DESTDIR)$(MAN1DIR)
94 version : ReadMe.c wiggle.1
95 @rm -f version
96 @sed -n -e 's/.*VERSION "\([0-9.]*\)".*/\1/p' ReadMe.c > .version-readme
97 @sed -n -e 's/.*WIGGLE 1 "" v\([0-9.]*\)$$/\1/p' wiggle.1 > .version-man
98 @cmp -s .version-readme .version-man && cat .version-man > version || { echo Inconsistant versions.; exit 1;}
100 dist : test clean version
101 mkdir -p DIST
102 rm -f DIST/wiggle-`cat version`
103 git archive --prefix wiggle-`cat version`/ v`cat version` | gzip -9 > DIST/wiggle-`cat version`.tar.gz
105 v : version
106 cat version
108 demo.patch: force
109 diff -rup demo.orig demo.patched | sed 's/demo.patched/demo/' > demo.patch
111 force: