[dm-devel] Re: KLIBC support for device-mapper-1.01.04

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2005-08-25 at 23:28 +0200, Martin Schlemmer wrote:
> Hi,
> 
> Some time back I sent a patch for KLIBC support for device-mapper, but
> no response so far.  I have however updated the patch.
> 

Ok, I checked multipath-tools again, and did query on the klibc mailing
lists (no real response), and decided to not have the _klibc suffix on
the library.  Also tweaked the build to build a binary default linked
dynamic to klibc, with --enable-static_link giving static linked binary.

Comments once again welcome.


Thanks,

-- 
Martin Schlemmer

diff -urpN device-mapper.1.01.04/aclocal.m4 device-mapper.1.01.04.klibc/aclocal.m4
--- device-mapper.1.01.04/aclocal.m4	1970-01-01 02:00:00.000000000 +0200
+++ device-mapper.1.01.04.klibc/aclocal.m4	2005-08-27 12:48:59.000000000 +0200
@@ -0,0 +1,94 @@
+# klibc.m4 serial 99
+## Copyright (C) 1995-2003 Free Software Foundation, Inc.
+## This file is free software, distributed under the terms of the GNU
+## General Public License.  As a special exception to the GNU General
+## Public License, this file may be distributed as part of a program
+## that contains a configuration script generated by Autoconf, under
+## the same distribution terms as the rest of that program.
+##
+## This file can can be used in projects which are not available under
+## the GNU General Public License or the GNU Library General Public
+## License but which still want to provide support for the GNU gettext
+## functionality.
+## Please note that the actual code of the KLIBC Library is partly covered
+## by the GNU Library General Public License, and party copyrighted by the
+## Regents of The University of California, and the rest is covered by a
+## MIT style license. 
+
+# Authors:
+#   Martin Schlemmer <azarah@xxxxxxxxxxxxxxxx>, 2005.
+
+
+# AC_CHECK_KLIBC
+# --------------
+# Check if the user wants KLIBC support enabled.  If so, set KLIBC=yes and
+# fill in KLIBC_PREFIX, KLIBC_BINDIR, KLIBC_SBINDIR, KLIBC_LIBDIR and
+# KLIBC_INCLUDEDIR.  CC is also set to the proper klcc executable.
+# NOTE:  This should be called before AC_PROG_CC, and before header, function
+#        or type checks.
+AC_DEFUN([AC_CHECK_KLIBC],
+[AC_BEFORE([$0], [AC_PROG_CC])
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_ARG_ENABLE([klibc],
+              [AS_HELP_STRING([--enable-klibc],
+                              [Enable linking to klibc [no].  You need at
+                               least klibc-1.0 or later for this.  Set KLCC
+                               to the absolute file name of klcc if not in
+                               the PATH])],
+              [KLIBC=$enableval], [KLIBC=no])
+AC_ARG_ENABLE([klibc-layout],
+              [AS_HELP_STRING([--enable-klibc-layout],
+                              [Enable installing binaries, libraries and
+                               headers into the klibc prefix [yes] ])],
+              [if test "X$KLIBC" != Xno; then
+                 KLIBC_LAYOUT=$enableval
+               else
+                 KLIBC_LAYOUT=no
+               fi],
+              [if test "X$KLIBC" != Xno; then
+                 KLIBC_LAYOUT=yes
+               else
+                 KLIBC_LAYOUT=no
+               fi])
+
+if test "X$KLIBC" != Xno; then
+  # Basic cross compiling support.  I do not think it is wise to use
+  # AC_CHECK_TOOL, because if we are cross compiling, we do not want
+  # just 'klcc' to be returned ...
+  if test "${host_alias}" != "${build_alias}"; then
+    AC_CHECK_PROGS([KLCC], [${host_alias}-klcc], [no])
+  else
+    AC_CHECK_PROGS([KLCC], [klcc], [no])
+  fi
+  if test "X$KLCC" = Xno; then
+    AC_MSG_ERROR([cannot find klibc frontend 'klcc'!])
+  fi
+
+  CC="$KLCC"
+  CFLAGS="-Os"
+
+  KLIBC_KCROSS="$($KLCC -print-klibc-kcross 2>/dev/null)"
+  KLIBC_PREFIX="$($KLCC -print-klibc-prefix 2>/dev/null)"
+  KLIBC_BIN_DIR="$($KLCC -print-klibc-bindir 2>/dev/null)"
+  KLIBC_SBIN_DIR="${KLIBC_PREFIX}/${KLIBC_KCROSS}sbin"
+  KLIBC_LIB_DIR="$($KLCC -print-klibc-libdir 2>/dev/null)"
+  KLIBC_INCLUDE_DIR="$($KLCC -print-klibc-includedir 2>/dev/null)"
+
+  if test "X$KLIBC_LAYOUT" != Xno; then
+    prefix="$KLIBC_PREFIX"
+    bindir="$KLIBC_BIN_DIR"
+    sbindir="$KLIBC_SBIN_DIR"
+    libdir="$KLIBC_LIB_DIR"
+    includedir="$KLIBC_INCLUDE_DIR"
+  fi
+
+  # At least KLIBC_LIB_DIR should be valid, else klibc is too old or
+  # something went wrong
+  if test ! -d "$KLIBC_LIB_DIR"; then
+    AC_MSG_ERROR([your klibc installation is too old or not functional!])
+  fi
+fi
+
+AC_SUBST(KLIBC)
+])# AC_CHECK_KLIBC
+
diff -urpN device-mapper.1.01.04/configure.in device-mapper.1.01.04.klibc/configure.in
--- device-mapper.1.01.04/configure.in	2005-08-02 23:04:51.000000000 +0200
+++ device-mapper.1.01.04.klibc/configure.in	2005-08-27 12:48:59.000000000 +0200
@@ -27,42 +27,64 @@ AC_CONFIG_AUX_DIR(autoconf) 
 dnl -- Get system type
 AC_CANONICAL_SYSTEM
 
