[exim-cvs] buildsystem tooling

Góra strony
Delete this message
Reply to this message
Autor: Exim Git Commits Mailing List
Data:  
Dla: exim-cvs
Temat: [exim-cvs] buildsystem tooling
Gitweb: https://git.exim.org/exim.git/commitdiff/baaa69d91ad081a6920f2e29e800a30c8de0255c
Commit:     baaa69d91ad081a6920f2e29e800a30c8de0255c
Parent:     cbe845f056c7a15d97056435a9e112a87f2ad312
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Tue Aug 13 21:19:19 2024 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Wed Aug 14 10:51:49 2024 +0100


    buildsystem tooling
---
 src/OS/Makefile-Base           |   3 +
 src/scripts/Configure-Makefile |   9 ++-
 src/scripts/MakeLinks          |   3 +-
 src/scripts/routers-Makefile   | 180 +++++++++++++++++++++++++++++++++++++++++
 src/src/lookups/Makefile       |  64 +++++----------
 src/src/routers/Makefile       |  61 +++++++++-----
 test/runtest                   |   6 +-
 7 files changed, 258 insertions(+), 68 deletions(-)


diff --git a/src/OS/Makefile-Base b/src/OS/Makefile-Base
index 5b74b6ac8..d45524561 100644
--- a/src/OS/Makefile-Base
+++ b/src/OS/Makefile-Base
@@ -968,6 +968,7 @@ buildlookups: config

 buildrouters: config
      @cd routers && $(MAKE) SHELL=$(SHELL) AR="$(AR)" $(MFLAGS) CC="$(CC)" CFLAGS="$(CFLAGS)" \
+       CFLAGS_DYNAMIC="$(CFLAGS_DYNAMIC)" \
        FE="$(FE)" RANLIB="$(RANLIB)" RM_COMMAND="$(RM_COMMAND)" HDRS="$(PHDRS)" \
        INCLUDE="$(INCLUDE) $(IPV6_INCLUDE) $(TLS_INCLUDE)"
      @echo " "
@@ -976,6 +977,7 @@ buildrouters: config


 buildtransports: config
      @cd transports && $(MAKE) SHELL=$(SHELL) AR="$(AR)" $(MFLAGS) CC="$(CC)" CFLAGS="$(CFLAGS)" \
+       CFLAGS_DYNAMIC="$(CFLAGS_DYNAMIC)" \
        FE="$(FE)" RANLIB="$(RANLIB)" RM_COMMAND="$(RM_COMMAND)" HDRS="$(PHDRS)" \
        INCLUDE="$(INCLUDE) $(IPV6_INCLUDE) $(TLS_INCLUDE)"
      @echo " "
@@ -984,6 +986,7 @@ buildtransports: config


 buildauths: config
      @cd auths && $(MAKE) SHELL=$(SHELL) AR="$(AR)" $(MFLAGS) CC="$(CC)" CFLAGS="$(CFLAGS)" \
+       CFLAGS_DYNAMIC="$(CFLAGS_DYNAMIC)" \
        FE="$(FE)" RANLIB="$(RANLIB)" RM_COMMAND="$(RM_COMMAND)" HDRS="$(PHDRS)" \
        INCLUDE="$(INCLUDE) $(IPV6_INCLUDE) $(TLS_INCLUDE)"
      @echo " "
diff --git a/src/scripts/Configure-Makefile b/src/scripts/Configure-Makefile
index 129f2a073..3b0528940 100755
--- a/src/scripts/Configure-Makefile
+++ b/src/scripts/Configure-Makefile
@@ -4,7 +4,7 @@
 # just got too horrendous to get it right in "make", because of the optionally
 # existing configuration files.
 #
-# Copyright (c) The Exim Maintainers 1995 - 2021
+# Copyright (c) The Exim Maintainers 1995 - 2024
 # SPDX-License-Identifier: GPL-2.0-or-later



@@ -291,6 +291,13 @@ rm -f $mftt
cp ../src/lookups/Makefile $look_mf_pre
../scripts/lookups-Makefile

+class="routers"
+cp ../src/$class/Makefile $class/Makefile.predynamic
+../scripts/$class-Makefile
+mv routers/Makefile.postdynamic $class/Makefile
+rm $class/Makefile.predynamic
+class=
+
 # See if there is a definition of EXIM_PERL in what we have built so far.
 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
diff --git a/src/scripts/MakeLinks b/src/scripts/MakeLinks
index 355f4d6e9..f413c625e 100755
--- a/src/scripts/MakeLinks
+++ b/src/scripts/MakeLinks
@@ -46,7 +46,8 @@ cd ..
 d="routers"
 mkdir $d
 cd $d
