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

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



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.

Comments and suggestions appreciated.


Regards,

-- 
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-25 21:31:31.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 nosferatu za org>, 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-25 23:19:40.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-25 21:44:16.000000000 +0200
@@ -17,11 +17,20 @@ top_srcdir = @top_srcdir@
 VPATH = @srcdir@
 
 TARGETS = dmsetup
-INSTALL_TYPE = install_dynamic
 
-ifeq ("@STATIC_LINK@", "yes")
-  TARGETS += dmsetup.static
-  INSTALL_TYPE += install_static
+ifeq ("@KLIBC@", "yes")
+  DMLIBS += -ldevmapper_klibc
+  DM_LIBRARY = libdevmapper_klibc.a
+  INSTALL_TYPE = install_dynamic
+else
+  DMLIBS += -ldevmapper
+  DM_LIBRARY = libdevmapper.so
+  INSTALL_TYPE = install_dynamic
+
+  ifeq ("@STATIC_LINK@", "yes")
+    TARGETS += dmsetup.static
+    INSTALL_TYPE += install_static
+  endif
 endif
 
 SOURCES = dmsetup.c
@@ -29,13 +38,13 @@ CLEAN_TARGETS = dmsetup dmsetup.static
 
 include ../make.tmpl
 
-dmsetup: $(OBJECTS) $(interfacedir)/libdevmapper.$(LIB_SUFFIX)
+dmsetup: $(OBJECTS) $(interfacedir)/$(DM_LIBRARY)
 	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) \
-	      -L$(interfacedir) -L$(DESTDIR)/lib -ldevmapper $(LIBS)
+	      -L$(interfacedir) -L$(DESTDIR)/lib $(DMLIBS) $(LIBS)
 
 dmsetup.static: $(OBJECTS) $(interfacedir)/libdevmapper.a
 	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) -static \
-	      -L$(interfacedir) -L$(DESTDIR)/lib -ldevmapper $(LIBS)
+	      -L$(interfacedir) -L$(DESTDIR)/lib $(DMLIBS) $(LIBS)
 
 install: $(INSTALL_TYPE)
 
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-25 22:34:33.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-25 21:40:07.000000000 +0200
@@ -29,12 +29,16 @@ SOURCES = libdm-common.c libdm-file.c $(
 
 INCLUDES = -I$(interface)
 
-LIB_STATIC = $(interface)/libdevmapper.a
-
-ifeq ("@LIB_SUFFIX@","dylib")
-  LIB_SHARED = $(interface)/libdevmapper.dylib
+ifeq ("@KLIBC@", "yes")
+  LIB_STATIC = $(interface)/libdevmapper_klibc.a
 else
-  LIB_SHARED = $(interface)/libdevmapper.so
+  LIB_STATIC = $(interface)/libdevmapper.a
+
+  ifeq ("@LIB_SUFFIX@","dylib")
+    LIB_SHARED = $(interface)/libdevmapper.dylib
+  else
+    LIB_SHARED = $(interface)/libdevmapper.so
+  endif
 endif
 
 CFLAGS += -DDEVICE_UID= DEVICE_UID@ -DDEVICE_GID= DEVICE_GID@ \
@@ -47,8 +51,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)
@@ -60,7 +70,8 @@ install_dynamic: install_ interface@
 		$(includedir)/libdevmapper.h
 
 install_static: install_ interface@_static
-	$(LN_S) -f libdevmapper.a.$(LIB_VERSION) $(libdir)/libdevmapper.a
+	$(LN_S) -f $(notdir $(LIB_STATIC)).$(LIB_VERSION) \
+		$(libdir)/$(notdir $(LIB_STATIC))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 444 libdevmapper.h \
 		$(includedir)/libdevmapper.h
 
@@ -72,9 +83,9 @@ install_ioctl: ioctl/libdevmapper.$(LIB_
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
 		$(libdir)/libdevmapper.$(LIB_SUFFIX).$(LIB_VERSION)
 
-install_ioctl_static: ioctl/libdevmapper.a
+install_ioctl_static: ioctl/$(notdir $(LIB_STATIC))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
-		$(libdir)/libdevmapper.a.$(LIB_VERSION)
+		$(libdir)/$(notdir $(LIB_STATIC)).$(LIB_VERSION)
 
 .PHONY: distclean_lib distclean
 
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-25 22:14:24.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-25 21:41:49.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-25 21:31:17.000000000 +0200
@@ -56,7 +55,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


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