]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make: Add toupper and tolower to reduce calls to $(shell)
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 2 Jun 2023 19:14:44 +0000 (15:14 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 2 Jun 2023 19:14:44 +0000 (15:14 -0400)
12 files changed:
Makefile
scripts/build/main.mk
scripts/build/make/dlopen.c [moved from scripts/build/dlopen.c with 99% similarity]
scripts/build/make/dlopen.mk [moved from scripts/build/dlopen.mk with 100% similarity]
scripts/build/make/log.c [moved from scripts/build/log.c with 100% similarity]
scripts/build/make/log.h [moved from scripts/build/log.h with 100% similarity]
scripts/build/make/util.c [new file with mode: 0644]
scripts/build/make/util.mk [new file with mode: 0644]
scripts/build/make/version.c [moved from scripts/build/version.c with 96% similarity]
scripts/build/make/version.mk [moved from scripts/build/version.mk with 100% similarity]
src/tests/ldap_sync/all.mk
src/tests/modules/all.mk

index 7f8dd0a4755aa09c77c539dc6d57c68d520d9de5..185f0fb6d9396ec6cd9abdd01a036a5f07b3f52f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -155,11 +155,12 @@ build/autoconf.mk: src/include/autoconf.h
           ifdef BUILD_MAKE_LIBS
             define n
           endef
-          $(info $(subst CC,$nCC,$(shell $(MAKE) VERBOSE=$(VERBOSE) libfreeradius-make-dlopen.${BUILD_LIB_EXT} libfreeradius-make-version.${BUILD_LIB_EXT})))
+          $(info $(subst CC,$nCC,$(shell $(MAKE) VERBOSE=$(VERBOSE) libfreeradius-make-dlopen.${BUILD_LIB_EXT} libfreeradius-make-version.${BUILD_LIB_EXT} libfreeradius-make-util.${BUILD_LIB_EXT})))
         endif
 
         load build/lib/.libs/libfreeradius-make-dlopen.${BUILD_LIB_EXT}(dlopen_gmk_setup)
         load build/lib/.libs/libfreeradius-make-version.${BUILD_LIB_EXT}(version_gmk_setup)
+        load build/lib/.libs/libfreeradius-make-util.${BUILD_LIB_EXT}(util_gmk_setup)
       else
         BUILD_DIR:=${top_srcdir}/build
         top_builddir:=${top_srcdir}/scripts/build
index 37cf9fcd7820e2a8f957d2ddb11bfe539b0b047d..71b79a43e05c1324f55ba68736a8f91d0b31a2bd 100644 (file)
@@ -1,4 +1,5 @@
 SUBMAKEFILES := \
        ../../src/include/all.mk \
-       dlopen.mk \
-       version.mk
+       make/dlopen.mk \
+       make/version.mk \
+       make/util.mk
similarity index 99%
rename from scripts/build/dlopen.c
rename to scripts/build/make/dlopen.c
index 622fa44fe3994cd01dc3afd646cbb924aeb057d5..f125d9aa2f6de7ee9ad575e2caee3b891b7df64a 100644 (file)
@@ -17,7 +17,7 @@
 /**
  * $Id$
  *
- * @file build/dlopen.c
+ * @file build/make/dlopen.c
  * @brief GNU make plugin to run dlopen()
  *
  * @copyright 2020 Network RADIUS SARL (legal@networkradius.com)
similarity index 100%
rename from scripts/build/log.c
rename to scripts/build/make/log.c
similarity index 100%
rename from scripts/build/log.h
rename to scripts/build/make/log.h
diff --git a/scripts/build/make/util.c b/scripts/build/make/util.c
new file mode 100644 (file)
index 0000000..20f897e
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * $Id$
+ *
+ * @file build/make/util.c
+ * @brief Version comparison functions to avoid horrible builtins
+ *
+ * @copyright 2023 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
+ */
+#include <gnumake.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "log.h"
+
+/*
+ *     The only exported symbol
+ */
+int util_gmk_setup(void);
+
+/*
+ * GNU make insists on this in a loadable object.
+ */
+extern int plugin_is_GPL_compatible;
+int plugin_is_GPL_compatible;
+
+static char *make_tolower(char const *nm, __attribute__((unused))  unsigned int argc, char **argv)
+{
+       size_t  len = strlen(argv[0]);
+       char    *out = gmk_alloc(len + 1);
+       int     i;
+
+       for (i = 0; i < len; i++) out[i] = tolower(argv[0][i]);
+       out[i] = '\0';
+
+       return out;
+}
+
+static char *make_toupper(char const *nm, __attribute__((unused))  unsigned int argc, char **argv)
+{
+       size_t  len = strlen(argv[0]);
+       char    *out = gmk_alloc(len + 1);
+       int     i;
+
+       for (i = 0; i < len; i++) out[i] = toupper(argv[0][i]);
+       out[i] = '\0';
+
+       return out;
+}
+
+int util_gmk_setup(void)
+{
+       gmk_add_function("tolower", &make_tolower, 1, 1, 0); /* min 1, max 1, please expand the input string */
+       gmk_add_function("toupper", &make_toupper, 1, 1, 0); /* min 1, max 1, please expand the input string */
+
+       return 1;
+}
diff --git a/scripts/build/make/util.mk b/scripts/build/make/util.mk
new file mode 100644 (file)
index 0000000..1b43a23
--- /dev/null
@@ -0,0 +1,31 @@
+TARGET                         := libfreeradius-make-util.$(BUILD_LIB_EXT)
+SOURCES                                := util.c log.c
+
+#
+#  This target is NOT built with static analyzer flags.
+#
+$(TARGET): CFLAGS              := $(filter-out -W%,$(filter-out -fsanitize%,$(CFLAGS)))
+$(TARGET): CPPFLAGS            := $(filter-out -W%,$(CPPFLAGS))
+$(TARGET): LDFLAGS             := $(filter-out -fsanitize%,$(LDFLAGS))
+
+#
+#  This gets built with the BUILD_CC i.e. the one we use to bootstrap
+#  this build system.
+#
+SRC_CC := ${HOST_COMPILE.c}
+TGT_LINKER := ${HOST_LINK.c}
+
+#
+#  If we're building this target, then don't try to use it until we know
+#  that building the target succeeds.
+#
+#ifneq "$(MAKECMDGOALS)" "$(TARGET)"
+#load ${BUILD_DIR}/lib/.libs/libfreeradius-make-util.$(BUILD_LIB_EXT)(util_gmk_setup)
+
+#$(info $(dlopen /home/foo/libcrypto,ASN1_verify,/home/user,/foo,/usr/local/Cellar/openssl@1.1/1.1.1d/lib))
+#$(info $(dlsym libcrypto,ASN1_verify))
+#$(info $(dlclose libcrypto))
+
+#$(info $(dlopen libfoobar))
+#$(info $(dlerror ))
+#endif
similarity index 96%
rename from scripts/build/version.c
rename to scripts/build/make/version.c
index 89f4315ff30ca60da5df6e91c24551d0fac304ea..2149161299458b059596a9fcc1d31f165e7bf81c 100644 (file)
@@ -194,9 +194,9 @@ static char *make_version_eq(char const *nm, unsigned int argc, char **argv)
 }
 int version_gmk_setup(void)
 {
-       gmk_add_function("version_gt", &make_version_gt, 2, 2, 0); /* min 1, max 1, please expand the input string */
-       gmk_add_function("version_lt", &make_version_lt, 2, 2, 0); /* min 1, max 1, please expand the input string */
-       gmk_add_function("version_eq", &make_version_eq, 2, 2, 0); /* min 1, max 1, please expand the input string */
+       gmk_add_function("version_gt", &make_version_gt, 2, 2, 0); /* min 2, max 2, please expand the input string */
+       gmk_add_function("version_lt", &make_version_lt, 2, 2, 0); /* min 2, max 2, please expand the input string */
+       gmk_add_function("version_eq", &make_version_eq, 2, 2, 0); /* min 2, max 2, please expand the input string */
 
        return 1;
 }