-for f in README Makefile accept.h accept.c dnslookup.h dnslookup.c \
+# Makefile is generated
+for f in README accept.h accept.c dnslookup.h dnslookup.c \
   ipliteral.h ipliteral.c iplookup.h iplookup.c manualroute.h \
   manualroute.c queryprogram.h queryprogram.c redirect.h redirect.c \
   rf_functions.h rf_change_domain.c rf_expand_data.c rf_get_errors_address.c \
diff --git a/src/scripts/routers-Makefile b/src/scripts/routers-Makefile
new file mode 100755
index 000000000..5bb6a78d8
--- /dev/null
+++ b/src/scripts/routers-Makefile
@@ -0,0 +1,180 @@
+#! /bin/sh
+
+# Copyright (c) The Exim Maintainers 1995 - 2021
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# We turn the configure-built build-$foo/routers/Makefile.predynamic into Makefile
+
+# We always re-exec ourselves at least once, because it's the cleanest and
+# most portable way to turn on various features we expect of POSIX sh.
+if [ -z "$EXIM_ROUTER_MAKEFILE_ADJUSTED" ]
+then
+  SHELL=/bin/sh
+  EXIM_ROUTER_MAKEFILE_ADJUSTED=yes
+  export EXIM_ROUTER_MAKEFILE_ADJUSTED
+
+  # Solaris sh and tr are problematic until we get xpg4 variants
+  if [ -x /usr/xpg4/bin/sh ]
+  then
+    PATH="/usr/xpg4/bin:$PATH"
+    export PATH
+    SHELL=/usr/xpg4/bin/sh
+    export SHELL
+  fi
+
+  # IRIX uses /bin/ksh for sh but in a compatibility mode unless $_XPG == 1,
+  # where said compatibility mode disables $(...)
+  _XPG=1
+  export _XPG
+
+  # We need the _right_ tr, so must do that first; but if a shell which
+  # we're more confident is sane is available, let's try that.  Mostly,
+  # the problem is that "local" is not actually in "the" standard, it's
+  # just in every not-insane shell.  Though arguably, there are no shells
+  # with POSIX-ish syntax which qualify as "not insane".
+  for b in /bin/dash /bin/bash /usr/local/bin/bash
+  do
+    if [ -x "$b" ]
+    then
+      SHELL="$b"
+      break
+    fi
+  done
+  # if we get a report of a system with zsh but not bash, we can add that
+  # to the list, but be sure to enable sh_word_split in that case.
+
+  exec "$SHELL" "$0" "$@"
+fi
+
+input=routers/Makefile.predynamic
+target=routers/Makefile.postdynamic
+defs_source=Makefile-t
+tag_marker='MAGIC-TAG-MODS-OBJ-RULES-GO-HERE'
+
+tab='    '
+
+# We rely on tr(1) for translating case below.  Some people export
+# values of LC_CTYPE and LC_COLLATE which apparently break our assumptions.
+# We're a script expecting certain output based on known inputs and not dealing
+# with UTF8, so we should be safe doing this:
+LC_ALL=C
+export LC_ALL
+
+if [ -f "$defs_source" ]
+then
+  :
+  # we are happy
+else
+  echo >&2 "$0: ERROR: MISSING FILE '${defs_source}'"
+  echo >&2 "$0: SHOULD HAVE BEEN CALLED FROM scripts/Configure-Makefile"
+  exit 1
+fi
+
+# nb: do not permit leading whitespace for this, as CFLAGS_DYNAMIC is exported
+# to the lookups subdir via a line with leading whitespace which otherwise
+# matches
+if grep -q "^CFLAGS_DYNAMIC[ $tab?:]*=" "$defs_source"
+then
+  # we have a definition, we're good to go
+  echo >&2 ">>> Creating routers/Makefile for building dynamic modules"
+  enable_dynamic=yes
+else
+  echo >&2 ">>> Creating routers/Makefile without dynamic module support"
+  enable_dynamic=''
+  # We always do something now, since there should always be a lookup,
+  # and now we need to run in order to put the OBJ=$(OBJ)+ rules in.  So we
+  # continue on.
+fi
+
+# For the want_ checks, we need to let the user override values from the make
+# command-line, not just check the Makefile.
+
+want_dynamic() {
+  local dyn_name="$1"
+  local re="ROUTER_${dyn_name}[ $tab]*=[ $tab]*2"
+  env | grep -q "^$re"
+  if [ $? -eq 0 ]; then return 0; fi
+  grep -q "^[ $tab]*$re" "$defs_source"
+}
+
+want_at_all() {
+  local want_name="$1"
+  local re="ROUTER_${want_name}[ $tab]*=[ $tab]*."
+  env | grep -q "^$re"
+  if [ $? -eq 0 ]; then return 0; fi
+  grep -q "^[ $tab]*$re" "$defs_source"
+}
+
+# Adapted want_at_all above to work for EXPERIMENTAL features
+want_experimental() {
+  local want_name="$1"
+  local re="EXPERIMENTAL_${want_name}[ $tab]*=[ $tab]*."
+  env | grep -q "^$re"
+  if [ $? -eq 0 ]; then return 0; fi
+  grep -q "^[ $tab]*$re" "$defs_source"
+}
+
+# The values of these variables will be emitted into the Makefile.
+
+MODS=""
+OBJ=""
+
+emit_module_rule() {
+  local name="$1"
+  local mod_name pkgconf
+  if [ "${name%:*}" = "$name" ]
+  then
+    # Square brackets are redundant but benign for POSIX compliant tr,
+    # however Solaris /usr/bin/tr requires them. Sometimes Solaris
+    # gets installed without a complete set of xpg4 tools, sigh.
+    mod_name=$(echo $name | tr [A-Z] [a-z])
+  else
+    mod_name="${name#*:}"
+    name="${name%:*}"
+  fi
+
+  if want_dynamic "$name"
+  then
+    if [ -z "$enable_dynamic" ]; then
+      echo >&2 "Missing CFLAGS_DYNAMIC prevents building dynamic $name"
+      exit 1
+    fi
+    MODS="${MODS} ${mod_name}.so"
+#    pkgconf=$(grep "^ROUTER_${name}_PC" "$defs_source")
+#    if [ $? -eq 0 ]; then
+#      pkgconf=$(echo $pkgconf | sed 's/^.*= *//')
+#      echo "ROUTER_${mod_name}_INCLUDE = $(pkg-config --cflags $pkgconf)"
+#      echo "ROUTER_${mod_name}_LIBS = $(pkg-config --libs $pkgconf)"
+#    else
+#      grep "^ROUTER_${name}_" "$defs_source"
+#      echo "ROUTER_${mod_name}_INCLUDE = \$(ROUTER_${name}_INCLUDE)"
+#      echo "ROUTER_${mod_name}_LIBS = \$(ROUTER_${name}_LIBS)"
+#    fi
+  elif want_at_all "$name"
+  then
+    OBJ="${OBJ} ${mod_name}.o"
+  fi
+}
+
+rm -f "$target"
+exec 5>&1
+exec > "$target"
+
+sed -n "1,/$tag_marker/p" < "$input"
+
+for name_mod in \
+    ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
+do
+  emit_module_rule $name_mod
+done
+
+echo "MODS = $MODS"
+echo "OBJ = $OBJ"
+
+sed -n "/$tag_marker/,\$p" < "$input"
+
+exec >&5
+
+# Configure-Makefile will move $target into place
+
+# vim: set ft=sh sw=2 :
diff --git a/src/src/lookups/Makefile b/src/src/lookups/Makefile
index f305e0655..12d9d88b4 100644
--- a/src/src/lookups/Makefile
+++ b/src/src/lookups/Makefile
@@ -12,7 +12,6 @@



 all:             lookups.a lf_quote.o lf_check_file.o lf_sqlperform.o $(MODS)
