File: Makefile

package info (click to toggle)
signify-openbsd 30-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 560 kB
  • sloc: ansic: 4,311; makefile: 203; sh: 72
file content (258 lines) | stat: -rw-r--r-- 6,715 bytes parent folder | download
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
##################################################################
# The following variables may be overriden in the command line:  #
#                                                                #
BZERO          ?=
MUSL           ?= 0
BUNDLED_LIBBSD ?= 0
PLEDGE         ?= noop
PKG_CONFIG     ?= pkg-config
WGET           ?= wget
libbsd_VERSION ?= 0.10.0
libbsd_BASEURL ?= http://libbsd.freedesktop.org/releases/
#                                                                #
##################################################################

CFLAGS   += $(EXTRA_CFLAGS)
LDFLAGS  += $(EXTRA_LDFLAGS)
CPPFLAGS += -include compat.h

S := crypto_api.c \
     mod_ed25519.c \
	 mod_ge25519.c \
	 fe25519.c \
	 sc25519.c \
	 bcrypt_pbkdf.c \
	 timingsafe_bcmp.c \
	 blowfish.c \
	 base64.c \
	 sha2.c \
	 sha256hl.c \
	 sha512hl.c \
	 sha512_256hl.c \
	 signify.c \
	 zsig.c

define SED_LAST_LINE
sed -n -e '/^[a-zA-Z_-]\+$$/p' | sed -n '$$p'
endef

BZERO := $(strip $(BZERO))
ifeq ($(BZERO),)
  BZERO := $(strip $(shell $(CC) -x c -E -P explicit_bzero.h | $(SED_LAST_LINE)))
endif
ifeq ($(BZERO),bundled)
  CPPFLAGS += -DBUNDLED_BZERO=1
  S += explicit_bzero.c
endif

PLEDGE := $(strip $(PLEDGE))
ifneq ($(PLEDGE),)
    S += pledge_$(PLEDGE).c
endif

MUSL := $(strip $(MUSL))
ifeq ($(MUSL),1)
  CC ?= musl-gcc
  BUNDLED_LIBBSD := 1
endif

BUNDLED_LIBBSD := $(strip $(BUNDLED_LIBBSD))
BUNDLED_LIBBSD_VERIFY_GPG := $(strip $(BUNDLED_LIBBSD_VERIFY_GPG))

ifneq ($(BUNDLED_LIBBSD_VERIFY_GPG),0)
  ifeq ($(BUNDLED_LIBBSD_VERIFY_GPG),)
    # Try to detect whether "gpg" is installed.
    BUNDLED_LIBBSD_VERIFY_GPG := $(shell which gpg 2> /dev/null || echo 0)
  endif
endif


all: signify
clean:


# Building a static binary with Musl requires a few extra steps.
# The rules take care of:
#
#   - Downloading a release (needed tools: wget).
#   - Check the PGP signature (needed tools: gpg).
#   - Unpack the tarball (needed tools: xz, tar).
#   - Build libbsd.
#
# TODO: Also support curl for downloads.
#
ifeq ($(BUNDLED_LIBBSD),1)

libbsd_VERSION  := $(strip $(libbsd_VERSION))
libbsd_BASEURL  := $(strip $(libbsd_BASEURL))
libbsd_TAR_NAME := libbsd-$(libbsd_VERSION).tar.xz
libbsd_TAR_URL  := $(libbsd_BASEURL)/$(libbsd_TAR_NAME)
libbsd_ARLIB    := libbsd-prefix/lib/libbsd.a
libbsd_INCLUDE  := libbsd-prefix/include

ifneq ($(BUNDLED_LIBBSD_VERIFY_GPG),0)
libbsd_ASC_NAME := $(libbsd_TAR_NAME).asc
libbsd_ASC_URL  := $(libbsd_BASEURL)/$(libbsd_ASC_NAME)
$(libbsd_ASC_NAME):
	$(WGET) -cO $@ '$(libbsd_ASC_URL)'
	touch $@
endif

$(libbsd_TAR_NAME): $(libbsd_ASC_NAME)
	$(WGET) -cO $@ '$(libbsd_TAR_URL)'
ifneq ($(BUNDLED_LIBBSD_VERIFY_GPG),0)
	$(BUNDLED_LIBBSD_VERIFY_GPG) --verify $(libbsd_ASC_NAME)
endif
	touch $@

libbsd-download: $(libbsd_TAR_NAME)

libbsd-clean:
	$(RM) -r libbsd-prefix libbsd-$(libbsd_VERSION)

clean: libbsd-clean

libbsd-print-urls:
ifneq ($(BUNDLED_LIBBSD_VERIFY_GPG),0)
	@echo '$(libbsd_ASC_URL)'
endif
	@echo '$(libbsd_TAR_URL)'

libbsd-$(libbsd_VERSION)/configure: $(libbsd_TAR_NAME)
	unxz -c $< | tar -xf -
	touch $@

libbsd-$(libbsd_VERSION)/Makefile: libbsd-$(libbsd_VERSION)/configure
	( cd libbsd-$(libbsd_VERSION) && ./configure \
		--enable-static --disable-shared \
		--prefix=$$(pwd)/../libbsd-prefix \
		CC=$(CC) LD=$(CC) )