-case "$host_os" in
-	linux*)
-		CFLAGS="$CFLAGS"
-		COPTIMISE_FLAG="-O2"
-		CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
-		LDDEPS="$LDDEPS .export.sym"
-		LIB_SUFFIX="so"
-		DMIOCTLS="yes"
-		SELINUX="yes" ;;
-	darwin*)
-		CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
-		COPTIMISE_FLAG="-O2"
-		CLDFLAGS="$CLDFLAGS"
-		LDDEPS="$LDDEPS"
-		LIB_SUFFIX="dylib"
-		DMIOCTLS="no"
-		SELINUX="no" ;;
-esac
-
 ################################################################################
 dnl -- Checks for programs.
 AC_PROG_AWK
-AC_PROG_CC
-AC_PROG_GCC_TRADITIONAL
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
 AC_PROG_RANLIB
 
 ################################################################################
+dnl -- Enables linking to klibc
+dnl -- We need to do this before header checks, as we need to set CC
+AC_CHECK_KLIBC
+
+################################################################################
+dnl -- Set system type flags, etc
+if test x$KLIBC != xyes; then
+	case "$host_os" in
+		linux*)
+			CFLAGS="$CFLAGS"
+			COPTIMISE_FLAG="-O2"
+			CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
+			LDDEPS="$LDDEPS .export.sym"
+			LIB_SUFFIX="so"
+			DMIOCTLS="yes"
+			SELINUX="yes" ;;
+		darwin*)
+			CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
+			COPTIMISE_FLAG="-O2"
+			CLDFLAGS="$CLDFLAGS"
+			LDDEPS="$LDDEPS"
+			LIB_SUFFIX="dylib"
+			DMIOCTLS="no"
+			SELINUX="no" ;;
+	esac
+else
+	dnl -- We only support linux with klibc ...
+	CFLAGS="$CFLAGS"
+	COPTIMISE_FLAG=
+	CLDFLAGS="$CLDFLAGS -Wl,--version-script,.export.sym"
+	LDDEPS="$LDDEPS .export.sym"
+	LIB_SUFFIX="a"
+	DMIOCTLS="yes"
+	SELINUX="no"
+fi
+
+################################################################################
+dnl -- Checks for CC.
+dnl -- Should be after klibc check.
+AC_PROG_CC
+AC_PROG_GCC_TRADITIONAL
+
+################################################################################
 dnl -- Checks for header files.
 AC_HEADER_DIRENT
 AC_HEADER_STDC
 AC_HEADER_TIME
 
