summaryrefslogtreecommitdiff
path: root/Makefile
blob: 182b9eaed25ec10e20bc63323714b4d00e8cfcee (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
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
all: local

# Configuration (override on the commandline)

LUA_VER := 5.1
LUA := /usr/bin/lua$(LUA_VER)
PREFIX ?= /usr/local
INST_ROOT := $(PREFIX)

# Internal stuff
LUA_MOD_PATH := $(INST_ROOT)/share/lua/$(LUA_VER)
LUA_MOD_INST_PATH := $(DESTDIR)$(LUA_MOD_PATH)
BIN_PATH := $(INST_ROOT)/bin
BIN_INST_PATH := $(DESTDIR)$(BIN_PATH)
LIB_BIN_PATH := $(INST_ROOT)/lib/gitano/bin
LIB_BIN_INST_PATH := $(DESTDIR)$(LIB_BIN_PATH)
SHARE_PATH := $(INST_ROOT)/share/gitano
SHARE_INST_PATH := $(DESTDIR)$(SHARE_PATH)
SKEL_INST_PATH := $(SHARE_INST_PATH)/skel
MAN_PATH := $(INST_ROOT)/share/man
MAN_INST_PATH := $(DESTDIR)$(MAN_PATH)

LIB_BINS := gitano-auth gitano-post-receive-hook gitano-update-hook	\
	    gitano-update-ssh gitano-pre-receive-hook

BINS := gitano-setup

TEST_BIN_NAMES := gitano-test-tool

TESTS := 01-basics 02-commands-as 02-commands-config 02-commands-copy		\
         02-commands-count-objects 02-commands-create 02-commands-destroy	\
         02-commands-fsck 02-commands-gc 02-commands-graveyard			\
         02-commands-group 02-commands-help 02-commands-ls 02-commands-readme	\
         02-commands-rename 02-commands-set-description 02-commands-set-head	\
         02-commands-set-owner 02-commands-sshkey 02-commands-user		\
         02-commands-whoami


MODS := gitano 								\
									\
	gitano.util							\
	gitano.actions gitano.config gitano.lace gitano.log		\
	gitano.markdown gitano.repository gitano.supple 		\
	gitano.command gitano.admincommand gitano.usercommand		\
	gitano.repocommand gitano.copycommand

SKEL_FILES := gitano-admin/rules/selfchecks.lace			\
	      gitano-admin/rules/aschecks.lace 				\
	      gitano-admin/rules/siteadmin.lace				\
	      gitano-admin/rules/destroyrepo.lace			\
	      gitano-admin/rules/remoteconfigchecks.lace		\
	      gitano-admin/rules/core.lace				\
	      gitano-admin/rules/renamerepo.lace			\
	      gitano-admin/rules/defines.lace				\
	      gitano-admin/rules/project.lace				\
	      gitano-admin/rules/adminchecks.lace			\
	      gitano-admin/rules/createrepo.lace

MAN1S := gitano-setup.1

MOD_DIRS := gitano
MOD_FILES := $(patsubst %,%.lua,$(subst .,/,$(MODS)))
SRC_MOD_FILES := $(patsubst %,lib/%,$(MOD_FILES))

LOCAL_BINS := $(patsubst %,bin/%,$(BINS) $(LIB_BINS))
LIB_BIN_SRCS := $(patsubst %,bin/%.in,$(LIB_BINS))

TEST_BINS := $(patsubst %,testing/%,$(TEST_BIN_NAMES))
TEST_BIN_SRCS := $(patsubst %,%.in,$(TEST_BINS))

YARN := yarn

TESTS := $(patsubst %,testing/%.yarn,$(TESTS))

GEN_BIN := utils/install-lua-bin
RUN_GEN_BIN := $(LUA) $(GEN_BIN) $(LUA)
define GEN_LOCAL_BIN

$(RUN_GEN_BIN) $(shell pwd) $(shell pwd)/bin $(shell pwd)/lib $1 $2
chmod 755 $2

endef

define GEN_INSTALL_BIN

$(RUN_GEN_BIN) $(SHARE_PATH) $(LIB_BIN_PATH) $(LUA_MOD_PATH) $1 $2
chmod 755 $2

endef

define GEN_INSTALL_MAN

cp $1 $2
chmod 644 $2

endef

define GEN_INSTALL_MOD

install -m 644 $1 $2

endef

local: $(LOCAL_BINS)

clean:
	@echo "CLEAN: local binaries"
	@$(RM) $(LOCAL_BINS)
	@echo "CLEAN: test binaries"
	@$(RM) $(TEST_BINS)

distclean: clean
	@find . -name "*~" -delete

bin/%: bin/%.in $(GEN_BIN)
	$(call GEN_LOCAL_BIN,$<,$@)

install: install-bins install-lib-bins install-mods install-skel install-man

install-man:
	mkdir -p $(MAN_INST_PATH)/man1
	$(foreach MAN,$(MAN1S),$(call GEN_INSTALL_MAN,doc/$(MAN),$(MAN_INST_PATH)/man1/$(MAN)))

install-bins: $(BIN_SRCS) $(GEN_BIN)
	mkdir -p $(BIN_INST_PATH)
	$(foreach BIN,$(BINS),$(call GEN_INSTALL_BIN,bin/$(BIN).in,$(BIN_INST_PATH)/$(BIN)))

install-lib-bins: $(LIB_BIN_SRCS) $(GEN_BIN)
	mkdir -p $(LIB_BIN_INST_PATH)
	$(foreach BIN,$(LIB_BINS),$(call GEN_INSTALL_BIN,bin/$(BIN).in,$(LIB_BIN_INST_PATH)/$(BIN)))

install-mods: $(SRC_MOD_FILES)
	mkdir -p $(patsubst %,$(LUA_MOD_INST_PATH)/%,$(MOD_DIRS))
	$(foreach MOD,$(MOD_FILES),$(call GEN_INSTALL_MOD,lib/$(MOD),$(LUA_MOD_INST_PATH)/$(MOD)))

install-skel:
	mkdir -p $(SKEL_INST_PATH)/gitano-admin/rules
	for SKELFILE in $(SKEL_FILES); do \
		install -m 644 skel/$$SKELFILE $(SKEL_INST_PATH)/$$SKELFILE; \
	done

test: local $(TEST_BINS)
	@$(YARN) --env GTT="$$(pwd)/testing/gitano-test-tool"			\
	        testing/library.yarn $(TESTS)

testing/%: testing/%.in $(GEN_BIN)
	$(call GEN_LOCAL_BIN,$<,$@)