-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
137 lines (122 loc) · 4.99 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
export PREFIX ?= /usr
export MKDIR ?= mkdir -p
export DOCDIR ?= $(DESTDIR)$(PREFIX)/share/man
LOGDIR ?= $(DESTDIR)/var/log/cmail
CONFDIR ?= $(DESTDIR)/etc/cmail
DBDIR ?= $(DESTDIR)$(CONFDIR)/databases
BANNER ?= $(shell hostname)
TLSKEY ?= temp.key
TLSCERT ?= temp.cert
.PHONY: clean install init tls-init rtldumps
all:
@$(MAKE) -C cmail-smtpd
@$(MAKE) -C cmail-dispatchd
@$(MAKE) -C cmail-popd
@$(MAKE) -C cmail-imapd
@$(MAKE) -C cmail-admin
$(MKDIR) bin
@mv cmail-smtpd/cmail-smtpd bin/
@mv cmail-dispatchd/cmail-dispatchd bin/
@mv cmail-popd/cmail-popd bin/
# mv cmail-imapd/cmail-imapd bin/
install:
@printf "Installing to %s%s\n" "$(DESTDIR)" "$(PREFIX)"
install -m 0755 bin/* "$(DESTDIR)$(PREFIX)/sbin"
$(MAKE) -C cmail-admin install
install-doc:
$(MAKE) -C doc install
$(MAKE) -C cmail-admin install-doc
uninstall:
@printf "Removing daemon binaries from %s%s\n" "$(DESTDIR)" "$(PREFIX)"
$(RM) $(DESTDIR)$(PREFIX)/sbin/cmail-smtpd
$(RM) $(DESTDIR)$(PREFIX)/sbin/cmail-dispatchd
$(RM) $(DESTDIR)$(PREFIX)/sbin/cmail-popd
#remove legacy binaries
$(RM) $(DESTDIR)$(PREFIX)/sbin/cmail-msa
$(RM) $(DESTDIR)$(PREFIX)/sbin/cmail-mta
$(MAKE) -C cmail-admin uninstall
init:
@printf "*** Testing for sqlite3 CLI binary\n"
@sqlite3 --version
@printf "\n*** Creating cmail user\n"
-adduser --disabled-login --system --group --quiet cmail
@printf "\n*** Creating configuration directories\n"
$(MKDIR) "$(LOGDIR)"
$(MKDIR) "$(CONFDIR)"
$(MKDIR) "$(DBDIR)"
chown root:cmail "$(DBDIR)"
chmod 770 "$(DBDIR)"
@printf "\n*** Copying example configuration files to %s\n" "$(CONFDIR)"
cp example-configs/*.conf.src "$(CONFDIR)"
@printf "\n*** Updating the sample configuration files with dynamic defaults\n"
sed -e 's,LOGFILE,$(LOGDIR)/cmail-smtpd.log,' -e 's,MASTERDB,$(DBDIR)/master.db3,' "$(CONFDIR)/smtpd.conf.src" > $(CONFDIR)/smtpd.conf
sed -e 's,LOGFILE,$(LOGDIR)/cmail-dispatchd.log,' -e 's,MASTERDB,$(DBDIR)/master.db3,' "$(CONFDIR)/dispatchd.conf.src" > $(CONFDIR)/dispatchd.conf
sed -e 's,LOGFILE,$(LOGDIR)/cmail-popd.log,' -e 's,MASTERDB,$(DBDIR)/master.db3,' "$(CONFDIR)/popd.conf.src" > $(CONFDIR)/popd.conf
@printf "\n*** Updating announce hostname to %s\n" "$(BANNER)"
sed -i -e 's,BANNER,$(BANNER),g' "$(CONFDIR)/smtpd.conf" "$(CONFDIR)/dispatchd.conf" "$(CONFDIR)/popd.conf"
@printf "\n*** Creating empty master database in %s/master.db3\n" "$(DBDIR)"
cat sql-update/install_master.sql | sqlite3 "$(DBDIR)/master.db3"
chown root:cmail "$(DBDIR)/master.db3"
chmod 770 "$(DBDIR)/master.db3"
tls-init: init
@printf "\n*** Creating certificate storage directory in %s/keys\n" "$(CONFDIR)"
$(MKDIR) "$(CONFDIR)/keys"
chmod 700 "$(CONFDIR)/keys"
ifeq ($(TLSKEY),temp.key)
@printf "\n*** Creating temporary TLS certificate in %s/keys\n" "$(CONFDIR)"
openssl req -x509 -newkey rsa:8192 -keyout "$(CONFDIR)/keys/temp.key" -out "$(CONFDIR)/keys/temp.cert" -days 100 -nodes
endif
-chmod 600 "$(CONFDIR)/keys"/*
@printf "\n*** Updating the configuration files in %s\n" "$(CONFDIR)"
sed -i -e 's,TLSCERT,$(CONFDIR)/keys/$(TLSCERT),' -e 's,TLSKEY,$(CONFDIR)/keys/$(TLSKEY),' -e 's,#cert,cert,g' "$(CONFDIR)/smtpd.conf"
sed -i -e 's,TLSCERT,$(CONFDIR)/keys/$(TLSCERT),' -e 's,TLSKEY,$(CONFDIR)/keys/$(TLSKEY),' -e 's,#cert,cert,g' "$(CONFDIR)/popd.conf"
uninit:
@printf "\n*** Removing databases from %s\n" "$(DBDIR)"
$(RM) -r $(DBDIR)
@printf "\n*** Removing logfiles from %s\n" "$(LOGDIR)"
$(RM) -r $(LOGDIR)
@printf "\n*** Removing configuration data from %s\n" "$(CONFDIR)"
$(RM) -r $(CONFDIR)
@printf "\n*** Removing cmail user\n"
userdel cmail
rtldumps:
@-rm -rf rtldumps
$(MAKE) CC=gcc CFLAGS=-fdump-rtl-expand -C cmail-smtpd
$(MAKE) CC=gcc CFLAGS=-fdump-rtl-expand -C cmail-dispatchd
$(MAKE) CC=gcc CFLAGS=-fdump-rtl-expand -C cmail-popd
$(MKDIR) rtldumps
mv cmail-smtpd/*.expand rtldumps/
mv cmail-dispatchd/*.expand rtldumps/
mv cmail-popd/*.expand rtldumps/
coverage-build:
$(MAKE) CC=gcc CFLAGS="-fprofile-arcs -ftest-coverage" -C cmail-smtpd
$(MAKE) CC=gcc CFLAGS="-fprofile-arcs -ftest-coverage" -C cmail-dispatchd
$(MAKE) CC=gcc CFLAGS="-fprofile-arcs -ftest-coverage" -C cmail-popd
$(MKDIR) bin
@mv cmail-smtpd/cmail-smtpd bin/
@mv cmail-dispatchd/cmail-dispatchd bin/
@mv cmail-popd/cmail-popd bin/
# mv cmail-imapd/cmail-imapd bin/
$(MKDIR) tests/coverage/gcov
@mv cmail-smtpd/smtpd.gcno tests/coverage/gcov
@mv cmail-popd/popd.gcno tests/coverage/gcov
@mv cmail-dispatchd/dispatchd.gcno tests/coverage/gcov
# @mv cmail-imapd/imapd.gcno tests/coverage/gcov
cppcheck:
@printf "Running cppcheck on cmail-smtpd\n"
cppcheck --enable=all cmail-smtpd/smtpd.c
@printf "\nRunning cppcheck on cmail-dispatchd\n"
cppcheck --enable=all cmail-dispatchd/dispatchd.c
@printf "\nRunning cppcheck on cmail-popd\n"
cppcheck --enable=all cmail-popd/popd.c
clean:
$(RM) bin/*
@$(MAKE) -C cmail-smtpd clean
@$(MAKE) -C cmail-dispatchd clean
@$(MAKE) -C cmail-popd clean
@$(MAKE) -C cmail-imapd clean
@$(MAKE) -C cmail-admin clean
@$(MAKE) -C doc clean
cleanup-bins:
$(RM) $(which cmail-mta)
$(RM) $(which cmail-msa)