From 75a0ecf48c629d9ed68f95c5912fd74df412aa28 Mon Sep 17 00:00:00 2001 From: "Steffen (Daode) Nurpmeso" Date: Mon, 18 Jul 2016 23:58:31 +0200 Subject: [PATCH] mk-conf.sh, mk-mk.in: diversify.. testing on old Solaris showed that we need -lrt for nanosleep(2) there, and that is to say not only in the main MUA, but also in the privilege-separated child: and that exceeds the capability of our current makefile system! I am too lazy to auto-generate the makefile via mk-conf.sh, and implement program-specific rules as such, on the other hand the current approach should not be used since libraries like OpenSSL, Kerberos etc. should never be linked against the privilege-sepa- rated child. The quick-and-easy solution is to resort mk-conf.sh into "base" and "extended functionality, and fork away macros like BASE_LIBS etc. after the former have been worked, and to use those flags for the sub-program(s) that we build instead of the fully fledged stuff. Since inference rules take no arguments, we need to provide special make rules for the subprograms. So later most functionality will be in a library, and then most things have to change again anyway. For now this is good enough. --- mk-conf.sh | 253 +++++++++++++++++++++++++++---------------------------------- mk-mk.in | 8 +- 2 files changed, 118 insertions(+), 143 deletions(-) diff --git a/mk-conf.sh b/mk-conf.sh index 239c750a..a7a71d91 100644 --- a/mk-conf.sh +++ b/mk-conf.sh @@ -1045,11 +1045,31 @@ run_check() { _link_mayrun 1 "${1}" "${2}" "${3}" "${4}" "${5}" } -## +feat_def() { + if feat_yes ${1}; then + echo '#define HAVE_'${1}'' >> ${h} + else + echo '/* WANT_'${1}'=0 */' >> ${h} + fi +} + +squeeze_em() { + < "${1}" > "${2}" ${awk} \ + 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}' +} + +## Generics # May be multiline.. [ -n "${OS_DEFINES}" ] && printf -- "${OS_DEFINES}" >> ${h} -feat_yes CROSS_BUILD && msg ' . CROSS_BUILD enabled, not _running_ tests' + +feat_def AMALGAMATION +feat_def CROSS_BUILD +feat_def DEBUG +feat_def DEVEL +feat_def DOCSTRINGS +feat_def ERRORS +feat_def NYD2 if run_check inline '"inline" functions' \ '#define HAVE_INLINE @@ -1082,7 +1102,9 @@ then : fi -## +## Test for "basic" system-calls / functionality that is used by all parts +## of our program. Once this is done fork away BASE_LIBS and other BASE_* +## macros to be used by only the subprograms (potentially). if run_check clock_gettime 'clock_gettime(2)' \ '#define HAVE_CLOCK_GETTIME' << \! @@ -1311,7 +1333,7 @@ else config_exit 1 fi -## +## optional stuff run_check pathconf 'f?pathconf(2)' '#define HAVE_PATHCONF' << \! #include @@ -1394,54 +1416,6 @@ int main(void){ } ! -link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \! -#include -int main(void){ - setlocale(LC_ALL, ""); - return 0; -} -! - -if [ "${have_setlocale}" = yes ]; then - link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \ - '#define HAVE_C90AMEND1' << \! -#include -#include -#include -#include -int main(void){ - char mbb[MB_LEN_MAX + 1]; - wchar_t wc; - - iswprint(L'c'); - towupper(L'c'); - mbtowc(&wc, "x", 1); - mbrtowc(&wc, "x", 1, NULL); - wctomb(mbb, wc); - return (mblen("\0", 1) == 0); -} -! - - if [ "${have_c90amend1}" = yes ]; then - link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \! -#include -int main(void){ - wcwidth(L'c'); - return 0; -} -! - fi - - link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \! -#include -#include -int main(void){ - nl_langinfo(DAY_1); - return (nl_langinfo(CODESET) == NULL); -} -! -fi # have_setlocale - if run_check realpath 'realpath(3)' '#define HAVE_REALPATH' << \! #include int main(void){ @@ -1467,31 +1441,7 @@ int main(void){ fi fi -link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \! -#include -int main(void){ - return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH); -} -! - -link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \! -#include -int main(void){ - struct dirent de; - return !(de.d_type == DT_UNKNOWN || - de.d_type == DT_DIR || de.d_type == DT_LNK); -} -! - -## - -if feat_yes DEBUG; then - echo '#define HAVE_DEBUG' >> ${h} -fi - -if feat_yes AMALGAMATION; then - echo '#define HAVE_AMALGAMATION' >> ${h} -fi +## optional and selectable if feat_no NOALLOCA; then # Due to NetBSD PR lib/47120 it seems best not to use non-cc-builtin @@ -1508,16 +1458,6 @@ int main(void){ ! fi -if feat_yes DEVEL; then - echo '#define HAVE_DEVEL' >> ${h} -fi - -if feat_yes NYD2; then - echo '#define HAVE_NYD2' >> ${h} -fi - -## - if feat_yes DOTLOCK; then if run_check readlink 'readlink(2)' << \! #include @@ -1554,7 +1494,84 @@ int main(void){ fi fi -## +## Now it is the time to fork away the BASE_ series + +${rm} -f ${tmp} +squeeze_em ${inc} ${tmp} +${mv} ${tmp} ${inc} +squeeze_em ${lib} ${tmp} +${mv} ${tmp} ${lib} + +echo "BASE_LIBS = `${cat} ${lib}`" >> ${mk} +echo "BASE_INCS = `${cat} ${inc}`" >> ${mk} + +## The remains are expected to be used only by the main MUA binary! + +link_check setlocale 'setlocale(3)' '#define HAVE_SETLOCALE' << \! +#include +int main(void){ + setlocale(LC_ALL, ""); + return 0; +} +! + +if [ "${have_setlocale}" = yes ]; then + link_check c90amend1 'ISO/IEC 9899:1990/Amendment 1:1995' \ + '#define HAVE_C90AMEND1' << \! +#include +#include +#include +#include +int main(void){ + char mbb[MB_LEN_MAX + 1]; + wchar_t wc; + + iswprint(L'c'); + towupper(L'c'); + mbtowc(&wc, "x", 1); + mbrtowc(&wc, "x", 1, NULL); + wctomb(mbb, wc); + return (mblen("\0", 1) == 0); +} +! + + if [ "${have_c90amend1}" = yes ]; then + link_check wcwidth 'wcwidth(3)' '#define HAVE_WCWIDTH' << \! +#include +int main(void){ + wcwidth(L'c'); + return 0; +} +! + fi + + link_check nl_langinfo 'nl_langinfo(3)' '#define HAVE_NL_LANGINFO' << \! +#include +#include +int main(void){ + nl_langinfo(DAY_1); + return (nl_langinfo(CODESET) == NULL); +} +! +fi # have_setlocale + +link_check fnmatch 'fnmatch(3)' '#define HAVE_FNMATCH' << \! +#include +int main(void){ + return (fnmatch("*", ".", FNM_PATHNAME | FNM_PERIOD) == FNM_NOMATCH); +} +! + +link_check dirent_d_type 'struct dirent.d_type' '#define HAVE_DIRENT_TYPE' << \! +#include +int main(void){ + struct dirent de; + return !(de.d_type == DT_UNKNOWN || + de.d_type == DT_DIR || de.d_type == DT_LNK); +} +! + +## optional and selectable if feat_yes ICONV; then ${cat} > ${tmp2}.c << \! @@ -2272,14 +2289,6 @@ else echo '/* WANT_TERMCAP_PREFER_TERMINFO=0 */' >> ${h} fi -if feat_yes ERRORS; then - echo '#define HAVE_ERRORS' >> ${h} -else - echo '/* WANT_ERRORS=0 */' >> ${h} -fi - -## - if feat_yes SPAM_SPAMC; then echo '#define HAVE_SPAM_SPAMC' >> ${h} if command -v spamc >/dev/null 2>&1; then @@ -2296,11 +2305,7 @@ else echo '/* WANT_SPAM_SPAMD=0 */' >> ${h} fi -if feat_yes SPAM_FILTER; then - echo '#define HAVE_SPAM_FILTER' >> ${h} -else - echo '/* WANT_SPAM_FILTER=0 */' >> ${h} -fi +feat_def SPAM_FILTER if feat_yes SPAM_SPAMC || feat_yes SPAM_SPAMD || feat_yes SPAM_FILTER; then echo '#define HAVE_SPAM' >> ${h} @@ -2308,12 +2313,6 @@ else echo '/* HAVE_SPAM */' >> ${h} fi -if feat_yes DOCSTRINGS; then - echo '#define HAVE_DOCSTRINGS' >> ${h} -else - echo '/* WANT_DOCSTRINGS=0 */' >> ${h} -fi - if feat_yes QUOTE_FOLD &&\ [ -n "${have_c90amend1}" ] && [ -n "${have_wcwidth}" ]; then echo '#define HAVE_QUOTE_FOLD' >> ${h} @@ -2321,43 +2320,14 @@ else echo '/* WANT_QUOTE_FOLD=0 */' >> ${h} fi -if feat_yes FILTER_HTML_TAGSOUP; then - echo '#define HAVE_FILTER_HTML_TAGSOUP' >> ${h} -else - echo '/* WANT_FILTER_HTML_TAGSOUP=0 */' >> ${h} -fi - -if feat_yes COLOUR; then - echo '#define HAVE_COLOUR' >> ${h} -else - echo '/* WANT_COLOUR=0 */' >> ${h} -fi - -if feat_yes DOTLOCK; then - echo '#define HAVE_DOTLOCK' >> ${h} -else - echo '/* WANT_DOTLOCK=0 */' >> ${h} -fi - -if feat_yes MD5; then - echo '#define HAVE_MD5' >> ${h} -else - echo '/* WANT_MD5=0 */' >> ${h} -fi - -if feat_yes NOMEMDBG; then - echo '#define HAVE_NOMEMDBG' >> ${h} -else - echo '/* WANT_NOMEMDBG=0 */' >> ${h} -fi +feat_def FILTER_HTML_TAGSOUP +feat_def COLOUR +feat_def DOTLOCK +feat_def MD5 +feat_def NOMEMDBG ## Summarizing -# Since we cat(1) the content of those to cc/"ld", convert them to single line -squeeze_em() { - < "${1}" > "${2}" ${awk} \ - 'BEGIN {ORS = " "} /^[^#]/ {print} {next} END {ORS = ""; print "\n"}' -} ${rm} -f ${tmp} squeeze_em ${inc} ${tmp} ${mv} ${tmp} ${inc} @@ -2406,6 +2376,7 @@ printf '# ifdef HAVE_COLOUR\n ",COLOUR"\n# endif\n' >> ${h} printf '# ifdef HAVE_DOTLOCK\n ",DOTLOCK-FILES"\n# endif\n' >> ${h} printf '# ifdef HAVE_DEBUG\n ",DEBUG"\n# endif\n' >> ${h} printf '# ifdef HAVE_DEVEL\n ",DEVEL"\n# endif\n' >> ${h} +printf '# ifdef HAVE_CROSS_BUILD\n ",CROSS-BUILD"\n# endif\n' >> ${h} printf ';\n# endif /* _ACCMACVAR_SOURCE || HAVE_AMALGAMATION */\n' >> ${h} # Create the real mk.mk diff --git a/mk-mk.in b/mk-mk.in index b793d630..69a57c0a 100644 --- a/mk-mk.in +++ b/mk-mk.in @@ -41,10 +41,14 @@ $(PRIVSEP): privsep.o @if [ -z "$(VERBOSE)" ]; then echo ' LINK $(@)';\ else echo ' $$ $(CC) $(LDFLAGS) -o $(@) privsep.o';\ fi;\ - $(CC) $(LDFLAGS) -o $(@) privsep.o + $(CC) $(LDFLAGS) -o $(@) privsep.o $(BASE_LIBS) @if ( command -v size ) > /dev/null 2>&1; then size $(@); fi -privsep.o: config.h nail.h dotlock.h +privsep.o: privsep.c config.h nail.h dotlock.h + @if [ -z "$(VERBOSE)" ]; then echo ' CC $(@)';\ + else echo ' $$ $(CC) $(CFLAGS) $(BASE_INCS) -c privsep.c';\ + fi;\ + $(CC) $(CFLAGS) $(BASE_INCS) -c privsep.c mime_types.h: mime.types @echo ' GEN $(@)';\ -- 2.11.4.GIT