-AC_CHECK_HEADERS(ctype.h dirent.h errno.h fcntl.h getopt.h inttypes.h limits.h stdarg.h stdio.h stdlib.h string.h sys/ioctl.h sys/param.h sys/stat.h sys/types.h unistd.h,,AC_MSG_ERROR(bailing out))
+AC_CHECK_HEADERS(ctype.h dirent.h errno.h fcntl.h inttypes.h limits.h stdarg.h stdio.h stdlib.h string.h sys/ioctl.h sys/param.h sys/stat.h sys/types.h unistd.h,,AC_MSG_ERROR(bailing out))
 
 ################################################################################
 dnl -- Checks for typedefs, structures, and compiler characteristics.
@@ -206,7 +228,10 @@ fi
 
 ################################################################################
 dnl -- Check for getopt
-AC_CHECK_HEADERS(getopt.h, CFLAGS="$CFLAGS -DHAVE_GETOPTLONG")
+dnl -- We do not want this with klibc
+if test x$KLIBC != xyes; then
+	AC_CHECK_HEADERS(getopt.h, CFLAGS="$CFLAGS -DHAVE_GETOPTLONG")
+fi
 
 ################################################################################
 dnl -- Internationalisation stuff
diff -urpN device-mapper.1.01.04/dmsetup/Makefile.in device-mapper.1.01.04.klibc/dmsetup/Makefile.in
--- device-mapper.1.01.04/dmsetup/Makefile.in	2005-01-27 18:16:52.000000000 +0200
+++ device-mapper.1.01.04.klibc/dmsetup/Makefile.in	2005-08-27 12:58:32.000000000 +0200
@@ -19,6 +19,10 @@ VPATH = @srcdir@
 TARGETS = dmsetup
 INSTALL_TYPE = install_dynamic
 
+ifeq ("@KLIBC@", "yes")
+  EXTRA_LDFLAGS = -shared
+endif
+
 ifeq ("@STATIC_LINK@", "yes")
   TARGETS += dmsetup.static
   INSTALL_TYPE += install_static
@@ -30,7 +34,7 @@ CLEAN_TARGETS = dmsetup dmsetup.static
 include ../make.tmpl
 
 dmsetup: $(OBJECTS) $(interfacedir)/libdevmapper.$(LIB_SUFFIX)
-	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) \
+	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) $(EXTRA_LDFLAGS) \
 	      -L$(interfacedir) -L$(DESTDIR)/lib -ldevmapper $(LIBS)
 
 dmsetup.static: $(OBJECTS) $(interfacedir)/libdevmapper.a
diff -urpN device-mapper.1.01.04/dmsetup/dmsetup.c device-mapper.1.01.04.klibc/dmsetup/dmsetup.c
--- device-mapper.1.01.04/dmsetup/dmsetup.c	2005-07-29 18:11:23.000000000 +0200
+++ device-mapper.1.01.04.klibc/dmsetup/dmsetup.c	2005-08-27 12:48:59.000000000 +0200
@@ -26,7 +26,9 @@
 #include <dirent.h>
 #include <errno.h>
 #include <unistd.h>
-#include <libgen.h>
+#ifndef __KLIBC__
+# include <libgen.h>
+#endif
 #include <sys/wait.h>
 #include <unistd.h>
 #include <sys/param.h>
