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
SUBMAKEFILES := \
../../src/include/all.mk \
- dlopen.mk \
- version.mk
+ make/dlopen.mk \
+ make/version.mk \
+ make/util.mk
/**
* $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)
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+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
}
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;
}
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
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