-#         for f in *.so; do mv $$f `basename $$f .so`_lookup.so; done


 lookups.a:       $(OBJ)
          @$(RM_COMMAND) -f lookups.a
@@ -31,47 +30,26 @@ lf_check_file.o: $(HDRS) lf_check_file.c  lf_functions.h
 lf_quote.o:      $(HDRS) lf_quote.c       lf_functions.h
 lf_sqlperform.o: $(HDRS) lf_sqlperform.c  lf_functions.h


-cdb.o:           $(HDRS) cdb.c
-dbmdb.o:         $(HDRS) dbmdb.c
-dnsdb.o:         $(HDRS) dnsdb.c
-dsearch.o:       $(HDRS) dsearch.c
-ibase.o:         $(HDRS) ibase.c
-ldap.o:          $(HDRS) ldap.c
-lmdb.o:          $(HDRS) lmdb.c
-json.o:          $(HDRS) json.c
-lsearch.o:       $(HDRS) lsearch.c
-mysql.o:         $(HDRS) mysql.c
-nis.o:           $(HDRS) nis.c
-nisplus.o:       $(HDRS) nisplus.c
-oracle.o:        $(HDRS) oracle.c
-passwd.o:        $(HDRS) passwd.c
-pgsql.o:         $(HDRS) pgsql.c
-readsock.o:      $(HDRS) readsock.c
-redis.o:         $(HDRS) redis.c
-spf.o:           $(HDRS) spf.c
-sqlite.o:        $(HDRS) sqlite.c
-testdb.o:        $(HDRS) testdb.c
-whoson.o:        $(HDRS) whoson.c
-
-cdb.so:           $(HDRS) cdb.c
-dbmdb.so:         $(HDRS) dbmdb.c
-dnsdb.so:         $(HDRS) dnsdb.c
-dsearch.so:       $(HDRS) dsearch.c
-ibase.so:         $(HDRS) ibase.c
-json.so:          $(HDRS) json.c
-ldap.so:          $(HDRS) ldap.c
-lmdb.so:          $(HDRS) lmdb.c
-lsearch.so:       $(HDRS) lsearch.c
-mysql.so:         $(HDRS) mysql.c
-nis.so:           $(HDRS) nis.c
-nisplus.so:       $(HDRS) nisplus.c
-oracle.so:        $(HDRS) oracle.c
-passwd.so:        $(HDRS) passwd.c
-pgsql.so:         $(HDRS) pgsql.c
-redis.so:         $(HDRS) redis.c
-spf.so:           $(HDRS) spf.c
-sqlite.so:        $(HDRS) sqlite.c
-testdb.so:        $(HDRS) testdb.c
-whoson.so:        $(HDRS) whoson.c
+cdb.o cdb.so:           $(HDRS) cdb.c
+dbmdb.o dbmdb.so:       $(HDRS) dbmdb.c
+dnsdb.o dnsdb.so:       $(HDRS) dnsdb.c
+dsearch.o dsearch.so:   $(HDRS) dsearch.c
+ibase.o ibase.so:       $(HDRS) ibase.c
+ldap.o ldap.so:         $(HDRS) ldap.c
+lmdb.o lmdb.so:         $(HDRS) lmdb.c
+json.o json.so:         $(HDRS) json.c
+lsearch.o lsearch.so:   $(HDRS) lsearch.c
+mysql.o mysql.so:       $(HDRS) mysql.c
+nis.o nis.so:           $(HDRS) nis.c
+nisplus.o nisplus.so:   $(HDRS) nisplus.c
+oracle.o oracle.so:     $(HDRS) oracle.c
+passwd.o passwd.so:     $(HDRS) passwd.c
+pgsql.o pgsql.so:       $(HDRS) pgsql.c
+readsock.o readsock.so: $(HDRS) readsock.c
+redis.o redis.so:       $(HDRS) redis.c
+spf.o spf.so:           $(HDRS) spf.c
+sqlite.o sqlite.so:     $(HDRS) sqlite.c
+testdb.o testdb.so:     $(HDRS) testdb.c
+whoson.o whoson.so:     $(HDRS) whoson.c


