mirror of
https://github.com/foxcpp/maddy.git
synced 2025-04-05 22:17:39 +03:00
Add Makefile to replace build.sh
This commit is contained in:
parent
f44201603b
commit
13b0accf90
4 changed files with 123 additions and 0 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -24,6 +24,12 @@ _testmain.go
|
||||||
cmd/maddy/maddy
|
cmd/maddy/maddy
|
||||||
cmd/maddyctl/maddyctl
|
cmd/maddyctl/maddyctl
|
||||||
cmd/maddy-*-helper/maddy-*-helper
|
cmd/maddy-*-helper/maddy-*-helper
|
||||||
|
maddy
|
||||||
|
maddyctl
|
||||||
|
|
||||||
|
# Man pages
|
||||||
|
docs/man/*.1
|
||||||
|
docs/man/*.5
|
||||||
|
|
||||||
# Certificates and private keys.
|
# Certificates and private keys.
|
||||||
*.pem
|
*.pem
|
||||||
|
|
89
Makefile
Normal file
89
Makefile
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
SHELL := bash
|
||||||
|
.OHESHELL:
|
||||||
|
#.SHELLFLAGS := -eu -o pipefail
|
||||||
|
.DELETE_ON_ERROR:
|
||||||
|
MAKEFLAGS += --warn-undefined-variables
|
||||||
|
MAKEFLAGS += --no-builtin-rules
|
||||||
|
|
||||||
|
# Install configuration
|
||||||
|
DESTDIR ?= /
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
SYSTEMDUNITS ?= $(PREFIX)/lib/systemd
|
||||||
|
FAIL2BANDIR ?= /etc/fail2ban
|
||||||
|
|
||||||
|
# Build configuration
|
||||||
|
TAGS ?= ""
|
||||||
|
LDFLAGS ?= "-Wl,-z,relro,-z,now"
|
||||||
|
CGO_LDFLAGS ?= $(LDFLAGS)
|
||||||
|
|
||||||
|
# Compiled into maddy{,ctl} executables.
|
||||||
|
MADDY_VER ?= $(shell ./git-version.sh)
|
||||||
|
CONFIGDIR ?= /etc/maddy
|
||||||
|
STATEDIR ?= /var/lib/maddy
|
||||||
|
RUNTIMEDIR ?= /run/maddy
|
||||||
|
|
||||||
|
.PHONY: all test check install man-pages clean
|
||||||
|
|
||||||
|
all: cmd/maddy/maddy cmd/maddyctl/maddyctl man-pages
|
||||||
|
|
||||||
|
man-pages:
|
||||||
|
@$(MAKE) -s $(shell find docs/man -name '*.scd' | sed 's/.scd//')
|
||||||
|
|
||||||
|
# Manual pages
|
||||||
|
%.1: %.1.scd
|
||||||
|
@echo '-- Generating $<'
|
||||||
|
@scdoc < $< > $@
|
||||||
|
|
||||||
|
%.5: %.5.scd
|
||||||
|
@echo '-- Generating $<'
|
||||||
|
@scdoc < $< > $@
|
||||||
|
|
||||||
|
cmd/maddy/maddy: $(shell find -name '*.go' -or -name '*.c' -or -name '*.h')
|
||||||
|
@echo '-- Building maddy...'
|
||||||
|
@go build -trimpath -buildmode=pie -tags "$(TAGS)" \
|
||||||
|
-ldflags "-extldflags \"$(LDFLAGS)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.DefaultLibexecDirectory=$(PREFIX)/lib/maddy\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.DefaultStateDirectory=$(STATEDIR)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.DefaultRuntimeDirectory=$(RUNTIMEDIR)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.ConfigDirectory=$(CONFIGDIR)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.Version=$(MADDY_VER)\"" \
|
||||||
|
-o $@ ./cmd/maddy
|
||||||
|
|
||||||
|
cmd/maddyctl/maddyctl: $(shell find -name '*.go' -or -name '*.c' -or -name '*.h')
|
||||||
|
@echo '-- Building maddyctl...'
|
||||||
|
@go build -trimpath -buildmode=pie -tags "$(TAGS)" \
|
||||||
|
-ldflags "-extldflags \"$(LDFLAGS)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.DefaultLibexecDirectory=$(PREFIX)/lib/maddy\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.DefaultStateDirectory=$(STATEDIR)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.DefaultRuntimeDirectory=$(RUNTIMEDIR)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.ConfigDirectory=$(CONFIGDIR)\" \
|
||||||
|
-X \"github.com/foxcpp/maddy.Version=$(MADDY_VER)\"" \
|
||||||
|
-o $@ ./cmd/maddyctl
|
||||||
|
|
||||||
|
lint:
|
||||||
|
@golangci-lint run
|
||||||
|
|
||||||
|
check:
|
||||||
|
@echo '-- Running unit tests...'
|
||||||
|
@go test -count 3 -race ./...
|
||||||
|
@echo '-- Running integration tests...'
|
||||||
|
@cd tests && ./run.sh
|
||||||
|
|
||||||
|
install: cmd/maddy/maddy cmd/maddyctl/maddyctl man-pages
|
||||||
|
install -Dm 0755 -t "$(DESTDIR)/$(PREFIX)/bin" cmd/maddy/maddy cmd/maddyctl/maddyctl
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(PREFIX)/share/man/man1" docs/man/*.1
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(PREFIX)/share/man/man5" docs/man/*.5
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(PREFIX)/share/vim/vimfiles/ftdetect/" dist/vim/ftdetect/*.vim
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(PREFIX)/share/vim/vimfiles/ftplugin/" dist/vim/ftplugin/*.vim
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(PREFIX)/share/vim/vimfiles/syntax/" dist/vim/syntax/*.vim
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(FAIL2BANDIR)/jail.d/" dist/fail2ban/jail.d/*
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(FAIL2BANDIR)/filter.d/" dist/fail2ban/filter.d/*
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(SYSTEMDUNITS)/system/" dist/systemd/*
|
||||||
|
@sed -Ei "s!/usr/bin!$(PREFIX)/bin!g;\
|
||||||
|
s!/usr/lib/maddy!$(PREFIX)/lib/maddy!g;\
|
||||||
|
s!/etc/maddy!$(CONFIGDIR)!g" "$(DESTDIR)/$(SYSTEMDUNITS)/system/"*.service
|
||||||
|
install -Dm 0644 -t "$(DESTDIR)/$(CONFIGDIR)/" maddy.conf
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f cmd/maddy/maddy cmd/maddyctl/maddyctl
|
||||||
|
@rm -f docs/man/*.1 docs/man/*.5
|
2
build.sh
2
build.sh
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo '!!! build.sh script is deprecated and will be removed in the next release.'
|
||||||
|
|
||||||
options=$(getopt -o hb:p:d: -l help,builddir:,prefix:,destdir:,systemddir:,configdir:,statedir:,runtimedir:,fail2bandir:,tags:,prefix:,gitversion:,version:,source:,sudo -- "$@")
|
options=$(getopt -o hb:p:d: -l help,builddir:,prefix:,destdir:,systemddir:,configdir:,statedir:,runtimedir:,fail2bandir:,tags:,prefix:,gitversion:,version:,source:,sudo -- "$@")
|
||||||
eval set -- "$options"
|
eval set -- "$options"
|
||||||
print_help() {
|
print_help() {
|
||||||
|
|
26
git-version.sh
Executable file
26
git-version.sh
Executable file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
DESCR=$(git describe --long 2>/dev/null)
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "source-build"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
set -e
|
||||||
|
|
||||||
|
MADDY_MAJOR=$(sed 's/^v//' <<<$DESCR | cut -f1 -d '.')
|
||||||
|
MADDY_MINOR=$(cut -f2 -d '.' <<<$DESCR )
|
||||||
|
|
||||||
|
MADDY_PATCH=$(cut -f1 -d '-' <<<$DESCR | sed 's/-.+//' | cut -f3 -d '.')
|
||||||
|
MADDY_SNAPSHOT=$(cut -f2 -d '-' <<<$DESCR)
|
||||||
|
MADDY_COMMIT=$(cut -f3 -d '-' <<<$DESCR)
|
||||||
|
|
||||||
|
if [ $MADDY_SNAPSHOT -ne 0 ]; then
|
||||||
|
(( MADDY_MINOR++ ))
|
||||||
|
MADDY_PATCH=0
|
||||||
|
|
||||||
|
MADDY_VER="$MADDY_MAJOR.$MADDY_MINOR.$MADDY_PATCH-dev$MADDY_SNAPSHOT+$MADDY_COMMIT"
|
||||||
|
else
|
||||||
|
MADDY_VER="$MADDY_MAJOR.$MADDY_MINOR.$MADDY_PATCH+$MADDY_COMMIT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $MADDY_VER
|
Loading…
Add table
Add a link
Reference in a new issue