Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Some rework on mariadb_config
1) mariadb_config now tries to determine the path from which it was started, in following order:
- if environment variable MARIADB_CONFIG was set
- use system call(s) to determine the path
- if the previous mentioned attemps where unsuccessful, build option CMAKE_INSTALL_PREFIX will be used

2) Added support variables pkglibdir, pkgincludedir and pkgplugindr.

3) Adjusted server version for C/C standalone builds to 10.5.5
  • Loading branch information
9EOR9 committed Sep 13, 2020
1 parent 29a3396 commit 448514a
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -163,8 +163,8 @@ IF(MAJOR_VERSION)
SET(MARIADB_CLIENT_VERSION_EXTRA ${EXTRA_VERSION})
ELSE()
SET(MARIADB_CLIENT_VERSION_MAJOR "10")
SET(MARIADB_CLIENT_VERSION_MINOR "4")
SET(MARIADB_CLIENT_VERSION_PATCH "3")
SET(MARIADB_CLIENT_VERSION_MINOR "5")
SET(MARIADB_CLIENT_VERSION_PATCH "5")
SET(MARIADB_CLIENT_VERSION_EXTRA "")
ENDIF()
SET(MARIADB_CLIENT_VERSION "${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}.${MARIADB_CLIENT_VERSION_PATCH}${MARIADB_CLIENT_VERSION_EXTRA}")
Expand Down
3 changes: 3 additions & 0 deletions cmake/CheckIncludeFiles.cmake
Expand Up @@ -18,6 +18,7 @@ CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H)
CHECK_INCLUDE_FILES (fcntl.h HAVE_FCNTL_H)
CHECK_INCLUDE_FILES (float.h HAVE_FLOAT_H)
CHECK_INCLUDE_FILES (limits.h HAVE_LIMITS_H)
CHECK_INCLUDE_FILES (linux/limits.h HAVE_LINUX_LIMITS_H)
CHECK_INCLUDE_FILES (pwd.h HAVE_PWD_H)
CHECK_INCLUDE_FILES (sched.h HAVE_SCHED_H)
CHECK_INCLUDE_FILES (select.h HAVE_SELECT_H)
Expand All @@ -42,7 +43,9 @@ CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILES (sys/ioctl.h HAVE_SYS_IOCTL_H)
CHECK_INCLUDE_FILES (sys/select.h HAVE_SYS_SELECT_H)
CHECK_INCLUDE_FILES (sys/socket.h HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILES (sys/sysctl.h HAVE_SYS_SYSCTL_H)
CHECK_INCLUDE_FILES (sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES (sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES (sys/un.h HAVE_SYS_UN_H)
CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES (utime.h HAVE_UTIME_H)
Expand Down
3 changes: 3 additions & 0 deletions include/ma_config.h.in
Expand Up @@ -11,6 +11,7 @@
#cmakedefine HAVE_FCNTL_H 1
#cmakedefine HAVE_FLOAT_H 1
#cmakedefine HAVE_LIMITS_H 1
#cmakedefine HAVE_LINUX_LIMITS_H 1
#cmakedefine HAVE_PWD_H 1
#cmakedefine HAVE_SELECT_H 1
#cmakedefine HAVE_STDDEF_H 1
Expand All @@ -21,6 +22,8 @@
#cmakedefine HAVE_SYS_SELECT_H 1
#cmakedefine HAVE_SYS_SOCKET_H 1
#cmakedefine HAVE_SYS_STREAM_H 1
#cmakedefine HAVE_SYS_STAT_H 1
#cmakedefine HAVE_SYS_SYSCTL_H 1
#cmakedefine HAVE_SYS_TYPES_H 1
#cmakedefine HAVE_SYS_UN_H 1
#cmakedefine HAVE_UNISTD_H 1
Expand Down
211 changes: 183 additions & 28 deletions mariadb_config/mariadb_config.c.in
@@ -1,20 +1,45 @@
#include <ma_config.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <mariadb_version.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if defined(HAVE_SYS_SYSCTL_H) && defined(__FreeBSD__)
#include <sys/sysctl.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <unistd.h>
#ifdef HAVE_LINUX_LIMITS_H
#include <linux/limits.h>
#endif
#include <string.h>
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#endif

static char *mariadb_progname;

#define INCLUDE "-I@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDEDIR@ -I@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDEDIR@/mysql"
#define LIBS "-L@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@/@INSTALL_LIBDIR@/ -lmariadb"
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif

#define INCLUDE "-I%s/@INSTALL_INCLUDEDIR@ -I%s/@INSTALL_INCLUDEDIR@/mysql"
#define LIBS "-L%s/@INSTALL_LIBDIR@/ -lmariadb"
#define LIBS_SYS "@extra_dynamic_LDFLAGS@"
#define CFLAGS INCLUDE
#define VERSION "@MARIADB_CLIENT_VERSION@"
#define CC_VERSION "@CPACK_PACKAGE_VERSION@"
#define PLUGIN_DIR "@CMAKE_INSTALL_PREFIX@/@INSTALL_PLUGINDIR@"
#define PLUGIN_DIR "%s/@INSTALL_PLUGINDIR@"
#define SOCKET "@MARIADB_UNIX_ADDR@"
#define PORT "@MARIADB_PORT@"
#define TLS_LIBRARY_VERSION "@TLS_LIBRARY_VERSION@"
#define PKG_INCLUDEDIR "%s/@INSTALL_INCLUDEDIR@"
#define PKG_PLUGINDIR "%s/@INSTALL_PLUGINDIR@"
#define PKG_LIBDIR "%s/@INSTALL_LIBDIR@"

#if defined(SOLARIS) || defined(__sun)
#define OPT_STRING_TYPE (char *)
Expand All @@ -35,9 +60,22 @@ static struct option long_options[]=
{OPT_STRING_TYPE "port", no_argument, 0, 'i'},
{OPT_STRING_TYPE "plugindir", no_argument, 0, 'j'},
{OPT_STRING_TYPE "tlsinfo", no_argument, 0, 'k'},
{OPT_STRING_TYPE "variable", 2, 0, 'm'},
{NULL, 0, 0, 0}
};

static struct {
const char *variable;
const char *value;
} variables[] = {
{"pkgincludedir", PKG_INCLUDEDIR},
{"pkglibdir", PKG_LIBDIR},
{"pkgplugindir", PKG_PLUGINDIR},
{NULL, NULL}
};

char installation_dir[PATH_MAX];

static const char *values[]=
{
CFLAGS,
Expand All @@ -51,7 +89,8 @@ static const char *values[]=
SOCKET,
PORT,
PLUGIN_DIR,
TLS_LIBRARY_VERSION
TLS_LIBRARY_VERSION,
"VAR VAR is one of:"
};

void usage(void)
Expand All @@ -60,19 +99,115 @@ void usage(void)
puts("Copyright 2011-2020 MariaDB Corporation AB");
puts("Get compiler flags for using the MariaDB Connector/C.");
printf("Usage: %s [OPTIONS]\n", mariadb_progname);
printf("Compiler: @CMAKE_C_COMPILER_ID@ @CMAKE_C_COMPILER_VERSION@\n");
while (long_options[i].name)
{
if (values[i])
printf(" --%-12s [%s]\n", long_options[i].name, values[i]);
if (!long_options[i].has_arg)
{
if (values[i])
{
printf(" --%-12s [", long_options[i].name);
printf(values[i], installation_dir, installation_dir);
printf("]\n");
}
} else
{
printf(" --%s=%s\n", long_options[i].name, values[i]);
/* Variables */
if (long_options[i].val == 'm')
{
int i= 0;
while (variables[i].variable)
{
printf(" %-14s [", variables[i].variable);
printf(variables[i].value, installation_dir);
printf("]\n");
i++;
}
}
}

i++;
}
}

/*
mariadb_get_install_location()
Tries to find the installation location in the following order:
1) check if MARIADB_CONFIG environment variable was set
2) try to determine the installation directory from executable path
3) Fallback if 1 and 2 failed: use CMAKE_SYSROOT/CMAKE_INSTALL_PREFIX
*/
static void mariadb_get_install_location()
{
char *p= NULL;
struct stat s;

/* Check environment variable MARIADB_CONFIG */
if ((p= getenv("MARIADB_CONFIG")))
{
if (!stat(p, &s) && S_ISREG(s.st_mode))
{
goto end;
}
}
/* Try to determine path of executable */
if (!(p= alloca(PATH_MAX)))
goto end;
else {
#if defined(__APPLE__)
unsigned int len= PATH_MAX;
if (_NSGetExecutablePath(p, &len) != 0)
*p= 0;
else if (realpath(p, p) != 0)
*p= 0;
#elif defined(__sun) || defined(SOLARIS)
if (realpath(getexecname(), p) == NULL)
*p= 0;
#elif defined(__NetBSD__)
ssize_t len= readlink("/proc/curproc/exe", p, PATH_MAX);
if (len == -1 || len == PATH_MAX)
*p= 0;
#elif defined(__FreeBSD__)
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
size_t cb = PATH_MAX;
if (sysctl(mib, 4, p, &cb, NULL, 0) == -1)
*p= 0;
#elif defined(__linux__)
ssize_t len= readlink("/proc/self/exe", p, PATH_MAX);
if (len == -1 || len == PATH_MAX)
*p= 0;
#elif
*p= 0;
#endif
}
end:
if (p && p[0])
{
char *c, *search= alloca(6 + strlen(mariadb_progname));
sprintf(search, "/bin/%s", mariadb_progname);
c= strstr(p, search);
if (c)
{
strncpy(installation_dir, p, c - p);
}
else
*p=0;
}
if (!p || !p[0])
{
strncpy(installation_dir, "@CMAKE_SYSROOT@@CMAKE_INSTALL_PREFIX@", PATH_MAX - 1);
return;
}
}

int main(int argc, char **argv)
{
int c;
mariadb_progname= argv[0];
char *p = strrchr(argv[0], '/');
mariadb_progname= p ? p + 1 : argv[0];

mariadb_get_install_location();

if (argc <= 1)
{
Expand All @@ -86,43 +221,63 @@ int main(int argc, char **argv)
c= getopt_long(argc, argv, "abcdefghijkl", long_options, &option_index);

switch(c) {
case 'a':
puts(CFLAGS);
case 'a': /* CFLAGS and Include directories */
printf(CFLAGS, installation_dir, installation_dir);
break;
case 'b':
case 'b': /* Usage */
usage();
break;
case 'c':
puts(INCLUDE);
case 'c': /* Include directories */
printf(INCLUDE, installation_dir, installation_dir);
break;
case 'd':
case 'd': /* Library directories and names */
case 'e':
puts(LIBS);
printf(LIBS, installation_dir);
break;
case 'f': /* Server version */
printf(VERSION);
break;
case 'f':
puts(VERSION);
case 'g': /* Connector/C version */
printf(CC_VERSION);
break;
case 'g':
puts(CC_VERSION);
case 'h': /* Unix socket */
printf(SOCKET);
break;
case 'h':
puts(SOCKET);
case 'i': /* default port */
printf(PORT);
break;
case 'i':
puts(PORT);
case 'j': /* plugin directory */
printf(PLUGIN_DIR, installation_dir);
break;
case 'j':
puts(PLUGIN_DIR);
case 'k': /* TLS version */
printf(TLS_LIBRARY_VERSION);
break;
case 'k':
puts(TLS_LIBRARY_VERSION);
case 'l': /* System libraries */
printf(LIBS_SYS);
break;
case 'l':
puts(LIBS_SYS);
case 'm': /* variable */
{
int i= 0;
while (variables[i].variable)
{
if (!strcmp(optarg, variables[i].variable))
{
printf(variables[i].value, installation_dir);
break;
}
i++;
}
if (!variables[i].variable)
{
printf("Unknown variable '%s'\n", optarg);
exit(1);
}
break;
}
default:
exit((c != -1));
}
printf("\n");
}

exit(0);
Expand Down

0 comments on commit 448514a

Please sign in to comment.