main(): verify *expandargv* value content in case of OPT_D_V
[s-mailx.git] / mk-mk.in
blob2001051d039c4d8bfd21f246827c55bf4d1fd793
1 #@ "mk-mk.in" -- mk.mk template, completed by mk-conf.sh.
2 #@ Please see "INSTALL" and "make.rc" instead.
4 OBJ = $(OBJ_SRC:.c=.o)
5 .SUFFIXES: .o .c .y
6 .c.o:
7         @if [ -z "$(VERBOSE)" ]; then echo '  CC $(<)';\
8         else echo '  $$ $(CC) $(CFLAGS) $(INCS) -c $(<)';\
9         fi;\
10         $(CC) $(CFLAGS) $(INCS) -c $(<)
11 .c .y: ;
13 all: _all_echoes $(UAGENT) $(OPTIONAL_PRIVSEP)
14 _all_echoes:
15         @echo 'Building..';\
16         if [ -z "$(VERBOSE)" ]; then \
17                 echo '. CC      : $(CC)';\
18                 echo '. CFLAGS  : $(CFLAGS)';\
19                 echo '. INCS    : $(INCS)';\
20                 [ -n "$(LDFLAGS)" ] && echo '. LDFLAGS : $(LDFLAGS)';\
21                 echo '. LIBS    : $(LIBS)';\
22         fi
24 $(UAGENT): $(OBJ)
25         @if [ -z "$(VERBOSE)" ]; then echo '  LINK $(@)';\
26         else echo '  $$ $(CC) $(LDFLAGS) -o $(@) $(OBJ) $(LIBS)';\
27         fi;\
28         $(CC) $(LDFLAGS) -o $(@) $(OBJ) $(LIBS)
29         @if ( command -v size ) > /dev/null 2>&1; then size $(@); fi
31 $(OBJ): config.h nail.h nailfuns.h $(AMALGAM_DEP)
32 $(AMALGAM_TARGET) accmacvar.o: okeys.h version.h
33 $(AMALGAM_TARGET) fio.o: dotlock.h
34 $(AMALGAM_TARGET) lex.o: cmd_tab.h
35 $(AMALGAM_TARGET) mime_types.o: mime_types.h
36 $(AMALGAM_TARGET) pop3.o smtp.o urlcrecry.o: rfc1321.h
37 $(AMALGAM_TARGET) smtp.o: smtp_gssapi.h
39 $(PRIVSEP): privsep.o
40         @if [ -z "$(VERBOSE)" ]; then echo '  LINK $(@)';\
41         else echo '  $$ $(CC) $(LDFLAGS) -o $(@) privsep.o';\
42         fi;\
43         $(CC) $(LDFLAGS) -o $(@) privsep.o
44         @if ( command -v size ) > /dev/null 2>&1; then size $(@); fi
46 privsep.o: config.h nail.h dotlock.h
48 mime_types.h: mime.types
49         @echo '  GEN $(@)';\
50         LC_ALL=C < ./mime.types > $(@) $(awk) '\
51         function add(mt, ln) {\
52                 gsub(/[[:space:]]+/, " ", ln);\
53                 i = split(ln, i_a);\
54                 e = "";\
55                 for (j = 1; j <= i; ++j) {\
56                         k = i_a[j];\
57                         e = (e ? e " " : "") k\
58                 }\
59                 if (e) {\
60                         if (e_a[mt])\
61                                 e_a[mt] = e_a[mt] " ";\
62                         e_a[mt] = e_a[mt] e\
63                 }\
64         }\
65         /^[[:space:]]*#/ {next}\
66         /^[[:space:]]*$$/ {ltype = ""; next}\
67         /^[[:space:]]/ {\
68                 if (!ltype)\
69                         print "FAULTY CONTINUATION: " $$0 >> "/dev/stderr";\
70                 add(ltype, $$0);\
71                 next\
72         }\
73         /^(@([thH]@)? )?[[:alpha:]]/ {\
74                 if ($$1 ~ /^@([thH]@)?$$/) {\
75                         pa = $$1;\
76                         $$1 = $$2;\
77                         $$2 = ""\
78                 } else\
79                         pa = "";\
80                 if ($$1 !~ /^([[:alnum:]]+)\/([[:alnum:]_+-]+)$$/)\
81                         print "FAULTY MIME TYPE: <" $$1 ">" >> "/dev/stderr";\
82                 ltype = $$1; $$1 = "";\
83                 if (pa)\
84                         p_a[ltype] = pa;\
85                 if (!nt_a[ltype])\
86                         no_a[++no_ai] = nt_a[ltype] = ltype;\
87                 add(ltype, $$0)\
88         }\
89         END {\
90                 for (z = 1; z <= no_ai; ++z) {\
91                         t = no_a[z];\
92                         j = index(t, "/");\
93                         mt = toupper(substr(t, 1, j - 1));\
94                         j = substr(t, j + 1);\
95                         l = length(j);\
96                         if (!p_a[t])\
97                                 mt = "_MT_" mt;\
98                         else {\
99                                 tm = p_a[t];\
100                                 if (tm == "@" || tm == "@t@")\
101                                         mt = "_MT_" mt " | _MT_PLAIN";\
102                                 else if (tm == "@h@")\
103                                         mt = "_MT_" mt " | _MT_SOUP_h";\
104                                 else if (tm == "@H@")\
105                                         mt = "_MT_" mt " | _MT_SOUP_H";\
106                         }\
107                         print "   {" mt ", " l ", \"" j e_a[t] "\"},"\
108                 }\
109         }\
110         '
112 test: all
113         @echo 'Running test, please wait';\
114         MAKE=$(MAKE) \
115         awk=$(awk) cat=$(cat) cksum=$(cksum) rm=$(rm) sed=$(sed) grep=$(grep) \
116         $(SHELL) ./cc-test.sh --check-only ./$(UAGENT)
118 # Corresponds to same thing in makefile!
119 _version_from_header = VERSION="`< version.h $(sed) \
120                 -e '/ VERSION /b X' -e d -e ':X' \
121                 -e 's/[^\"]*\"v\([^\"]\{1,\}\)\"/\1/'`"
123 mkman.1: nail.1
124         @[ -n "$(VERBOSE)" ] && echo '  GEN $(UAGENT) manual ($(@))';\
125         LC_ALL=C _SYSCONFRC="$(SYSCONFRC)" _UAGENT="$(UAGENT)" \
126                 $(_version_from_header) \
127         < ./nail.1 > $(@) $(awk) '\
128         BEGIN { written = 0 }\
129         /\.\\"--MKMAN-START--/, /\.\\"--MKMAN-END--/ {\
130                 if (written++ != 0)\
131                         next;\
132                 OFS = "";\
133                 un = toupper(ENVIRON["_UAGENT"]);\
134                 ln = tolower(un);\
135                 cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
136                 print ".ds UU \\\\%", un;\
137                 print ".ds UA \\\\%", cn;\
138                 print ".ds ua \\\\%", ln;\
139                 print ".ds VV \\\\%v", ENVIRON["VERSION"];\
140                 path = ENVIRON["_SYSCONFRC"];\
141                 gsub("/", "/\\:", path);\
142                 print ".ds UR \\\\%", path;\
143                 OFS = " ";\
144                 next\
145         }\
146         {print}\
147         '
149 mkrc.rc: nail.rc
150         @[ -n "$(VERBOSE)" ] &&\
151                 echo '  GEN $(UAGENT) default resource file ($(@))';\
152         LC_ALL=C _SYSCONFRC="$(SYSCONFRC)" _UAGENT="$(UAGENT)" \
153                 $(_version_from_header) \
154         < ./nail.rc > $(@) $(awk) 'BEGIN {written = 0}\
155         /^#--MKRC-START--/, /^#--MKRC-END--/ {\
156                 if (written == 1)\
157                         next;\
158                 written = 1;\
159                 OFS = "";\
160                 ln = tolower(ENVIRON["_UAGENT"]);\
161                 cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
162                 print "#@ ", ENVIRON["_SYSCONFRC"];\
163                 print "#@ Configuration file for ", cn, "(1) v",\
164                         ENVIRON["VERSION"];\
165                 OFS = " ";\
166                 next\
167         }\
168         {print}\
169         '
171 _install_echoes:
172         @echo 'Installing..'
173 install: _install_echoes mkman.1 mkrc.rc
174         @__mkdir() {\
175                 _dir=$${1};\
176                 if [ -d "$${_dir}" ]; then :; else\
177                         [ -n "$(VERBOSE)" ] &&\
178                                 echo "  \$$ $(mkdir) -m 0755 -p '$${_dir}'";\
179                         $(mkdir) -m 0755 -p "$${_dir}";\
180                 fi;\
181         };\
182         __copyfile() {\
183                 _mode=$${1} _src=$${2} _dst=$${3};\
184                 [ -n "$(VERBOSE)" ] &&\
185                         echo "  \$$ $(cp) -f '$${_src}' '$${_dst}'";\
186                 $(cp) -f "$${_src}" "$${_dst}";\
187                 [ -n "$(VERBOSE)" ] &&\
188                         echo "  \$$ $(chmod) $${_mode} '$${_dst}'";\
189                 $(chmod) $${_mode} "$${_dst}";\
190         };\
191         __copychownfile() {\
192                 _mode=$${1} _ident=$${2} _src=$${3} _dst=$${4};\
193                 [ -n "$(VERBOSE)" ] &&\
194                         echo "  \$$ $(cp) -f '$${_src}' '$${_dst}'";\
195                 $(cp) -f "$${_src}" "$${_dst}";\
196                 [ -n "$(VERBOSE)" ] &&\
197                         echo "  \$$ $(chown) $${_ident} '$${_dst}'";\
198                 $(chown) $${_ident} "$${_dst}";\
199                 [ -n "$(VERBOSE)" ] &&\
200                         echo "  \$$ $(chmod) $${_mode} '$${_dst}'";\
201                 $(chmod) $${_mode} "$${_dst}";\
202         };\
203         __stripfile() {\
204                 _file=$${1};\
205                 if [ "$(WANT_DEBUG)" != 0 ]; then \
206                         [ -n "$(VERBOSE)" ] &&\
207                                 echo "  \$$ :WANT_DEBUG=1, not strip(1)ing";\
208                 elif [ -n "$(HAVE_STRIP)" ]; then \
209                         [ -n "$(VERBOSE)" ] &&\
210                                 echo "  \$$ $(STRIP) '$${_file}'";\
211                         $(strip) "$${_file}";\
212                 fi;\
213         };\
214         if [ -n "$(DESTDIR)" ]; then __mkdir "$(DESTDIR)"; fi;\
215         __mkdir "$(DESTDIR)$(BINDIR)";\
216         __stripfile "$(UAGENT)";\
217         __copyfile 0555 "$(UAGENT)" "$(DESTDIR)$(BINDIR)/$(UAGENT)";\
218         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
219                 __mkdir "$(DESTDIR)$(LIBEXECDIR)";\
220                 __stripfile "$(PRIVSEP)";\
221                 m='o=rx' o=;\
222                 if [ -n "$(_____PRIVSEP_GROUP)" ]; then \
223                         m="g=rxs,$${m}" o=":$(PRIVSEP_GROUP)";\
224                 else \
225                         m="g=rx,$${m}";\
226                 fi;\
227                 if [ -n "$(PRIVSEP_USER)" ]; then \
228                         m="u=rxs,$${m}" o="$(PRIVSEP_USER)$${o}";\
229                 else \
230                         m="u=rx,$${m}";\
231                 fi;\
232                 __copychownfile "$${m}" "$${o}" "$(PRIVSEP)" \
233                                 "$(DESTDIR)$(LIBEXECDIR)/$(PRIVSEP)";\
234         fi;\
235         __mkdir "$(DESTDIR)$(MANDIR)/man1";\
236         __copyfile 0444 ./mkman.1 "$(DESTDIR)$(MANDIR)/man1/$(UAGENT).1";\
237         __mkdir "$(DESTDIR)$(SYSCONFDIR)";\
238         if [ -f "$(DESTDIR)$(SYSCONFDIR)/$(SYSCONFRC)" ]; then :; else\
239                 __copyfile 0444 ./mkrc.rc \
240                         "$(DESTDIR)$(SYSCONFDIR)/$(SYSCONFRC)";\
241         fi
243 uninstall:
244         @echo 'Uninstalling..';\
245         [ -n "$(VERBOSE)" ] &&\
246                 echo '  $$ $(rm) -f "$(DESTDIR)$(BINDIR)/$(UAGENT)" \
247                         "$(DESTDIR)$(MANDIR)/man1/$(UAGENT).1"';\
248         $(rm) -f "$(DESTDIR)$(BINDIR)/$(UAGENT)" \
249                 "$(DESTDIR)$(MANDIR)/man1/$(UAGENT).1";\
250         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
251                 [ -n "$(VERBOSE)" ] &&\
252                         echo \
253                           '  $$ $(rm) -f "$(DESTDIR)$(LIBEXECDIR)/$(PRIVSEP)"';\
254                 $(rm) -f "$(DESTDIR)$(LIBEXECDIR)/$(PRIVSEP)";\
255         fi;\
256         if [ -n "$(VERBOSE)" ] && [ -f "$(DESTDIR)$(SYSCONFRC)" ]; then \
257                 echo '  NOTE: not removing "$(DESTDIR)$(SYSCONFRC)"';\
258         fi
260 clean:
261         @echo 'Cleaning up..';\
262         [ -n "$(VERBOSE)" ] &&\
263                 echo '  $$ $(rm) -f $(OBJ) $(UAGENT) ./mime_types.h ./mkman.1 \
264                         ./mkrc.rc';\
265         $(rm) -f $(OBJ) $(UAGENT) ./mime_types.h ./mkman.1 ./mkrc.rc;\
266         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
267                 [ -n "$(VERBOSE)" ] &&\
268                         echo '  $$ $(rm) -f ./privsep.o $(PRIVSEP)';\
269                 $(rm) -f ./privsep.o $(PRIVSEP);\
270         fi
272 distclean: clean
273         @echo 'Deconfiguring..';\
274         [ -n "$(VERBOSE)" ] && echo '  $$ $(rm) -f ./config.* ./*.mk';\
275         $(rm) -f ./config.* ./*.mk
277 # MUST work with "grep=grep sed=sed cmp=cmp mv=mv", otherwise modify makefile
278 _update-version:
279         @LC_ALL=C; export LC_ALL;\
280         if [ -z "$(VERSION)" ]; then \
281                 eval VERSION="`(git describe --tags) 2>/dev/null`";\
282                 if [ -n "$${VERSION}" ]; then \
283                         VERSION="`echo $${VERSION} |\
284                                 $(sed) -e 's/^v\{0,1\}\(.*\)/\1/'`";\
285                         [ "`git status --porcelain |\
286                                 $(awk) '\
287                                         BEGIN {n=0}\
288                                         /version\.h/ {next}\
289                                         /^\?\?/ {next}\
290                                         {++n}\
291                                         END {print n}\
292                                 '`" -ne 0 ] &&\
293                                 VERSION="$${VERSION}-dirty";\
294                 else \
295                         $(_version_from_header);\
296                         echo "$${VERSION}" | $(grep) -q -F dirty ||\
297                                 VERSION="$${VERSION}-dirty";\
298                 fi;\
299         fi;\
300         vmaj="`echo \"$${VERSION}\" |\
301                 $(sed) -e 's/^\([^.]\{1,\}\).*/\1/'`";\
302         vmin="`echo \"$${VERSION}\" |\
303                 $(sed) -e 's/^[^.]\{1,\}\.\([^.]\{1,\}\).*/\1/'`";\
304         [ "$${vmin}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vmin=0;\
305         vupd="`echo \"$${VERSION}\" |\
306                 $(sed) -e 's/^[^.]\{1,\}\.[^.]\{1,\}\.\([^.-]\{1,\}\).*/\1/'`";\
307         [ "$${vupd}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vupd=0;\
308         trap "$(rm) ./version.tmp" 0 1 2 15;\
309         printf > ./version.tmp "#define VERSION \"v$${VERSION}\"\n";\
310         printf >> ./version.tmp "#define VERSION_MAJOR \"$${vmaj}\"\n";\
311         printf >> ./version.tmp "#define VERSION_MINOR \"$${vmin}\"\n";\
312         printf >> ./version.tmp "#define VERSION_UPDATE \"$${vupd}\"\n";\
313         $(cmp) ./version.tmp ./version.h >/dev/null 2>&1 && exit;\
314         $(mv) ./version.tmp ./version.h;\
315         trap : 0 1 2 15
317 # s-mk-mode