(Pseudo) Fix history (non gabbiness) by stripping PS_ARGLIST_MASK
[s-mailx.git] / mk-mk.in
blob9a63267ef4ff6261525d469458b95ebdab320ccf
1 #@ mk-mk.in -- mk.mk template, completed by mk-conf.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="`< version.h $(sed) \
7                 -e '/ 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)
19         $(ECHO_LINK)$(CC) $(LDFLAGS) -o $(@) $(OBJ) $(LIBS)
20         $(SIZE_CHECK)
22 $(OBJ): config.h nail.h nailfuns.h $(AMALGAM_DEP)
23 $(AMALGAM_TARGET) accmacvar.o: okeys.h version.h
24 $(AMALGAM_TARGET) dotlock.o: dotlock.h
25 $(AMALGAM_TARGET) lex_input.o: cmd_tab.h
26 $(AMALGAM_TARGET) mime_types.o: mime_types.h
27 $(AMALGAM_TARGET) pop3.o smtp.o urlcrecry.o: rfc1321.h
28 $(AMALGAM_TARGET) smtp.o: smtp_gssapi.h
29 $(AMALGAM_TARGET) termcap.o: tcaps.h
31 $(VAL_PRIVSEP): privsep.o
32         $(ECHO_LINK)$(CC) $(LDFLAGS) -o $(@) privsep.o $(BASE_LIBS)
33         $(SIZE_CHECK)
35 privsep.o: privsep.c config.h nail.h dotlock.h
36         $(ECHO_CC)$(CC) $(CFLAGS) $(BASE_INCS) -c privsep.c
38 test: all
39         $(ECHO_TEST)\
40         MAKE=$(MAKE) \
41         awk=$(awk) cat=$(cat) cksum=$(cksum) rm=$(rm) sed=$(sed) grep=$(grep) \
42         $(SHELL) ./cc-test.sh --check-only ./$(VAL_UAGENT)
44 mime_types.h: mime.types
45         $(ECHO_GEN)\
46         LC_ALL=C < ./mime.types > $(@) $(awk) '\
47         function add(mt, ln) {\
48                 gsub(/[[:space:]]+/, " ", ln);\
49                 i = split(ln, i_a);\
50                 e = "";\
51                 for (j = 1; j <= i; ++j) {\
52                         k = i_a[j];\
53                         e = (e ? e " " : "") k\
54                 }\
55                 if (e) {\
56                         if (e_a[mt])\
57                                 e_a[mt] = e_a[mt] " ";\
58                         e_a[mt] = e_a[mt] e\
59                 }\
60         }\
61         /^[[:space:]]*#/ {next}\
62         /^[[:space:]]*$$/ {ltype = ""; next}\
63         /^[[:space:]]/ {\
64                 if (!ltype)\
65                         print "FAULTY CONTINUATION: " $$0 >> "/dev/stderr";\
66                 add(ltype, $$0);\
67                 next\
68         }\
69         /^(@([thH]@)? )?[[:alpha:]]/ {\
70                 if ($$1 ~ /^@([thH]@)?$$/) {\
71                         pa = $$1;\
72                         $$1 = $$2;\
73                         $$2 = ""\
74                 } else\
75                         pa = "";\
76                 if ($$1 !~ /^([[:alnum:]]+)\/([[:alnum:]_+-]+)$$/)\
77                         print "FAULTY MIME TYPE: <" $$1 ">" >> "/dev/stderr";\
78                 ltype = $$1; $$1 = "";\
79                 if (pa)\
80                         p_a[ltype] = pa;\
81                 if (!nt_a[ltype])\
82                         no_a[++no_ai] = nt_a[ltype] = ltype;\
83                 add(ltype, $$0)\
84         }\
85         END {\
86                 for (z = 1; z <= no_ai; ++z) {\
87                         t = no_a[z];\
88                         j = index(t, "/");\
89                         mt = toupper(substr(t, 1, j - 1));\
90                         j = substr(t, j + 1);\
91                         l = length(j);\
92                         if (!p_a[t])\
93                                 mt = "_MT_" mt;\
94                         else {\
95                                 tm = p_a[t];\
96                                 if (tm == "@" || tm == "@t@")\
97                                         mt = "_MT_" mt " | _MT_PLAIN";\
98                                 else if (tm == "@h@")\
99                                         mt = "_MT_" mt " | _MT_SOUP_h";\
100                                 else if (tm == "@H@")\
101                                         mt = "_MT_" mt " | _MT_SOUP_H";\
102                         }\
103                         print "   {" mt ", " l ", \"" j e_a[t] "\"},"\
104                 }\
105         }\
106         '
108 mkman.1: nail.1
109         $(ECHO_GEN)\
110         LC_ALL=C _SYSCONFRC="$(VAL_SYSCONFRC)" _UAGENT="$(VAL_UAGENT)" \
111                 $(_version_from_header) \
112         < ./nail.1 > $(@) $(awk) '\
113         BEGIN { written = 0 }\
114         /\.\\"--MKMAN-START--/, /\.\\"--MKMAN-END--/ {\
115                 if (written++ != 0)\
116                         next;\
117                 OFS = "";\
118                 un = toupper(ENVIRON["_UAGENT"]);\
119                 ln = tolower(un);\
120                 cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
121                 print ".ds UU \\\\%", un;\
122                 print ".ds UA \\\\%", cn;\
123                 print ".ds ua \\\\%", ln;\
124                 print ".ds VV \\\\%v", ENVIRON["VERSION"];\
125                 path = ENVIRON["_SYSCONFRC"];\
126                 gsub("/", "/\\:", path);\
127                 print ".ds UR \\\\%", path;\
128                 OFS = " ";\
129                 next\
130         }\
131         {print}\
132         '
134 mkrc.rc: nail.rc
135         $(ECHO_GEN)\
136         LC_ALL=C _SYSCONFRC="$(VAL_SYSCONFRC)" _UAGENT="$(VAL_UAGENT)" \
137                 $(_version_from_header) \
138         < ./nail.rc > $(@) $(awk) 'BEGIN {written = 0}\
139         /^#--MKRC-START--/, /^#--MKRC-END--/ {\
140                 if (written == 1)\
141                         next;\
142                 written = 1;\
143                 OFS = "";\
144                 ln = tolower(ENVIRON["_UAGENT"]);\
145                 cn = toupper(substr(ln, 1, 1)) substr(ln, 2);\
146                 print "#@ ", ENVIRON["_SYSCONFRC"];\
147                 print "#@ Configuration file for ", cn, "(1) v",\
148                         ENVIRON["VERSION"];\
149                 OFS = " ";\
150                 next\
151         }\
152         {print}\
153         '
155 install: mkman.1 mkrc.rc
156         $(ECHO_BLOCK_BEGIN)\
157         __mkdir() {\
158                 _dir=$${1};\
159                 if [ -d "$${_dir}" ]; then :; else\
160                         $(mkdir) -m 0755 -p "$${_dir}";\
161                 fi;\
162         };\
163         __copyfile() {\
164                 _mode=$${1} _src=$${2} _dst=$${3};\
165                 $(cp) -f "$${_src}" "$${_dst}";\
166                 $(chmod) $${_mode} "$${_dst}";\
167         };\
168         __copychownfile() {\
169                 _mode=$${1} _ident=$${2} _src=$${3} _dst=$${4};\
170                 $(cp) -f "$${_src}" "$${_dst}";\
171                 $(chown) $${_ident} "$${_dst}";\
172                 $(chmod) $${_mode} "$${_dst}";\
173         };\
174         __stripfile() {\
175                 _file=$${1};\
176                 if [ "$(OPT_DEBUG)" != 0 ]; then :;\
177                 elif [ -n "$(HAVE_STRIP)" ]; then \
178                         $(strip) "$${_file}";\
179                 fi;\
180         };\
181         if [ -n "$(DESTDIR)" ]; then __mkdir "$(DESTDIR)"; fi;\
182         __mkdir "$(DESTDIR)$(VAL_BINDIR)";\
183         __stripfile "$(VAL_UAGENT)";\
184         __copyfile 0555 "$(VAL_UAGENT)" \
185                 "$(DESTDIR)$(VAL_BINDIR)/$(VAL_UAGENT)";\
186         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
187                 __mkdir "$(DESTDIR)$(VAL_LIBEXECDIR)";\
188                 __stripfile "$(VAL_PRIVSEP)";\
189                 m='o=rx' o=;\
190                 if [ -n "$(_____PRIVSEP_GROUP)" ]; then \
191                         m="g=rxs,$${m}" o=":$(VAL_PRIVSEP_GROUP)";\
192                 else \
193                         m="g=rx,$${m}";\
194                 fi;\
195                 if [ -n "$(VAL_PRIVSEP_USER)" ]; then \
196                         m="u=rxs,$${m}" o="$(VAL_PRIVSEP_USER)$${o}";\
197                 else \
198                         m="u=rx,$${m}";\
199                 fi;\
200                 __copychownfile "$${m}" "$${o}" "$(VAL_PRIVSEP)" \
201                                 "$(DESTDIR)$(VAL_LIBEXECDIR)/$(VAL_PRIVSEP)";\
202         fi;\
203         __mkdir "$(DESTDIR)$(VAL_MANDIR)/man1";\
204         __copyfile 0444 ./mkman.1 \
205                 "$(DESTDIR)$(VAL_MANDIR)/man1/$(VAL_UAGENT).1";\
206         __mkdir "$(DESTDIR)$(VAL_SYSCONFDIR)";\
207         if [ -f "$(DESTDIR)$(VAL_SYSCONFDIR)/$(VAL_SYSCONFRC)" ]; then :; else\
208                 __copyfile 0444 ./mkrc.rc \
209                         "$(DESTDIR)$(VAL_SYSCONFDIR)/$(VAL_SYSCONFRC)";\
210         fi;\
211         $(ECHO_BLOCK_END)
213 uninstall:
214         $(ECHO_BLOCK_BEGIN)\
215         echo 'Uninstalling..';\
216         $(rm) -f "$(DESTDIR)$(VAL_BINDIR)/$(VAL_UAGENT)" \
217                 "$(DESTDIR)$(VAL_MANDIR)/man1/$(VAL_UAGENT).1";\
218         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
219                 $(rm) -f "$(DESTDIR)$(VAL_LIBEXECDIR)/$(VAL_PRIVSEP)";\
220         fi;\
221         if [ -n "$(VERBOSE)" ] && [ -f "$(DESTDIR)$(VAL_SYSCONFRC)" ]; then \
222                 echo '  NOTE: not removing "$(DESTDIR)$(VAL_SYSCONFRC)"';\
223         fi;\
224         $(ECHO_BLOCK_END)
226 clean:
227         $(ECHO_CMD)\
228         $(rm) -f $(OBJ) $(VAL_UAGENT) ./mime_types.h ./mkman.1 ./mkrc.rc;\
229         if [ -n "$(OPTIONAL_PRIVSEP)" ]; then \
230                 $(rm) -f ./privsep.o $(VAL_PRIVSEP);\
231         fi
233 distclean: clean
234         $(ECHO_CMD)\
235         $(rm) -f ./config.* ./*.mk
237 # MUST work with "grep=grep sed=sed cmp=cmp mv=mv", otherwise need to change
238 # mk-release.inc
239 _update-version:
240         @LC_ALL=C; export LC_ALL;\
241         if [ -z "$(VERSION)" ]; then \
242                 eval VERSION="`(git describe --tags) 2>/dev/null`";\
243                 if [ -n "$${VERSION}" ]; then \
244                         VERSION="`echo $${VERSION} |\
245                                 $(sed) -e 's/^v\{0,1\}\(.*\)/\1/'`";\
246                         [ "`git status --porcelain |\
247                                 $(awk) '\
248                                         BEGIN {n=0}\
249                                         /version\.h/ {next}\
250                                         /^\?\?/ {next}\
251                                         {++n}\
252                                         END {print n}\
253                                 '`" -ne 0 ] &&\
254                                 VERSION="$${VERSION}-dirty";\
255                 else \
256                         $(_version_from_header);\
257                         echo "$${VERSION}" | $(grep) -q -F dirty ||\
258                                 VERSION="$${VERSION}-dirty";\
259                 fi;\
260         fi;\
261         vmaj="`echo \"$${VERSION}\" |\
262                 $(sed) -e 's/^\([^.]\{1,\}\).*/\1/'`";\
263         vmin="`echo \"$${VERSION}\" |\
264                 $(sed) -e 's/^[^.]\{1,\}\.\([^.]\{1,\}\).*/\1/'`";\
265         [ "$${vmin}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vmin=0;\
266         vupd="`echo \"$${VERSION}\" |\
267                 $(sed) -e 's/^[^.]\{1,\}\.[^.]\{1,\}\.\([^.-]\{1,\}\).*/\1/'`";\
268         [ "$${vupd}" = "$${VERSION}" ] && VERSION="$${VERSION}.0" vupd=0;\
269         trap "$(rm) ./version.tmp" 0 1 2 15;\
270         printf > ./version.tmp "#define VERSION \"v$${VERSION}\"\n";\
271         printf >> ./version.tmp "#define VERSION_MAJOR \"$${vmaj}\"\n";\
272         printf >> ./version.tmp "#define VERSION_MINOR \"$${vmin}\"\n";\
273         printf >> ./version.tmp "#define VERSION_UPDATE \"$${vupd}\"\n";\
274         $(cmp) ./version.tmp ./version.h >/dev/null 2>&1 && exit;\
275         $(mv) ./version.tmp ./version.h;\
276         trap : 0 1 2 15
278 # s-mk-mode