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