forked from mcdope/pam_usb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
205 lines (167 loc) · 6 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
200
201
202
203
204
205
# Set to 'yes' to include debugging information, e.g. DEBUG=yes make -e
DEBUG := no
PREFIX ?= /usr
ARCH := $(shell uname -m)
UID := $(shell id -u)
GID := $(shell id -g)
USE_FEDORA_LIBDIR := $(shell test -d /lib64/security && echo 1 || echo 0)
VERSION := $(shell git for-each-ref --sort=creatordate --format '%(tag)' refs/tags | tail -n 1).$(shell git rev-list --count $(shell git for-each-ref --sort=creatordate --format '%(tag)' refs/tags | tail -n 1)..HEAD)
ifeq ($(ARCH), x86_64)
ifeq ($(USE_FEDORA_LIBDIR), 1)
LIBDIR ?= lib64
else
LIBDIR ?= lib/x86_64-linux-gnu
endif
endif
ifeq ($(ARCH), i686)
LIBDIR ?= lib
endif
# compiler/linker options
CC := gcc
CFLAGS := $(CFLAGS) -Wall -fPIC `pkg-config --cflags libxml-2.0` \
`pkg-config --cflags udisks2`
LIBS := `pkg-config --libs libxml-2.0` \
`pkg-config --libs udisks2`
# common source files
SRCS := src/conf.c \
src/mem.c \
src/log.c \
src/xpath.c \
src/pad.c \
src/volume.c \
src/process.c \
src/tmux.c \
src/local.c \
src/device.c
OBJS := $(SRCS:.c=.o)
# pam_usb
PAM_USB_SRCS := src/pam.c
PAM_USB_OBJS := $(PAM_USB_SRCS:.c=.o)
PAM_USB := pam_usb.so
PAM_USB_LDFLAGS := -shared
PAM_USB_DEST := $(DESTDIR)/$(LIBDIR)/security
# pamusb-check
PAMUSB_CHECK_SRCS := src/pamusb-check.c
PAMUSB_CHECK_OBJS := $(PAMUSB_CHECK_SRCS:.c=.o)
PAMUSB_CHECK := pamusb-check
# Tools
PAMUSB_CONF := pamusb-conf
PAMUSB_AGENT := pamusb-agent
PAMUSB_KEYRING_GNOME := pamusb-keyring-unlock-gnome
TOOLS_DEST := $(DESTDIR)$(PREFIX)/bin
TOOLS_SRC := tools
# Conf
CONFS := doc/pam_usb.conf
CONFS_DEST := $(DESTDIR)/etc/security
# Doc
DOCS := doc/CONFIGURATION doc/QUICKSTART
DOCS_DEST := $(DESTDIR)$(PREFIX)/share/doc/pam_usb
# Man
MANS := doc/pamusb-conf.1.gz doc/pamusb-agent.1.gz doc/pamusb-check.1.gz doc/pamusb-keyring-unlock-gnome.1.gz
MANS_DEST := $(DESTDIR)$(PREFIX)/share/man/man1
# PAM config
PAM_CONF := debian/pam-auth-update/usb
PAM_CONF_DEST := $(DESTDIR)$(PREFIX)/share/pam-configs
# Binaries
RM := rm
INSTALL := install
MKDIR := mkdir
DEBUILD := debuild -b -uc -us --lintian-opts --profile debian
RPMBUILD := rpmbuild -v -bb --clean fedora/SPECS/pam_usb.spec
ZSTBUILD := cd arch_linux && makepkg && cd ..
MANCOMPILE := gzip -kf
DOCKER := docker
ifeq (yes, ${DEBUG})
CFLAGS := ${CFLAGS} -ggdb
endif
all : manpages $(PAM_USB) $(PAMUSB_CHECK)
$(PAM_USB) : $(OBJS) $(PAM_USB_OBJS)
$(CC) -o $(PAM_USB) $(PAM_USB_LDFLAGS) $(LDFLAGS) $(OBJS) $(PAM_USB_OBJS) $(LIBS)
$(PAMUSB_CHECK) : $(OBJS) $(PAMUSB_CHECK_OBJS)
$(CC) -o $(PAMUSB_CHECK) $(LDFLAGS) $(OBJS) $(PAMUSB_CHECK_OBJS) $(LIBS)
%.o : %.c
${CC} -c ${CFLAGS} $< -o $@
clean :
$(RM) -f $(MANS) $(PAM_USB) $(PAMUSB_CHECK) $(OBJS) $(PAMUSB_CHECK_OBJS) $(PAM_USB_OBJS)
manpages:
$(MANCOMPILE) ./doc/*.1
install : all
$(MKDIR) -p $(CONFS_DEST) $(DOCS_DEST) $(MANS_DEST) $(TOOLS_DEST) $(PAM_USB_DEST)
$(INSTALL) -m755 $(PAM_USB) $(PAM_USB_DEST)
$(INSTALL) -m755 $(PAMUSB_CHECK) $(TOOLS_SRC)/$(PAMUSB_CONF) $(TOOLS_SRC)/$(PAMUSB_AGENT) $(TOOLS_SRC)/$(PAMUSB_KEYRING_GNOME) $(TOOLS_DEST)
$(INSTALL) -b -m644 $(CONFS) $(CONFS_DEST)
$(INSTALL) -m644 $(DOCS) $(DOCS_DEST)
$(INSTALL) -m644 $(MANS) $(MANS_DEST)
if test -d $(PAM_CONF_DEST); then $(INSTALL) -m644 $(PAM_CONF) $(PAM_CONF_DEST)/libpam-usb; fi
deinstall :
$(RM) -f $(PAM_USB_DEST)/$(PAM_USB)
$(RM) -f $(TOOLS_DEST)/$(PAMUSB_CHECK) $(TOOLS_DEST)/$(PAMUSB_CONF) $(TOOLS_DEST)/$(PAMUSB_AGENT) $(TOOLS_DEST)/$(PAMUSB_KEYRING_GNOME) $(PAM_CONF_DEST)/$(PAM_CONF)
$(RM) -rf $(DOCS_DEST)
$(RM) -f $(MANS_DEST)/pamusb-*\.1\.gz
$(RM) -f $(PAM_CONF_DEST)/$(PAM_CONF)
changelog :
git log --pretty=format:"%h %ad%x09%an%x09%s" --date=short 40b17fa..HEAD > changelog-from-v0.5.0
debchangelog :
git log --pretty=format:" * %s (%an <%ae>)" --date=short 40b17fa..HEAD > changelog-for-deb
builddir :
mkdir -p .build > /dev/null 2>&1 || echo 0
deb : clean builddir
$(DEBUILD)
deb-sign : build-debian
debsign -S -k$(APT_SIGNING_KEY) `ls -t .build/*.changes | head -1`
rpm : clean builddir
$(RPMBUILD)
yes | cp -rf fedora/RPMS/$(ARCH)/*.rpm .build
rpm-sign: build-fedora
rpm --addsign `ls -t .build/*.rpm | head -1`
rpm-lint: build-fedora
rpmlint `ls -t .build/*.rpm | head -1`
zst: clean builddir sourcegz
rm -f arch_linux/*.zst ../pamusb.tar.gz
mv .build/pam_usb-$(VERSION).tar.gz arch_linux/pamusb.tar.gz
$(ZSTBUILD)
yes | cp -rf arch_linux/*.zst .build
rm -rf arch_linux/src arch_linux/pkg arch_linux/pamusb.tar.gz arch_linux/*.zst
sourcegz: clean builddir
tar --exclude="debian/.debhelper" \
--exclude="debian/files" \
--exclude="debian/libpam-usb/*" \
--exclude="debian/libpam-usb.debhelper.log" \
--exclude="debian/libpam-usb.substvars" \
--exclude="debian/debhelper-build-stamp" \
--exclude="debian/libpam-usb.postinst.debhelper" \
--exclude="debian/libpam-usb.postrm.debhelper" \
--exclude="debian/libpam-usb.prerm.debhelper" \
--exclude="fedora/RPMS/x86_64" \
--exclude="fedora/BUILD/*" \
--exclude="tests" \
--exclude=".build" \
--exclude=".idea" \
--exclude=".vscode" \
--exclude=".github" \
--exclude=".git" \
-zcvf .build/pam_usb-$(VERSION).tar.gz .
buildenv-debian :
$(DOCKER) build -f Dockerfile.debian -t mcdope/pam_usb-ubuntu-build .
buildenv-fedora :
$(DOCKER) build -f Dockerfile.fedora -t mcdope/pam_usb-fedora-build .
buildenv-arch :
$(DOCKER) build -f Dockerfile.arch -t mcdope/pam_usb-arch-build .
build-debian : buildenv-debian
$(DOCKER) run -i \
-v`pwd`/.build:/usr/local/src \
-v`pwd`:/usr/local/src/pam_usb \
--rm mcdope/pam_usb-ubuntu-build \
sh -c "make deb && chown -R $(UID):$(GID) .build debian"
build-fedora : buildenv-fedora
$(DOCKER) run -i \
-v`pwd`/.build:/usr/local/src \
-v`pwd`:/usr/local/src/pam_usb \
--rm mcdope/pam_usb-fedora-build \
sh -c "make rpm && chown -R $(UID):$(GID) .build fedora"
build-arch : buildenv-arch
$(DOCKER) run -i \
-v`pwd`/.build:/usr/local/src \
-v`pwd`:/usr/local/src/pam_usb \
--rm mcdope/pam_usb-arch-build \
sh -c "chown -R builduser:builduser . && sudo -u builduser make zst && chown -R $(UID):$(GID) ."