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