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

# Configuration (override on the commandline)

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

# 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
LANG_INST_PATH := $(SHARE_INST_PATH)/lang
MAN_PATH := $(INST_ROOT)/share/man
MAN_INST_PATH := $(DESTDIR)$(MAN_PATH)
PLUGIN_PATH := $(SYSCONF_DIR)/gitano/plugins:$(INST_ROOT)/lib/gitano/plugins

LIB_BINS := gitano-auth gitano-post-receive-hook gitano-update-hook	\
	    gitano-update-ssh gitano-pre-receive-hook gitano-smart-http.cgi \
	    gitano-command.cgi

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-git-upload-archive 02-commands-group 02-commands-help	\
         02-commands-keyring \
         02-commands-ls 02-commands-readme 02-commands-rename 02-commands-rsync	\
         02-commands-sshkey 02-commands-user 02-commands-whoami 03-cgit-support	\
         03-shallow-push


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 gitano.auth gitano.plugins\
	gitano.i18n

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

LANG_FILES := json.lua en.lua

MAN1S := gitano-setup.1


PLUGINS := rsync.lua archive.lua

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 $(shell pwd)/plugins $1 $2
chmod 755 $2

endef

define GEN_INSTALL_BIN

$(RUN_GEN_BIN) $(SHARE_PATH) $(LIB_BIN_PATH) $(LUA_MOD_PATH) $(PLUGIN_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)
	$(LUAC) -p $(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,$<,$@)

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

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

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

install-lang:
	mkdir -p $(LANG_INST_PATH)
	for LANGFILE in $(LANG_FILES); do \
		install -m 644 lang/$$LANGFILE $(LANG_INST_PATH)/$$LANGFILE; \
	done

install-plugins:
	mkdir -p $(DESTDIR)$(INST_ROOT)/lib/gitano/plugins
	mkdir -p $(DESTDIR)$(SYSCONF_DIR)/gitano/plugins
	for PLUGIN in $(PLUGINS); do \
		install -m 644 plugins/$$PLUGIN $(DESTDIR)$(INST_ROOT)/lib/gitano/plugins; \
	done
	for LANGFILE in $(wildcard $(patsubst %.lua,plugins/%_*.lua,$(PLUGINS))); do \
		install -m 644 $$LANGFILE $(DESTDIR)$(INST_ROOT)/lib/gitano/plugins; \
	done

YARN_ARGS ?=
ifneq ($(LUA_PATH),)
YARN_ARGS += --env LUA_PATH="$(LUA_PATH)"
endif
ifneq ($(LUA_CPATH),)
YARN_ARGS += --env LUA_CPATH="$(LUA_CPATH)"
endif
ifneq ($(SCENARIO),)
YARN_ARGS += --run "$(SCENARIO)"
endif

ifneq ($(YARN_SNAPSHOT),)
YARN_ARGS += --snapshot
endif

TEST_PROTO ?= ssh

ifeq ($(filter $(TEST_PROTO),ssh http),)
$(error TEST_PROTO should be ssh or http)
endif

basictest: local $(TEST_BINS)
	@echo "Running basic yarns in '$(TEST_PROTO)' mode"
	@echo "Set TEST_PROTO if you want to change that"
	@$(YARN)							 \
		--env GTT="$$(pwd)/testing/gitano-test-tool"		 \
		--env GTT_PROTO=$(TEST_PROTO) 				 \
		$(YARN_ARGS)                                             \
	        testing/library.yarn testing/01*.yarn

test: local $(TEST_BINS)
	@echo "Running full yarns in 'ssh' mode"
	@$(YARN)							 \
		--env GTT="$$(pwd)/testing/gitano-test-tool"		 \
		--env GTT_PROTO=ssh 					 \
		$(YARN_ARGS)                                             \
	        testing/library.yarn $(TESTS)
	@echo "Running full yarns in 'http' mode"
	@$(YARN)							 \
		--env GTT="$$(pwd)/testing/gitano-test-tool"		 \
		--env GTT_PROTO=ssh 					 \
		$(YARN_ARGS)                                             \
	        testing/library.yarn $(TESTS)

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

check: test