This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
200 lines (164 loc) · 5.88 KB
/
Makefile
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
#
# MIT License
#
# Copyright (c) 2016, 2017, 2018 Nicola Worthington <nicolaw@tfb.net>.
#
name := blip
libname := $(name).bash
manpages := $(libname).3 $(libname).7
markdown := $(manpages:=.md)
specfile := $(name).spec
SHELL = /bin/sh
SED = sed
GPG = gpg
GREP = grep
TAR = tar
MV = mv
CP = cp
LN = ln
TR = tr
INSTALL = install
POD2MAN = pod2man
MD2MAN = go-md2man
GIT_DESCRIBE := git describe --long --always --abbrev=4 --match=v* --dirty=~dirty --tags
GIT_VERSION := $(strip $(shell $(GIT_DESCRIBE) 2>/dev/null))
ifeq ($(GIT_VERSION),)
-include version.mk
endif
comma:= ,
empty:=
space:= $(empty) $(empty)
vcsahead := $(word $(shell echo $$(( $(words $(subst -, ,$(GIT_VERSION))) - 1 )) ),$(subst -, ,$(GIT_VERSION)))
vcstag := $(subst $(space),-,$(wordlist 1,$(shell echo $$(( $(words $(subst -, ,$(GIT_VERSION))) - 2 )) ),$(subst -, ,$(GIT_VERSION))))
vcsshortref := $(firstword $(subst ~, ,$(lastword $(subst -, ,$(GIT_VERSION)))))
vcsdirty := $(findstring ~dirty,$(GIT_VERSION))
version := $(vcstag:v%=%)
versionmajor := $(word 1, $(subst ., ,$(version)))
versionminor := $(word 2, $(subst ., ,$(version)))
versionpatch := $(word 3, $(subst ., ,$(version)))
release := 1
#debdistro := $(shell lsb_release -is | $(TR) 'A-Z' 'a-z')
makefile := $(abspath $(lastword $(MAKEFILE_LIST)))
srcdir := $(dir $(makefile))
builddir := $(name)-$(version)
gpgkeyid := 6393F646
gpgsign := $(subst $(gpgkeyid),true,$(findstring $(gpgkeyid),$(shell $(GPG) --list-secret-keys)))
prefix = /usr/local
bindir = $(prefix)/bin
libdir = $(prefix)/lib
sharedir = $(prefix)/share
docsdir = $(sharedir)/doc/blip
mandir = $(sharedir)/man
man3dir = $(mandir)/man3
man7dir = $(mandir)/man7
DISTTAR := $(name)-$(version)$(vcsdirty).tar.gz
DISTRPM := $(name)-$(version)-$(release)$(vcsdirty).noarch.rpm
#DISTDEBTAR := $(name)_$(version)$(debdistro)$(release).orig.tar.gz
#DISTDEB := $(name)_$(version)$(debdistro)_all.deb
DISTDEBTAR := $(name)_$(version).orig.tar.gz
DISTDEB := $(name)_$(version)_all.deb
TARGETS := $(libname) $(manpages)
all: $(TARGETS)
clean:
$(RM) $(TARGETS)
veryclean: distclean clean
$(RM) version.mk
distclean: clean
$(RM) $(DISTTAR) $(DISTDEB) $(DISTRPM) $(DISTDEBTAR) *.gz *.xz *.dsc *.changes *.build *.rpm *.deb
$(RM) -r $(builddir)
$(builddir): | version.mk
mkdir $(builddir)
$(CP) -r version.mk $(specfile) $(libname).in Makefile CONTRIBUTORS RPM-GPG-KEY-nicolaw LICENSE *.md debian/ examples/ tests/ $@/
release:
mkdir $@
release/$(version): | release
mkdir $@
stash: $(DISTTAR) $(DISTRPM) $(DISTDEB) | release/$(version)
$(CP) -rpv $(name)_$(version)* $(name)-$(version)* release/$(version)
dist: $(DISTTAR) $(DISTRPM) $(DISTDEB)
$(DISTTAR): $(builddir)
$(TAR) -zcf $@ $(builddir)
$(libname): $(libname).in
$(SED) -e "s/@VERSION_MAJOR@/$(versionmajor)/g" \
-e "s/@VERSION_MINOR@/$(versionminor)/g" \
-e "s/@VERSION_PATCH@/$(versionpatch)/g" \
-e "s/@VERSION_TAG@/$(vcsshortref)$(vcsdirty)/g" \
$< > $@
version.mk:
echo -n "GIT_VERSION := " > $@
$(GIT_DESCRIBE) >> $@
vcsinfo:
@echo "vcsahead=>$(vcsahead)<"
@echo "vcstag=>$(vcstag)<"
@echo "vcsshortref=>$(vcsshortref)<"
@echo "vcsdirty=>$(vcsdirty)<"
@echo "version=>$(version)<"
@echo "versionmajor=>$(versionmajor)<"
@echo "versionminor=>$(versionminor)<"
@echo "versionpatch=>$(versionpatch)<"
@echo "release=>$(release)<"
debian/changelog:
git-dch --debian-branch=master --debian-tag="v%(version)s" --id-length=4 --distribution=xenial
# git-dch --debian-branch=master --debian-tag="v%(version)s" --id-length=4 --distribution=$$(lsb_release -cs)
# $(srcdir)/gitversion.sh -d .git -p $(name) -S -l deb > $@
# TODO: Fix automated generation of both RPM and DEB changelogs again.
#$(specfile): $(specfile).in
# $(CP) $< $@
# #$(srcdir)/gitversion.sh -d .git -p $(name) -S -l rpm >> $@
$(libname).3: $(libname).3.md
$(MD2MAN) -in $< -out $@
$(libname).7: CMDARG.md
$(MD2MAN) -in $< -out $@
#$(manpages): %: %.md
# $(MD2MAN) -in $< -out $@
#$(manpage): $(libname).pod
# $(POD2MAN) \
# --name="$(shell echo $libname | tr A-Z a-z)" \
# --release="$(libname) $(version)" \
# --center="$(libname)" \
# --section=3 \
# --utf8 $< > $@
$(DISTDEBTAR): $(DISTTAR)
$(LN) -f $< $@
deb: $(DISTDEB)
$(DISTDEB): debian/changelog $(DISTDEBTAR) $(builddir)
cd $(builddir) && debuild -sa -us -uc -i -I
dpkg-deb -I $@
dpkg-deb -c $@
ifeq ($(gpgsign),true)
echo bacon
cd $(builddir) && debuild -sa -i -I -k$(gpgkeyid) -S
endif
rpm: $(DISTRPM)
$(DISTRPM): $(specfile) $(DISTTAR)
rpmbuild -ba "$(specfile)" \
--define "name $(name)" \
--define "version $(version)" \
--define "release $(release)$(vcsdirty)" \
--define "dirty $(vcsdirty)" \
$(subst true,--sign,$(gpgsign)) \
--define "_sourcedir $(srcdir)" \
--define "_rpmdir $(srcdir)" \
--define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm"
rpm -qpil $@
test: $(libname) $(manpages)
@bash tests/tests.sh
@bash -c 'if type -P bash-4.4.0-1 ; then bash-4.4.0-1 tests/tests.sh ; fi'
@bash -c 'if type -P bash-4.3.0-1 ; then bash-4.3.0-1 tests/tests.sh ; fi'
@bash -c 'if type -P bash-4.2.0-1 ; then bash-4.2.0-1 tests/tests.sh ; fi'
@bash -c 'if type -P bash-4.1.0-1 ; then bash-4.1.0-1 tests/tests.sh ; fi'
@bash -c 'if type -P bash-4.0.0-1 ; then bash-4.0.0-1 tests/tests.sh "bash40_nounset_bug_workaround" ; fi'
install:
$(INSTALL) -m 0755 -d "$(DESTDIR)$(libdir)"
$(INSTALL) -m 0755 -d "$(DESTDIR)$(man3dir)"
$(INSTALL) -m 0755 -d "$(DESTDIR)$(man7dir)"
$(INSTALL) -m 0755 -d "$(DESTDIR)$(docsdir)/tests"
$(INSTALL) -m 0755 -d "$(DESTDIR)$(docsdir)/examples"
$(INSTALL) -m 0644 $(libname) "$(DESTDIR)$(libdir)"
$(INSTALL) -m 0644 *.3 "$(DESTDIR)$(man3dir)"
$(INSTALL) -m 0644 *.7 "$(DESTDIR)$(man7dir)"
$(INSTALL) -m 0644 README.* "$(DESTDIR)$(docsdir)"
$(INSTALL) -m 0644 *.md "$(DESTDIR)$(docsdir)"
$(INSTALL) -m 0644 tests/* "$(DESTDIR)$(docsdir)/tests"
$(INSTALL) -m 0644 examples/* "$(DESTDIR)$(docsdir)/examples"
.PHONY: all dist test install clean distclean deb rpm vcsinfo stash