diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 132 |
1 files changed, 72 insertions, 60 deletions
@@ -1,72 +1,83 @@ -# git-authz - who may move which refs. C99 and libc, nothing else. -# -# make build ./git-authz -# make test build, then run the unit suite and the behavioural suite -# make install install into $(DESTDIR)$(PREFIX) -# make clean -# -# No configure script, no cmake, no generated headers: the only portability -# knob this program needs is CFLAGS. Warnings are variables so that a strict -# build is a command line and not a build system: -# -# make WARN="-Wall -Wextra -Wpedantic -Werror" +SRC_DIR = src +CMD_DIR = cmd +TST_DIR = test -CC ?= cc -PREFIX ?= /usr/local -BINDIR ?= $(PREFIX)/bin -SHAREDIR ?= $(PREFIX)/share/git-host -SYSCONFDIR ?= /etc/git-host -HOOKDIR ?= $(SHAREDIR)/hooks +OBJ_DIR = obj -STD ?= -std=c99 -WARN ?= -Wall -Wextra -Wpedantic -CFLAGS ?= -O2 -g -CPPFLAGS += -D_POSIX_C_SOURCE=200809L +PROG = git-authz -PROG = git-authz -UNIT = tests/unit -OBJS = src/util.o src/glob.o src/policy.o src/hook.o src/validate.o src/edit.o \ - src/main.o +CMD_SRC = $(wildcard $(CMD_DIR)/*.c) +CMD_OBJ = $(CMD_SRC:%=$(OBJ_DIR)/%.o) -all: $(PROG) +TST_SRC = $(wildcard $(TST_DIR)/*.c) +TST_RUN = $(TST_SRC:$(TST_DIR)/%.c=$(OBJ_DIR)/test_runner/%) -$(PROG): $(OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) +CC_SRC = $(wildcard $(SRC_DIR)/*.c) +CC_OBJ = $(CC_SRC:%=$(OBJ_DIR)/%.o) -src/%.o: src/%.c src/authz.h - $(CC) $(STD) $(WARN) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< +CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -I$(SRC_DIR) +CFLAGS += -D_POSIX_C_SOURCE=200809L +CFLAGS += -g +LDFLAGS = -# AddressSanitizer/UBSan build of everything, so that the behavioural suite - -# which is what actually exercises the editing code paths - runs against them: -# -# make clean && make sanitizer -# -# Leaks are checked, which is why every command frees what it read: a program -# that exits in a millisecond does not need the memory back, but it does need -# the leak report to stay empty, or the one real leak hides among forty. -sanitizer: CFLAGS := -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer +$(OBJ_DIR)/%.c.o: %.c + @mkdir -p $(@D) + $(CC) $(CFLAGS) -o $@ -c $< + +$(PROG): $(CC_OBJ) $(CMD_OBJ) + @mkdir -p $(@D) + $(CC) $(LDFLAGS) $(CC_OBJ) $(CMD_OBJ) -o $@ + +$(OBJ_DIR)/test_runner/%: $(OBJ_DIR)/$(TST_DIR)/%.c.o $(CC_OBJ) + @mkdir -p $(@D) + $(CC) $(LDFLAGS) $(CC_OBJ) $< -o $@ + +# The test/*.c programs are the pieces tested directly: what a glob matches, +# what a ref normalises to, what a policy decides and what the refusal says. +# test/run.sh is the other half - the same binary driven the way a receive hook +# drives it, with an identity in the environment and "old new ref" on stdin, +# and no git anywhere in it. +.PHONY: test +test: $(PROG) $(TST_RUN) + @mkdir -p $(TST_DIR)/tmp + $(foreach var,$(TST_RUN),./$(var) &&) true + AUTHZ=./$(PROG) sh $(TST_DIR)/run.sh + +# Both suites again with AddressSanitizer and UBSan, which is the only reason +# every command frees what it read: a process that exits in a millisecond does +# not need the memory back, but it does need that report to stay empty, or the +# one real leak hides among forty. +.PHONY: sanitizer +sanitizer: CFLAGS := -std=c99 -Wall -Wextra -Wpedantic -I$(SRC_DIR) \ + -D_POSIX_C_SOURCE=200809L -O1 -g -fsanitize=address,undefined \ + -fno-omit-frame-pointer sanitizer: LDFLAGS := -fsanitize=address,undefined sanitizer: test -# The unit test links the parts it tests, not the command line, so that a -# broken argument parser cannot hide a working matcher (or the other way round). -$(UNIT): tests/unit.c src/util.o src/glob.o src/policy.o - $(CC) $(STD) $(WARN) $(CPPFLAGS) $(CFLAGS) -o $@ tests/unit.c \ - src/util.o src/glob.o src/policy.o - -test: $(PROG) $(UNIT) - mkdir -p tests/tmp - $(UNIT) - AUTHZ=./$(PROG) sh tests/run.sh - -# The hook is a symlink to the program, named 'pre-receive', because that name -# is what core.hooksPath looks for and what selects authorize mode inside the -# binary. The link is relative so that a staged install, an unpacked prefix and -# the image built from either all resolve to the binary that came with them -# rather than to whatever lives at the same absolute path on the reading side. +# The same build with the warnings turned into errors, so that CI proves the +# tree is clean rather than merely quiet. +.PHONY: strict +strict: CFLAGS += -Werror +strict: all + +.PHONY: all +all: $(PROG) $(TST_RUN) + +# The hook is a symlink named 'pre-receive', because that name is what +# core.hooksPath looks for and what selects authorize mode inside the binary. +# It is relative so that a staged install, an unpacked prefix or an image +# assembled elsewhere points at the binary that came with it rather than at +# whatever occupies that absolute path on the machine reading it. # # The policy is configuration: an existing one is an operator's file, so it is # kept and the new one arrives beside it as authz.conf.new. +PREFIX ?= /usr/local +BINDIR ?= $(PREFIX)/bin +SHAREDIR ?= $(PREFIX)/share/git-host +SYSCONFDIR ?= /etc/git-host +HOOKDIR ?= $(SHAREDIR)/hooks + +.PHONY: install install: $(PROG) install -d $(DESTDIR)$(BINDIR) $(DESTDIR)$(HOOKDIR) $(DESTDIR)$(SYSCONFDIR) install -m 0755 $(PROG) $(DESTDIR)$(BINDIR)/$(PROG) @@ -81,11 +92,12 @@ install: $(PROG) ln -s "$$link" $(DESTDIR)$(HOOKDIR)/pre-receive; \ echo " $(HOOKDIR)/pre-receive -> $$link" +.PHONY: uninstall uninstall: rm -f $(DESTDIR)$(BINDIR)/$(PROG) $(DESTDIR)$(HOOKDIR)/pre-receive +.PHONY: clean clean: - rm -f $(OBJS) $(PROG) $(UNIT) - rm -rf tests/tmp - -.PHONY: all test install uninstall clean + @$(RM) -rf obj/ + @$(RM) -rf $(TST_DIR)/tmp + @$(RM) $(PROG) |