$(libbsd_ARLIB) $(libbsd_INCLUDE)/bsd/bsd.h: libbsd-$(libbsd_VERSION)/Makefile
	$(MAKE) -C libbsd-$(libbsd_VERSION) install

.PHONY: libbsd-download libbsd-clean libbsd-print-urls

LIBBSD_DEPS    := libbsd-prefix/lib/libbsd.a
LIBBSD_CFLAGS  := -isystem libbsd-prefix/include
LIBBSD_LDFLAGS :=

$S: $(libbsd_INCLUDE)/bsd/bsd.h

else

LIBBSD_PKG_VERSION := 0.7
LIBBSD_PKG_CHECK   := $(shell $(PKG_CONFIG) libbsd --atleast-version=$(LIBBSD_PKG_VERSION) && echo ok)
ifneq ($(strip $(LIBBSD_PKG_CHECK)),ok)
  $(error libbsd is not installed or version is older than $(LIBBSD_PKG_VERSION))
endif
LIBBSD_DEPS    :=
LIBBSD_CFLAGS  := $(shell $(PKG_CONFIG) libbsd --cflags)
LIBBSD_LDFLAGS := $(shell $(PKG_CONFIG) libbsd --libs)

endif


# In order to use libwaive, we need libseccomp and making sure that the
# Git submodule corresponding to libwaive is properly checked out.
#
ifeq ($(PLEDGE),waive)
SECCOMP_CFLAGS := $(shell $(PKG_CONFIG) libseccomp --cflags)
SECCOMP_LIBS   := $(shell $(PKG_CONFIG) libseccomp --libs)
CFLAGS  += $(SECCOMP_CFLAGS) -pthread
LDFLAGS += $(SECCOMP_LIBS) -pthread
S       += libwaive/waive.c

ifneq ($(wildcard .gitmodules),)
libwaive/waive.c: .gitmodules
	git submodule init && git submodule update libwaive
	touch $@
endif
endif

ifeq ($(strip $(VERIFY_ONLY)),)
S += ohash.c
else
     CPPFLAGS += -DVERIFY_ONLY=1
     $(warning )
     $(warning ******************************************************)
     $(warning )
     $(warning Building with VERIFY_ONLY enabled is unsupported, YMMV)
     $(warning )
     $(warning ******************************************************)
     $(warning )
endif

ifeq ($(strip $(BOUNDS_CHECKING)),1)
    CPPFLAGS += -DCOMPAT_BOUNDS_CHECKING
endif

ifneq ($(strip $(LTO)),)
    CFLAGS += -flto
    LDFLAGS += -flto
endif

O := $(patsubst %.c,%.o,$S)


signify: override CFLAGS += $(LIBBSD_CFLAGS) -Wall
signify: $O $(LIBBSD_DEPS)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBBSD_LDFLAGS) $(LDLIBS)

zsig.o signify.o bcrypt_pbkdf.o: override CFLAGS += -Wno-pointer-sign

clean-signify:
	$(RM) $O signify signify.1.gz sha256hl.c sha512hl.c sha512_256hl.c

clean: clean-signify
.PHONY: clean-signify

signify.1.gz: signify.1
	gzip -9c $< > $@

sha256hl.c: helper.c
	sed -e 's/hashinc/sha2.h/g' \
	    -e 's/HASH/SHA256/g' \
	    -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $< > $@

sha512hl.c: helper.c
	sed -e 's/hashinc/sha2.h/g' \
	    -e 's/HASH/SHA512/g' \
	    -e 's/SHA[0-9][0-9][0-9]_CTX/SHA2_CTX/g' $< > $@

sha512_256hl.c:	helper.c
	sed -e 's/hashinc/sha2.h/g' \
	    -e 's/HASH/SHA512_256/g' \
	    -e 's/SHA512_256_CTX/SHA2_CTX/g' $< > $@

install: signify signify.1.gz
	install -m 755 -d $(DESTDIR)$(PREFIX)/bin
	install -m 755 -t $(DESTDIR)$(PREFIX)/bin signify
	install -m 755 -d $(DESTDIR)$(PREFIX)/share/man/man1
	install -m 644 -t $(DESTDIR)$(PREFIX)/share/man/man1 signify.1.gz

.PHONY: install

ifneq ($(wildcard .git/),)
GIT_TAG  = $(shell git describe --tags HEAD)
dist: T := $(GIT_TAG)
dist: V := $(patsubst v%,%,$T)
dist:
	git archive-all --force-submodules --prefix=signify-$V/ signify-$V.tar
	xz -f9 signify-$V.tar

.PHONY: dist
endif

check: signify
	@sh regress/run

.PHONY: check

static:
	$(MAKE) EXTRA_CFLAGS='$(EXTRA_CFLAGS) -pthread' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS) -pthread -static' BUNDLED_LIBBSD=1

static-musl:
	$(MAKE) EXTRA_CFLAGS='$(EXTRA_CFLAGS) -pthread' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS) -pthread -static' MUSL=1 CC=musl-gcc LD=musl-gcc

.PHONY: static musl-static