# End
diff --git a/src/src/routers/Makefile b/src/src/routers/Makefile
index 8f2432d5e..d13a493e9 100644
--- a/src/src/routers/Makefile
+++ b/src/src/routers/Makefile
@@ -2,42 +2,59 @@
# calling it routers.a. This is called from the main make file, after cd'ing
# to the directors subdirectory. The library also contains functions that
# are called only from within the individual routers.
+#
+# Copyright (c) The Exim Maintainers 2021 - 2024

-OBJ = accept.o dnslookup.o ipliteral.o iplookup.o manualroute.o \
-      queryprogram.o redirect.o \
-      rf_change_domain.o rf_expand_data.o rf_get_errors_address.o \
+# nb: at build time, the version of this file used will have had some
+#     extra variable definitions and prepended to it and module build rules
+#     interpolated below. This is done by scripts/routers-Makefile.
+
+# MAGIC-TAG-MODS-OBJ-RULES-GO-HERE
+
+RF_OBJ = rf_change_domain.o rf_expand_data.o rf_get_errors_address.o \
       rf_get_munge_headers.o rf_get_transport.o rf_get_ugid.o \
       rf_lookup_hostlist.o \
       rf_queue_add.o rf_self_action.o \
       rf_set_ugid.o


+OBJ += $(RF_OBJ)
+
+all:             routers.a $(MODS)
+
 routers.a:       $(OBJ)
          @$(RM_COMMAND) -f routers.a
          @echo "$(AR) routers.a"
          @$(AR) routers.a $(OBJ)
          $(RANLIB) $@


-.SUFFIXES:       .o .c
+.SUFFIXES:       .o .c .so
 .c.o:;           @echo "$(CC) $*.c"
          $(FE)$(CC) -c $(CFLAGS) $(INCLUDE) $*.c


-rf_change_domain.o:      $(HDRS) rf_change_domain.c      rf_functions.h
-rf_expand_data.o:        $(HDRS) rf_expand_data.c        rf_functions.h
-rf_get_errors_address.o: $(HDRS) rf_get_errors_address.c rf_functions.h
-rf_get_munge_headers.o:  $(HDRS) rf_get_munge_headers.c  rf_functions.h
-rf_get_transport.o:      $(HDRS) rf_get_transport.c      rf_functions.h
-rf_get_ugid.o:           $(HDRS) rf_get_ugid.c           rf_functions.h
-rf_lookup_hostlist.o:    $(HDRS) rf_lookup_hostlist.c    rf_functions.h
-rf_queue_add.o:          $(HDRS) rf_queue_add.c          rf_functions.h
-rf_self_action.o:        $(HDRS) rf_self_action.c        rf_functions.h
-rf_set_ugid.o:           $(HDRS) rf_set_ugid.c           rf_functions.h
-
-accept.o:        $(HDRS) accept.c       rf_functions.h accept.h
-dnslookup.o:     $(HDRS) dnslookup.c    rf_functions.h dnslookup.h
-ipliteral.o:     $(HDRS) ipliteral.c    rf_functions.h ipliteral.h
-iplookup.o:      $(HDRS) iplookup.c     rf_functions.h iplookup.h
-manualroute.o:   $(HDRS) manualroute.c  rf_functions.h manualroute.h
-queryprogram.o:  $(HDRS) queryprogram.c rf_functions.h queryprogram.h
-redirect.o:      $(HDRS) redirect.c     rf_functions.h redirect.h
+.c.so:;          @echo "$(CC) -shared $*.c"
+         $(FE)$(CC) -DDYNLOOKUP $(CFLAGS_DYNAMIC) $(CFLAGS) $(INCLUDE) $(DLFLAGS) $*.c -o $@
+
+
+
+$(OBJ) $(MOD): $(HDRS) rf_functions.h
+
+rf_change_domain.o:      rf_change_domain.c
+rf_expand_data.o:        rf_expand_data.c
+rf_get_errors_address.o: rf_get_errors_address.c
+rf_get_munge_headers.o:  rf_get_munge_headers.c
+rf_get_transport.o:      rf_get_transport.c
+rf_get_ugid.o:           rf_get_ugid.c
+rf_lookup_hostlist.o:    rf_lookup_hostlist.c
+rf_queue_add.o:          rf_queue_add.c
+rf_self_action.o:        rf_self_action.c
+rf_set_ugid.o:           rf_set_ugid.c
+
+accept.o accept.so:             accept.c       accept.h
+dnslookup.o dnslookup.so:       dnslookup.c    dnslookup.h
+ipliteral.o ipliteral.so:       ipliteral.c    ipliteral.h
+iplookup.o iplookup.so:         iplookup.c     iplookup.h
+manualroute.o manualroute.so:   manualroute.c  manualroute.h
+queryprogram.o queryprogram.so: queryprogram.c queryprogram.h
+redirect.o redirect.so:         redirect.c     redirect.h


# End
diff --git a/test/runtest b/test/runtest
index 1d7589a69..292233551 100755
--- a/test/runtest
+++ b/test/runtest
@@ -1298,11 +1298,15 @@ RESET_AFTER_EXTRA_LINE_READ:

     # drop lookups
     next if /^$time_pid?(?: Lookups\ \((?:built-in|dynamic)\):
-                    |Loaded\ "[^.]+\.so"\ \(\d+\ lookup\ types\)
+                    | Loaded\ "[^.]+\.so"\ \(\d+\ lookup\ types\)
                     | Loading\ lookup\ modules\ from
                     | Loaded\ \d+\ lookup\ modules
                     | Total\ \d+\ lookups)/x;


+    # drop loads of dyn-module drivers
+    next if /^$time_pid?(?:Loading\ \w+\ (?:router|transport|auth)\ driver\ from
+              | Loaded\ \w+\ (?:router|transport|auth)$)/x;
+
     # drop compiler information
     next if /^$time_pid?Compiler:/;



--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-cvs.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-cvs-unsubscribe@???
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/