summaryrefslogtreecommitdiff
path: root/Makefile
blob: e844f02dca4595cf15b6eaa697990969317c9e54 (plain)
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
all: test

MODULES := gall gall.util gall.ll \
	   gall.repository gall.object gall.commit gall.tag gall.tree
LUA_VER := 5.1

PREFIX ?= /usr/local

INST_BASE := $(PREFIX)
INST_ROOT := $(DESTDIR)$(INST_BASE)/share/lua/$(LUA_VER)
C_INST_ROOT := $(DESTDIR)$(INST_BASE)/lib/lua/$(LUA_VER)

INCS := -I/usr/include/lua$(LUA_VER) -Ilibgit2/build/gall-install/include
OPT := -O0 -g
PIC := -fPIC
WARN := -Wall -Werror
DEFS := 
CFLAGS := $(INCS) $(OPT) $(WARN) $(DEFS) $(PIC) $(CFLAGS)
LIBGIT2_LDEPS ?= -lssl -lssh2 -lrt
LFLAGS := -O1 -g -Llibgit2/build/gall-install/lib -lgit2 $(LIBGIT2_LDEPS) $(LFLAGS)

MOD_FILES := $(patsubst %,%.lua,$(subst .,/,$(MODULES)))

install: cmodule
	mkdir -p $(INST_ROOT)/gall
	for MOD in $(sort $(MOD_FILES)); do \
		cp lib/$${MOD} $(INST_ROOT)/$${MOD}; \
	done
	if test -e lib/gall/ll/git2.so; then \
		mkdir -p $(C_INST_ROOT)/gall/ll; \
		cp lib/gall/ll/git2.so $(C_INST_ROOT)/gall/ll/; \
	fi


LUA := LUA_CPATH="$(shell pwd)/lib/?.so;;" LUA_PATH="$(shell pwd)/lib/?.lua;$(shell pwd)/extras/luacov/src/?.lua;;" lua$(LUA_VER)

cmodule: try-cmodule

try-cmodule:
	-@$(MAKE) --no-print-directory do-cmodule

do-cmodule: lib/gall/ll/git2.so

lib/gall/ll/git2.so: libgit2/build/gall-install-stamp lib/gall/ll/git2.c
	$(CC) $(CFLAGS) lib/gall/ll/git2.c -o $@ -shared $(LFLAGS)

libgit2/build/gall-install-stamp:
	mkdir -p libgit2/build
	cd libgit2/build && cmake -DBUILD_SHARED_LIBS:BOOLEAN=OFF -DCMAKE_INSTALL_PREFIX:PATH=$(shell pwd)/libgit2/build/gall-install -DCMAKE_C_FLAGS=-fPIC ..
	cd libgit2/build && $(MAKE)
	echo "DISABLED BECAUSE LIBGIT2 AUTHORS ARE MAD: cd libgit2/build && $(MAKE) test"
	cd libgit2/build && ./libgit2_clar -xonline
	cd libgit2/build && $(MAKE) install DESTDIR=""
	touch $@

clean:
	$(RM) luacov.report.out luacov.report.git2.out luacov.stats.out
	$(RM) -r libgit2/build luagit2/build lib/gall/ll/git2.so

distclean: clean
	find . -name "*~" -delete
	$(RM) libgit2/tests-clar/clar.h
	$(RM) libgit2/tests-clar/clar_main.c

.PHONY: example
example:
	$(LUA) example/gall-example.lua

.PHONY: test
test: cmodule
	@$(RM) luacov.stats.out; \
	ERR=0; \
	for MOD in $(sort $(MODULES)); do \
		echo -n "$${MOD}: "; \
		$(LUA) test/test-$${MOD}.lua; \
		test "x$$?" = "x0" || ERR=1; \
	done; \
	$(LUA) extras/luacov/src/bin/luacov -X luacov. -X test. $(MODULES); \
	mv luacov.report.out luacov.report.git2.out; \
	for MOD in $(sort $(MODULES)); do \
		echo -n "$${MOD} [no git2]: "; \
		GALL_DISABLE_GIT2=1 $(LUA) test/test-$${MOD}.lua; \
		test "x$$?" = "x0" || ERR=1; \
	done; \
	$(LUA) extras/luacov/src/bin/luacov -X luacov. -X test. $(MODULES); \
	exit $$ERR
	@echo -n "Allowing use of luagit2 saves "; \
	PRE=$$(grep sp.spawn_simple luacov.report.git2.out | awk '{print $$1}'); \
	POST=$$(grep sp.spawn_simple luacov.report.out | awk '{print $$1}'); \
	NORM=$$((POST - PRE)); \
	echo -n $$((NORM - PRE)) / $${NORM}; \
	echo " calls out to git executable during test suite."

.PHONY: interactive
interactive:
	$(LUA) -e'gall=require"gall"' -i