index c795a6f3864ef788145ec664f3326e3d075f1521..e4883237a63cb5f55fa068f4d39f1ac8cfc8255d 100644 (file)
@@ -9,7 +9,7 @@ TEST := test.ldap_sync
 FILES := $(subst $(DIR)/,,$(wildcard $(DIR)/*/all.mk))
 
 define LDAP_FILTER
-ifeq "$($(shell echo ${1} | tr a-z A-Z)_TEST_SERVER)" ""
+ifeq "$($(toupper ${1})_TEST_SERVER)" ""
   FILES_SKIP += ${2}
 endif
 endef
index b0c32583be46db81182cf1bf2259d6450a77de0e..c84cd7f3f966511355cf753a009f54033786457b 100644 (file)
@@ -46,9 +46,9 @@ else
   ifdef ${1}_require_test_server
     ifdef TEST_SERVER
       # define and export FOO_TEST_SERVER if it's not already defined
-      $(eval export $(shell echo ${1} | tr a-z A-Z)_TEST_SERVER ?= $(TEST_SERVER))
+      $(eval export $(toupper ${1})_TEST_SERVER ?= $(TEST_SERVER))
     endif
-    ifeq "$($(shell echo ${1} | tr a-z A-Z)_TEST_SERVER)" ""
+    ifeq "$($(toupper ${1})_TEST_SERVER)" ""
       # the module requires a test server, but we don't have one.  Skip it.
       FILES_SKIP += ${2}
     endif