make-config.sh: actually find DragonFly BSD's ncurses installation
[s-mailx.git] / make-config.in
blob6a3661305ededaeec8a7e7e5fad8c596208cf261
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 \
107                 _UAGENT="$(VAL_UAGENT)" \
108                 _SYSCONFRC="$(VAL_SYSCONFDIR)/$(VAL_SYSCONFRC)" \
109                 _MAILRC="$(VAL_MAILRC)" \
110                         _DEAD="$(VAL_DEAD)" \
111                         _MBOX="$(VAL_MBOX)" \
112                         _NETRC="$(VAL_NETRC)" \
113                         _TMPDIR="$(VAL_TMPDIR)" \
114                                 _MT_S="$(VAL_MIME_TYPES_SYS)" \
115                                 _MT_U="$(VAL_MIME_TYPES_USR)" \
116                 $(_version_from_header) \
117         < $(SRCDIR)nail.1 > $(@) $(awk) '\
118         BEGIN { written = 0 }\
119         /\.\\"--MKMAN-START--/, /\.\\"--MKMAN-END--/ {\
120                 if (written++ != 0)\
121                         next;\
122                 OFS = "";\
123                 print ".ds VV \\\\%v", ENVIRON["VERSION"];\
124                 \
125                 un = toupper(ENVIRON["_UAGENT"]);\
126                         ln = tolower(un);\
127                         cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
128                         print ".ds UU \\\\%", un;\
129                         print ".ds UA \\\\%", cn;\
130                         print ".ds uA \\\\%", ln;\
131                 path = ENVIRON["_SYSCONFRC"];\
132                         gsub("/", "/\\:", path);\
133                         print ".ds UR \\\\%", path;\
134                 path = ENVIRON["_MAILRC"];\
135                         gsub("/", "/\\:", path);\
136                         print ".ds ur \\\\%", path;\
137                 \
138                 path = ENVIRON["_DEAD"];\
139                         gsub("/", "/\\:", path);\
140                         print ".ds VD \\\\%", path;\
141                 path = ENVIRON["_MBOX"];\
142                         gsub("/", "/\\:", path);\
143                         print ".ds VM \\\\%", path;\
144                 path = ENVIRON["_NETRC"];\
145                         gsub("/", "/\\:", path);\
146                         print ".ds VN \\\\%", path;\
147                 path = ENVIRON["_TMPDIR"];\
148                         gsub("/", "/\\:", path);\
149                         print ".ds VT \\\\%", path;\
150                 \
151                 path = ENVIRON["_MT_S"];\
152                         gsub("/", "/\\:", path);\
153                         print ".ds vS \\\\%", path;\
154                 path = ENVIRON["_MT_U"];\
155                         gsub("/", "/\\:", path);\
156                         print ".ds vU \\\\%", path;\
157                 \
158                 OFS = " ";\
159                 next\
160         }\
161         {print}\
162         '
164 urc.rc: $(SRCDIR)nail.rc
165         $(ECHO_GEN)\
166         LC_ALL=C _SYSCONFRC="$(VAL_SYSCONFRC)" _UAGENT="$(VAL_UAGENT)" \
167                 $(_version_from_header) \
168         < $(SRCDIR)nail.rc > $(@) $(awk) 'BEGIN {written = 0}\
169         /^#--MKRC-START--/, /^#--MKRC-END--/ {\
170                 if (written == 1)\
171                         next;\
172                 written = 1;\
173                 OFS = "";\
174                 ln = tolower(ENVIRON["_UAGENT"]);\
175                 cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
176                 print "#@ ", ENVIRON["_SYSCONFRC"];\
177                 print "#@ Configuration file for ", cn, " v",\
178                         ENVIRON["VERSION"];\
179                 OFS = " ";\
180                 next\
181         }\
182         {print}\
183         '
185 install:
186         $(ECHO_BLOCK_BEGIN)\
187         __mkdir() {\
188                 _dir="$(DESTDIR)$${1}";\
189                 if [ -d "$${_dir}" ]; then :; else \
190                         $(mkdir) -m 0755 -p "$${_dir}";\
191                 fi;\
192         };\
193         __copyfile() {\
194                 _mode=$${1} _src=$${2} _xdst=$${3} _dst="$(DESTDIR)$${3}";\
195                 $(cp) -f "$${_src}" "$${_dst}";\
196                 echo "rm -f \"\$${DESTDIR}$${_xdst}\"" >> \
197                         "$(VAL_UAGENT)-uninstall.sh";\
198                 $(chmod) $${_mode} "$${_dst}";\
199                 \
200         };\
201         __copychownfile() {\
202                 _mode=$${1} _ident=$${2} _src=$${3} \
203                         _xdst=$${4} _dst="$(DESTDIR)$${4}";\
204                 $(cp) -f "$${_src}" "$${_dst}";\
205                 echo "rm -f \"\$${DESTDIR}$${_xdst}\"" >> \
206                         "$(VAL_UAGENT)-uninstall.sh";\
207                 $(chown) $${_ident} "$${_dst}" || true;\
208                 $(chmod) $${_mode} "$${_dst}";\
209                 \
210         };\
211         __stripfile() {\
212                 _file=$${1};\
213                 if [ "$(OPT_DEBUG)" != 0 ]; then :;\
214                 elif [ -n "$(HAVE_STRIP)" ]; then \
215                         $(strip) "$${_file}";\
216                 fi;\
217         };\
218         \
219         echo '#!/bin/sh -' > "$(VAL_UAGENT)-uninstall.sh";\
220         echo '#@ Uninstall script for $(VAL_UAGENT)' >> \
221                 "$(VAL_UAGENT)-uninstall.sh";\
222         echo >> "$(VAL_UAGENT)-uninstall.sh";\
223         echo 'DESTDIR="$(DESTDIR)"' >> "$(VAL_UAGENT)-uninstall.sh";\
224         echo 'DESTDIR=' >> "$(VAL_UAGENT)-uninstall.sh";\
225         echo >> "$(VAL_UAGENT)-uninstall.sh";\
226         \
227         if [ -n "$(DESTDIR)" ]; then __mkdir ''; fi;\
228         __mkdir "$(VAL_BINDIR)";\
229         __mkdir "$(VAL_MANDIR)/man1";\
230         __mkdir "$(VAL_SYSCONFDIR)";\
231         \
232         __stripfile "$(VAL_UAGENT)";\
233         __copyfile 0555 "$(VAL_UAGENT)" "$(VAL_BINDIR)/$(VAL_UAGENT)";\
234         __copyfile 0444 ./uman.1 "$(VAL_MANDIR)/man1/$(VAL_UAGENT).1";\
235         if [ -f "$(DESTDIR)$(VAL_SYSCONFDIR)/$(VAL_SYSCONFRC)" ]; then :; else \
236                 __copyfile 0444 ./urc.rc "$(VAL_SYSCONFDIR)/$(VAL_SYSCONFRC)";\
237         fi;\
238         \
239         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
240                 __mkdir "$(VAL_LIBEXECDIR)";\
241                 \
242                 __stripfile "$(VAL_PRIVSEP)";\
243                 m='o=rx' o=;\
244                 if [ -n "$(_____PRIVSEP_GROUP)" ]; then \
245                         m="g=rxs,$${m}" o=":$(VAL_PRIVSEP_GROUP)";\
246                 else \
247                         m="g=rx,$${m}";\
248                 fi;\
249                 if [ -n "$(VAL_PRIVSEP_USER)" ]; then \
250                         m="u=rxs,$${m}" o="$(VAL_PRIVSEP_USER)$${o}";\
251                 else \
252                         m="u=rx,$${m}";\
253                 fi;\
254                 __copychownfile "$${m}" "$${o}" "$(VAL_PRIVSEP)" \
255                         "$(VAL_LIBEXECDIR)/$(VAL_PRIVSEP)";\
256         fi;\
257         \
258         if [ -z "$(DESTDIR)" ]; then \
259                 __copyfile 0555 "$(VAL_UAGENT)-uninstall.sh" \
260                         "$(VAL_BINDIR)/$(VAL_UAGENT)-uninstall.sh";\
261         fi;\
262         $(ECHO_BLOCK_END)
264 uninstall:
265         @echo 'Invoke $(VAL_UAGENT)-uninstall.sh to uninstall $(VAL_UAGENT)'
267 clean:
268         $(ECHO_CMD)\
269         $(rm) -f $(OBJ) $(VAL_UAGENT) ./gen-mime-types.h ./uman.1 ./urc.rc;\
270         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
271                 $(rm) -f ./privsep.o ./$(VAL_PRIVSEP);\
272         fi;\
273         \
274         if [ -f "$(VAL_UAGENT)-uninstall.sh" ]; then \
275                 $(rm) -f ./$(VAL_UAGENT)-uninstall.sh;\
276         fi
278 distclean: clean
279         $(ECHO_CMD)\
280         $(rm) -f ./mk-*
282 # MUST work with "grep=grep sed=sed cmp=cmp mv=mv", otherwise need to change
283 # make-release.inc
284 _update-version:
285         @LC_ALL=C; export LC_ALL;\
286         if [ -z "$(VERSION)" ]; then \
287                 eval VERSION="`(cd $(SRCDIR);\
288                         [ -d .git ] && git describe --tags) 2>/dev/null`";\
289                 if [ -n "$${VERSION}" ]; then \
290                         VERSION="`echo $${VERSION} |\
291                                 $(sed) -e 's/^v\{0,1\}\(.*\)/\1/'`";\
292                         [ "`(cd $(SRCDIR) && git status --porcelain) |\
293                                 $(awk) '\
294                                         BEGIN {n=0}\
295                                         /gen-version\.h/ {next}\
296                                         /^\?\?/ {next}\
297                                         {++n}\
298                                         END {print n}\
299                                 '`" -ne 0 ] &&\
300                                 VERSION="$${VERSION}-dirty";\
301                 else \
302                         $(_version_from_header);\
303                         echo "$${VERSION}" | $(grep) -q -F dirty ||\
304                                 VERSION="$${VERSION}-dirty";\
305                 fi;\
306         fi;\
307         vmaj="`echo \"$${VERSION}\" |\
308                 $(sed) -e 's/^\([^.]\{1,\}\).*/\1/'`";\
309         vmin="`echo \"$${VERSION}\" |\
310                 $(sed) -e 's/^[^.]\{1,\}\.\([^.]\{1,\}\).*/\1/'`";\
311         [ "$${vmin}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vmin=0;\
312         vupd="`echo \"$${VERSION}\" |\
313                 $(sed) -e 's/^[^.]\{1,\}\.[^.]\{1,\}\.\([^.-]\{1,\}\).*/\1/'`";\
314         [ "$${vupd}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vupd=0;\
315         trap "$(rm) -f ./version.tmp" 0 1 2 15;\
316         printf > ./version.tmp "#define n_VERSION \"v$${VERSION}\"\n";\
317         printf >> ./version.tmp \
318                 "#define n_VERSION_DATE \"`date -u +'%Y-%m-%d'`\"\n";\
319         printf >> ./version.tmp "#define n_VERSION_MAJOR \"$${vmaj}\"\n";\
320         printf >> ./version.tmp "#define n_VERSION_MINOR \"$${vmin}\"\n";\
321         printf >> ./version.tmp "#define n_VERSION_UPDATE \"$${vupd}\"\n";\
322         printf >> ./version.tmp \
323                 "#define n_VERSION_HEXNUM \"0x%02X%03X%03X\"\n" \
324                 "$${vmaj}" "$${vmin}" "$${vupd}";\
325         $(cmp) ./version.tmp ./gen-version.h >/dev/null 2>&1 && exit;\
326         $(mv) ./version.tmp ./gen-version.h;\
327         trap : 0 1 2 15
329 # s-mk-mode