THANKS: Cág
[s-mailx.git] / make-config.in
blobe39143eba067c7f0bf0d53ba6c2a0aa64144545f
1 #@ make-config.in -- mk-config.mk template, completed by make-config.sh.
2 #@ Please see INSTALL and make.rc instead.
4 .PHONY: all test install uninstall clean distclean
6 SIZE_CHECK = @if ( command -v size ) > /dev/null 2>&1; then size $(@); fi
8 _version_from_header = VERSION="`< gen-version.h $(sed) \
9                 -e '/ n_VERSION /b X' -e d -e ':X' \
10                 -e 's/[^\"]*\"v\([^\"]\{1,\}\)\"/\1/'`"
12 all: $(VAL_UAGENT) $(OPTIONAL_PRIVSEP)
14 $(VAL_UAGENT): $(OBJ) uman.1 urc.rc
15         $(ECHO_LINK)$(CC) $(LDFLAGS) -o $(@) $(OBJ) $(LIBS)
16         $(SIZE_CHECK)
18 $(OBJ): mk-config.h config.h $(SRCDIR)nail.h $(SRCDIR)nailfuns.h \
19                 $(AMALGAM_DEP)
20 $(AMALGAM_TARGET) auxlily.o: $(SRCDIR)gen-errors.h
21 $(AMALGAM_TARGET) accmacvar.o: $(SRCDIR)gen-okeys.h gen-version.h
22 $(AMALGAM_TARGET) cmd-tab.o: $(SRCDIR)cmd-tab.h
23 $(AMALGAM_TARGET) dotlock.o: $(SRCDIR)dotlock.h
24 $(AMALGAM_TARGET) obs-imap.o: $(SRCDIR)obs-imap-gssapi.h
25 $(AMALGAM_TARGET) mime-types.o: gen-mime-types.h
26 $(AMALGAM_TARGET) obs-imap.o pop3.o smtp.o urlcrecry.o: $(SRCDIR)rfc1321.h
27 $(AMALGAM_TARGET) smtp.o: $(SRCDIR)smtp-gssapi.h
28 $(AMALGAM_TARGET) termcap.o: $(SRCDIR)gen-tcaps.h
30 $(VAL_PRIVSEP): privsep.o
31         $(ECHO_LINK)$(CC) $(LDFLAGS) -o $(@) privsep.o $(BASE_LIBS)
32         $(SIZE_CHECK)
34 privsep.o: $(SRCDIR)privsep.c mk-config.h config.h \
35                 $(SRCDIR)nail.h $(SRCDIR)dotlock.h
36         $(ECHO_CC)$(CC) $(CFLAGS) $(BASE_INCS) -c $(SRCDIR)privsep.c
38 gen-mime-types.h: $(SRCDIR)mime.types
39         $(ECHO_GEN)\
40         LC_ALL=C < $(SRCDIR)mime.types > $(@) $(awk) '\
41         function add(mt, ln){\
42                 gsub(/[[:space:]]+/, " ", ln);\
43                 i = split(ln, i_a);\
44                 e = "";\
45                 for(j = 1; j <= i; ++j){\
46                         k = i_a[j];\
47                         e = (e ? e " " : "") k\
48                 }\
49                 if(e){\
50                         if(e_a[mt])\
51                                 e_a[mt] = e_a[mt] " ";\
52                         e_a[mt] = e_a[mt] e\
53                 }\
54         }\
55         /^[[:space:]]*#/{next}\
56         /^[[:space:]]*$$/{ltype = ""; next}\
57         /^[[:space:]]/{\
58                 if(!ltype)\
59                         print "FAULTY CONTINUATION: " $$0 >> "/dev/stderr";\
60                 add(ltype, $$0);\
61                 next\
62         }\
63         /^(@([thHq]@)? )?[[:alpha:]]/{\
64                 if($$1 ~ /^@([thHq]@)?$$/){\
65                         pa = $$1;\
66                         $$1 = $$2;\
67                         $$2 = ""\
68                 }else\
69                         pa = "";\
70                 if($$1 !~ /^([[:alnum:]]+)\/([[:alnum:]_+-]+)$$/)\
71                         print "FAULTY MIME TYPE: <" $$1 ">" >> "/dev/stderr";\
72                 ltype = $$1; $$1 = "";\
73                 if(pa)\
74                         p_a[ltype] = pa;\
75                 if(!nt_a[ltype])\
76                         no_a[++no_ai] = nt_a[ltype] = ltype;\
77                 add(ltype, $$0)\
78         }\
79         END{\
80                 for(z = 1; z <= no_ai; ++z){\
81                         t = no_a[z];\
82                         j = index(t, "/");\
83                         mt = toupper(substr(t, 1, j - 1));\
84                         j = substr(t, j + 1);\
85                         l = length(j);\
86                         if(!p_a[t])\
87                                 mt = "_MT_" mt;\
88                         else{\
89                                 tm = p_a[t];\
90                                 if(tm == "@" || tm == "@t@")\
91                                         mt = "_MT_" mt " | a_MT_TM_PLAIN";\
92                                 else if(tm == "@h@")\
93                                         mt = "_MT_" mt " | a_MT_TM_SOUP_h";\
94                                 else if(tm == "@H@")\
95                                         mt = "_MT_" mt " | a_MT_TM_SOUP_H";\
96                                 else if(tm == "@q@")\
97                                         mt = "_MT_" mt " | a_MT_TM_QUIET";\
98                         }\
99                         print "   {" mt ", " l ", \"" j e_a[t] "\"},"\
100                 }\
101         }\
102         '
104 uman.1: $(SRCDIR)nail.1
105         $(ECHO_GEN)\
106         LC_ALL=C _SYSCONFRC="$(VAL_SYSCONFRC)" _UAGENT="$(VAL_UAGENT)" \
107                 $(_version_from_header) \
108         < $(SRCDIR)nail.1 > $(@) $(awk) '\
109         BEGIN { written = 0 }\
110         /\.\\"--MKMAN-START--/, /\.\\"--MKMAN-END--/ {\
111                 if (written++ != 0)\
112                         next;\
113                 OFS = "";\
114                 print ".ds VV \\\\%v", ENVIRON["VERSION"];\
115                 \
116                 un = toupper(ENVIRON["_UAGENT"]);\
117                 ln = tolower(un);\
118                 cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
119                 print ".ds UU \\\\%", un;\
120                 print ".ds UA \\\\%", cn;\
121                 print ".ds uA \\\\%", ln;\
122                 \
123                 path = ENVIRON["_SYSCONFRC"];\
124                 gsub("/", "/\\:", path);\
125                 print ".ds UR \\\\%", path;\
126                 OFS = " ";\
127                 next\
128         }\
129         {print}\
130         '
132 urc.rc: $(SRCDIR)nail.rc
133         $(ECHO_GEN)\
134         LC_ALL=C _SYSCONFRC="$(VAL_SYSCONFRC)" _UAGENT="$(VAL_UAGENT)" \
135                 $(_version_from_header) \
136         < $(SRCDIR)nail.rc > $(@) $(awk) 'BEGIN {written = 0}\
137         /^#--MKRC-START--/, /^#--MKRC-END--/ {\
138                 if (written == 1)\
139                         next;\
140                 written = 1;\
141                 OFS = "";\
142                 ln = tolower(ENVIRON["_UAGENT"]);\
143                 cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
144                 print "#@ ", ENVIRON["_SYSCONFRC"];\
145                 print "#@ Configuration file for ", cn, " v",\
146                         ENVIRON["VERSION"];\
147                 OFS = " ";\
148                 next\
149         }\
150         {print}\
151         '
153 install:
154         $(ECHO_BLOCK_BEGIN)\
155         __mkdir() {\
156                 _dir="$(DESTDIR)$${1}";\
157                 if [ -d "$${_dir}" ]; then :; else \
158                         $(mkdir) -m 0755 -p "$${_dir}";\
159                 fi;\
160         };\
161         __copyfile() {\
162                 _mode=$${1} _src=$${2} _xdst=$${3} _dst="$(DESTDIR)$${3}";\
163                 $(cp) -f "$${_src}" "$${_dst}";\
164                 echo "rm -f \"\$${DESTDIR}$${_xdst}\"" >> \
165                         "$(VAL_UAGENT)-uninstall.sh";\
166                 $(chmod) $${_mode} "$${_dst}";\
167                 \
168         };\
169         __copychownfile() {\
170                 _mode=$${1} _ident=$${2} _src=$${3} \
171                         _xdst=$${4} _dst="$(DESTDIR)$${4}";\
172                 $(cp) -f "$${_src}" "$${_dst}";\
173                 echo "rm -f \"\$${DESTDIR}$${_xdst}\"" >> \
174                         "$(VAL_UAGENT)-uninstall.sh";\
175                 $(chown) $${_ident} "$${_dst}" || true;\
176                 $(chmod) $${_mode} "$${_dst}";\
177                 \
178         };\
179         __stripfile() {\
180                 _file=$${1};\
181                 if [ "$(OPT_DEBUG)" != 0 ]; then :;\
182                 elif [ -n "$(HAVE_STRIP)" ]; then \
183                         $(strip) "$${_file}";\
184                 fi;\
185         };\
186         \
187         echo '#!/bin/sh -' > "$(VAL_UAGENT)-uninstall.sh";\
188         echo '#@ Uninstall script for $(VAL_UAGENT)' >> \
189                 "$(VAL_UAGENT)-uninstall.sh";\
190         echo >> "$(VAL_UAGENT)-uninstall.sh";\
191         echo 'DESTDIR="$(DESTDIR)"' >> "$(VAL_UAGENT)-uninstall.sh";\
192         echo 'DESTDIR=' >> "$(VAL_UAGENT)-uninstall.sh";\
193         echo >> "$(VAL_UAGENT)-uninstall.sh";\
194         \
195         if [ -n "$(DESTDIR)" ]; then __mkdir ''; fi;\
196         __mkdir "$(VAL_BINDIR)";\
197         __mkdir "$(VAL_MANDIR)/man1";\
198         __mkdir "$(VAL_SYSCONFDIR)";\
199         \
200         __stripfile "$(VAL_UAGENT)";\
201         __copyfile 0555 "$(VAL_UAGENT)" "$(VAL_BINDIR)/$(VAL_UAGENT)";\
202         __copyfile 0444 ./uman.1 "$(VAL_MANDIR)/man1/$(VAL_UAGENT).1";\
203         if [ -f "$(DESTDIR)$(VAL_SYSCONFDIR)/$(VAL_SYSCONFRC)" ]; then :; else \
204                 __copyfile 0444 ./urc.rc "$(VAL_SYSCONFDIR)/$(VAL_SYSCONFRC)";\
205         fi;\
206         \
207         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
208                 __mkdir "$(VAL_LIBEXECDIR)";\
209                 \
210                 __stripfile "$(VAL_PRIVSEP)";\
211                 m='o=rx' o=;\
212                 if [ -n "$(_____PRIVSEP_GROUP)" ]; then \
213                         m="g=rxs,$${m}" o=":$(VAL_PRIVSEP_GROUP)";\
214                 else \
215                         m="g=rx,$${m}";\
216                 fi;\
217                 if [ -n "$(VAL_PRIVSEP_USER)" ]; then \
218                         m="u=rxs,$${m}" o="$(VAL_PRIVSEP_USER)$${o}";\
219                 else \
220                         m="u=rx,$${m}";\
221                 fi;\
222                 __copychownfile "$${m}" "$${o}" "$(VAL_PRIVSEP)" \
223                         "$(VAL_LIBEXECDIR)/$(VAL_PRIVSEP)";\
224         fi;\
225         \
226         if [ -z "$(DESTDIR)" ]; then \
227                 __copyfile 0555 "$(VAL_UAGENT)-uninstall.sh" \
228                         "$(VAL_BINDIR)/$(VAL_UAGENT)-uninstall.sh";\
229         fi;\
230         $(ECHO_BLOCK_END)
232 uninstall:
233         @echo 'Invoke $(VAL_UAGENT)-uninstall.sh to uninstall $(VAL_UAGENT)'
235 clean:
236         $(ECHO_CMD)\
237         $(rm) -f $(OBJ) $(VAL_UAGENT) ./gen-mime-types.h ./uman.1 ./urc.rc;\
238         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
239                 $(rm) -f ./privsep.o ./$(VAL_PRIVSEP);\
240         fi;\
241         \
242         if [ -f "$(VAL_UAGENT)-uninstall.sh" ]; then \
243                 $(rm) -f ./$(VAL_UAGENT)-uninstall.sh;\
244         fi
246 distclean: clean
247         $(ECHO_CMD)\
248         $(rm) -f ./mk-*
250 # MUST work with "grep=grep sed=sed cmp=cmp mv=mv", otherwise need to change
251 # make-release.inc
252 _update-version:
253         @LC_ALL=C; export LC_ALL;\
254         if [ -z "$(VERSION)" ]; then \
255                 eval VERSION="`(cd $(SRCDIR);\
256                         [ -d .git ] && git describe --tags) 2>/dev/null`";\
257                 if [ -n "$${VERSION}" ]; then \
258                         VERSION="`echo $${VERSION} |\
259                                 $(sed) -e 's/^v\{0,1\}\(.*\)/\1/'`";\
260                         [ "`(cd $(SRCDIR) && git status --porcelain) |\
261                                 $(awk) '\
262                                         BEGIN {n=0}\
263                                         /gen-version\.h/ {next}\
264                                         /^\?\?/ {next}\
265                                         {++n}\
266                                         END {print n}\
267                                 '`" -ne 0 ] &&\
268                                 VERSION="$${VERSION}-dirty";\
269                 else \
270                         $(_version_from_header);\
271                         echo "$${VERSION}" | $(grep) -q -F dirty ||\
272                                 VERSION="$${VERSION}-dirty";\
273                 fi;\
274         fi;\
275         vmaj="`echo \"$${VERSION}\" |\
276                 $(sed) -e 's/^\([^.]\{1,\}\).*/\1/'`";\
277         vmin="`echo \"$${VERSION}\" |\
278                 $(sed) -e 's/^[^.]\{1,\}\.\([^.]\{1,\}\).*/\1/'`";\
279         [ "$${vmin}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vmin=0;\
280         vupd="`echo \"$${VERSION}\" |\
281                 $(sed) -e 's/^[^.]\{1,\}\.[^.]\{1,\}\.\([^.-]\{1,\}\).*/\1/'`";\
282         [ "$${vupd}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vupd=0;\
283         trap "$(rm) -f ./version.tmp" 0 1 2 15;\
284         printf > ./version.tmp "#define n_VERSION \"v$${VERSION}\"\n";\
285         printf >> ./version.tmp \
286                 "#define n_VERSION_DATE \"`date -u +'%Y-%m-%d'`\"\n";\
287         printf >> ./version.tmp "#define n_VERSION_MAJOR \"$${vmaj}\"\n";\
288         printf >> ./version.tmp "#define n_VERSION_MINOR \"$${vmin}\"\n";\
289         printf >> ./version.tmp "#define n_VERSION_UPDATE \"$${vupd}\"\n";\
290         $(cmp) ./version.tmp ./gen-version.h >/dev/null 2>&1 && exit;\
291         $(mv) ./version.tmp ./gen-version.h;\
292         trap : 0 1 2 15
294 # s-mk-mode