From: Arran Cudbard-Bell Date: Fri, 2 Jun 2023 19:14:44 +0000 (-0400) Subject: make: Add toupper and tolower to reduce calls to $(shell) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe2ea7b89312774ce007a2fdc0da27fd41f29a89;p=thirdparty%2Ffreeradius-server.git make: Add toupper and tolower to reduce calls to $(shell) --- diff --git a/Makefile b/Makefile index 7f8dd0a4755..185f0fb6d93 100644 --- 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 diff --git a/scripts/build/main.mk b/scripts/build/main.mk index 37cf9fcd782..71b79a43e05 100644 --- a/scripts/build/main.mk +++ b/scripts/build/main.mk @@ -1,4 +1,5 @@ SUBMAKEFILES := \ ../../src/include/all.mk \ - dlopen.mk \ - version.mk + make/dlopen.mk \ + make/version.mk \ + make/util.mk diff --git a/scripts/build/dlopen.c b/scripts/build/make/dlopen.c similarity index 99% rename from scripts/build/dlopen.c rename to scripts/build/make/dlopen.c index 622fa44fe39..f125d9aa2f6 100644 --- a/scripts/build/dlopen.c +++ b/scripts/build/make/dlopen.c @@ -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) diff --git a/scripts/build/dlopen.mk b/scripts/build/make/dlopen.mk similarity index 100% rename from scripts/build/dlopen.mk rename to scripts/build/make/dlopen.mk diff --git a/scripts/build/log.c b/scripts/build/make/log.c similarity index 100% rename from scripts/build/log.c rename to scripts/build/make/log.c diff --git a/scripts/build/log.h b/scripts/build/make/log.h 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 index 00000000000..20f897e0a7a --- /dev/null +++ b/scripts/build/make/util.c @@ -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 +#include +#include +#include +#include + +#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 index 00000000000..1b43a23d196 --- /dev/null +++ b/scripts/build/make/util.mk @@ -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 diff --git a/scripts/build/version.c b/scripts/build/make/version.c similarity index 96% rename from scripts/build/version.c rename to scripts/build/make/version.c index 89f4315ff30..21491612994 100644 --- a/scripts/build/version.c +++ b/scripts/build/make/version.c @@ -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; } diff --git a/scripts/build/version.mk b/scripts/build/make/version.mk similarity index 100% rename from scripts/build/version.mk rename to scripts/build/make/version.mk diff --git a/src/tests/ldap_sync/all.mk b/src/tests/ldap_sync/all.mk index c795a6f3864..e4883237a63 100644 --- a/src/tests/ldap_sync/all.mk +++ b/src/tests/ldap_sync/all.mk @@ -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 diff --git a/src/tests/modules/all.mk b/src/tests/modules/all.mk index b0c32583be4..c84cd7f3f96 100644 --- a/src/tests/modules/all.mk +++ b/src/tests/modules/all.mk @@ -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