@@ -1054,7 +1056,18 @@ static int _process_switches(int *argc, 
 	memset(&_values, 0, sizeof(_values));
 
 	namebase = strdup((*argv)[0]);
+#ifndef __KLIBC__
 	base = basename(namebase);
+#else
+	base = strrchr(namebase, '/');
+	if (base != NULL)
+		/* Remove leading '/' */
+		base++;
+	else
+		/* Already basename ? */
+		base = namebase;
+	
+#endif
 
 	if (!strcmp(base, "devmap_name")) {
 		free(namebase);
diff -urpN device-mapper.1.01.04/lib/Makefile.in device-mapper.1.01.04.klibc/lib/Makefile.in
--- device-mapper.1.01.04/lib/Makefile.in	2005-04-28 00:32:00.000000000 +0200
+++ device-mapper.1.01.04.klibc/lib/Makefile.in	2005-08-27 12:48:59.000000000 +0200
@@ -47,8 +47,14 @@ include ../make.tmpl
 
 INSTALL_TYPE = install_dynamic
 
-ifeq ("@STATIC_LINK@", "yes")
-  INSTALL_TYPE += install_static
+ifeq ("@KLIBC@", "yes")
+  INSTALL_TYPE = install_static
+else
+  INSTALL_TYPE = install_dynamic
+
+  ifeq ("@STATIC_LINK@", "yes")
+    INSTALL_TYPE += install_static
+  endif
 endif
 
 install: $(INSTALL_TYPE)
diff -urpN device-mapper.1.01.04/lib/ioctl/libdm-iface.c device-mapper.1.01.04.klibc/lib/ioctl/libdm-iface.c
--- device-mapper.1.01.04/lib/ioctl/libdm-iface.c	2005-06-13 15:11:48.000000000 +0200
+++ device-mapper.1.01.04.klibc/lib/ioctl/libdm-iface.c	2005-08-27 12:48:59.000000000 +0200
@@ -122,24 +122,30 @@ static int _get_proc_number(const char *
 			    uint32_t *number)
 {
 	FILE *fl;
-	char nm[256];
-	int c;
+	char nm[256], buf[300];
+	int num, size;
 
 	if (!(fl = fopen(file, "r"))) {
 		log_error("%s: fopen failed: %s", file, strerror(errno));
 		return 0;
 	}
 
-	while (!feof(fl)) {
-		if (fscanf(fl, "%d %255s\n", number, &nm[0]) == 2) {
+	/* Use fread+sscanf for klibc compatibility. */
+	do {
+		size = 0;
+		do {
+			num = fread(&buf[size], sizeof(char), 1, fl);
+			if (num > 0)
+				size++;
+		} while (num > 0 && buf[size - 1] != '\n');
+		buf[size] = '\0';
+		if (sscanf(buf, "%d %255s\n", number, &nm[0]) == 2) {
 			if (!strcmp(name, nm)) {
 				fclose(fl);
 				return 1;
 			}
-		} else do {
-			c = fgetc(fl);
-		} while (c != EOF && c != '\n');
-	}
+		}
+	} while (num > 0);
 	fclose(fl);
 
 	log_error("%s: No entry for %s found", file, name);
@@ -151,6 +157,7 @@ static int _control_device_number(uint32
 	if (!_get_proc_number(PROC_DEVICES, MISC_NAME, major) ||
 	    !_get_proc_number(PROC_MISC, DM_NAME, minor)) {
 		*major = 0;
+		printf("Failed to get device number!\n");
 		return 0;
 	}
 
diff -urpN device-mapper.1.01.04/lib/libdm-file.c device-mapper.1.01.04.klibc/lib/libdm-file.c
--- device-mapper.1.01.04/lib/libdm-file.c	2005-01-27 18:16:54.000000000 +0200
+++ device-mapper.1.01.04.klibc/lib/libdm-file.c	2005-08-27 12:48:59.000000000 +0200
@@ -16,11 +16,13 @@
 #include "lib.h"
 #include "libdm-file.h"
 
-#include <sys/file.h>
+#ifndef __KLIBC__
+# include <sys/file.h>
+#endif
 #include <fcntl.h>
 #include <dirent.h>
 
-#ifdef linux
+#if defined(linux) && !defined(__KLIBC__)
 #  include <malloc.h>
 #endif
 
diff -urpN device-mapper.1.01.04/make.tmpl.in device-mapper.1.01.04.klibc/make.tmpl.in
--- device-mapper.1.01.04/make.tmpl.in	2005-01-27 18:16:51.000000000 +0200
+++ device-mapper.1.01.04.klibc/make.tmpl.in	2005-08-27 12:48:59.000000000 +0200
@@ -56,7 +56,12 @@ endif
 
 .SUFFIXES: .c .d .o .so .a .po .pot .mo .dylib
 
-CFLAGS += -fPIC -Wall -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline
+CFLAGS+=-fPIC -Wall -Wundef -Wcast-align -Wwrite-strings -Winline
+
+ifeq ("@KLIBC@", "no")
+  # These ones make klibc compiles very loud
+  CFLAGS+=-Wshadow -Wmissing-prototypes -Wmissing-declarations -Wnested-externs
+endif
 
 #CFLAGS += -W -Wconversion -Wpointer-arith -Wredundant-decls -Wbad-function-cast -Wcast-qual -Wmissing-noreturn
 

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux