Skip to contentSkip to conversation

KLIBC support for device-mapper

PATCH Martin Schlemmer 1 participant 2 messages Mar 6, 2005 – Mar 9, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

This patch adds support for compiling device-mapper against klibc (as of klibc-0.213). Detecting klibc is still fairly crappy, but I will see if we can get that simplified via support from klibc side.

Comments will be appreciated.

Thanks,

Signature · 1 line
Martin Schlemmer
configure.in +59 -17
diff -urpN device-mapper.1.01.00/configure.in device-mapper.1.01.00.klibc/configure.in
@@ -27,21 +27,6 @@ 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"
-		SOFLAG="-shared" ;;
-	darwin*)
-		CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
-		COPTIMISE_FLAG="-O2"
-		CLDFLAGS="$CLDFLAGS"
-		LDDEPS="$LDDEPS"
-		SOFLAG="-dynamiclib" ;;
-esac
-
 ################################################################################
 dnl -- Checks for programs.
 AC_PROG_AWK
@@ -53,12 +38,62 @@ 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 CFLAGS
+AC_ARG_ENABLE(klibc, [  --enable-klibc          Use this to link the tools to klibc.
+                          Set KLCC to the absolute file name of klcc if not
+                          in the PATH. ],  \
+KLIBC=yes, KLIBC=no)
+
+if test x$KLIBC = xyes; then
+	dnl Basic cross compiling support.  I do not think it is wise to use
+	dnl AC_CHECK_TOOL, because if we are cross compiling, we do not want
+	dnl just 'klcc' to be returned ...
+	if test x$cross_compiling = xyes; 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'!)
+		exit 1
+	fi
+	dnl Check what CFLAGS klcc passes to gcc, but filter gcc, -g
+	dnl and the -v option we passed
+	CFLAGS="`$KLCC -v -c 2>&1 | $AWK '{ $1 = ""; gsub(/(^| )(-v|-g)( +|$)/, " "); print; exit }'`"
+	dnl Check what LDFLAGS klcc passes to ld, but filter ld and '-o a.out'
+	KLIBC_LDFLAGS="`$KLCC -v 2>&1 | $AWK '{ $1 = ""; gsub(/(^| )-o *[[^ ]]*( +|$)/, " "); print; exit }'`"
+	KLIBC_LIBDIR="`echo $KLIBC_LDFLAGS | sed -e 's:\(^.* \|^\)\(/[[^[:space:]]]*\)/crt0.o.*:\2:'`"
+	FLAVOUR="klibc "
+fi
+
+################################################################################
+dnl -- Set system type flags, etc
+dnl -- We do not want this with klibc
+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"
+			SOFLAG="-shared" ;;
+		darwin*)
+			CFLAGS="$CFLAGS -no-cpp-precomp -fno-common"
+			COPTIMISE_FLAG="-O2"
+			CLDFLAGS="$CLDFLAGS"
+			LDDEPS="$LDDEPS"
+			SOFLAG="-dynamiclib" ;;
+	esac
+fi
+
+################################################################################
 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.
@@ -191,7 +226,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
@@ -320,6 +358,10 @@ AC_SUBST(tmpdir)
 AC_SUBST(CFLAGS)
 AC_SUBST(COPTIMISE_FLAG)
 AC_SUBST(CLDFLAGS)
+AC_SUBST(KLIBC)
+AC_SUBST(KLIBC_LDFLAGS)
+AC_SUBST(KLIBC_LIBDIR)
+AC_SUBST(LDFLAGS)
 AC_SUBST(LDDEPS)
 AC_SUBST(SOFLAG)
 AC_SUBST(DEBUG)
dmsetup/Makefile.in +16 -4
diff -urpN device-mapper.1.01.00/dmsetup/Makefile.in device-mapper.1.01.00.klibc/dmsetup/Makefile.in
@@ -17,11 +17,16 @@ 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")
+  INSTALL_TYPE = install_dynamic
+else
+  INSTALL_TYPE = install_dynamic
+
+  ifeq ("@STATIC_LINK@", "yes")
+    TARGETS += dmsetup.static
+    INSTALL_TYPE += install_static
+  endif
 endif
 
 SOURCES = dmsetup.c
@@ -29,9 +34,16 @@ CLEAN_TARGETS = dmsetup dmsetup.static
 
 include ../make.tmpl
 
+ifeq ("@KLIBC@", "no")
 dmsetup: $(OBJECTS) $(interfacedir)/libdevmapper.so
 	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) \
 	      -L$(interfacedir) -L$(DESTDIR)/lib -ldevmapper $(LIBS)
+else
+dmsetup: $(OBJECTS) $(interfacedir)/libdevmapper_klibc.a
+	$(LD) -o $@ $(OBJECTS) $(LDFLAGS) \
+	      -L$(interfacedir) -L$(DESTDIR)/$(libdir) -ldevmapper_klibc \
+	      $(LIBS) $(KLIBC_LDFLAGS)
+endif
 
 dmsetup.static: $(OBJECTS) $(interfacedir)/libdevmapper.a
 	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) -static \
lib/Makefile.in +22 -14
diff -urpN device-mapper.1.01.00/lib/Makefile.in device-mapper.1.01.00.klibc/lib/Makefile.in
@@ -21,8 +21,12 @@ SOURCES = libdm-common.c libdm-file.c $(
 
 INCLUDES = -I$(interface)
 
-LIB_STATIC = $(interface)/libdevmapper.a
-LIB_SHARED = $(interface)/libdevmapper.so
+ifeq ("@KLIBC@", "yes")
+  LIB_STATIC = $(interface)/libdevmapper_klibc.a
+else
+  LIB_STATIC = $(interface)/libdevmapper.a
+  LIB_SHARED = $(interface)/libdevmapper.so
+endif
 
 CFLAGS += -DDEVICE_UID=@DEVICE_UID@ -DDEVICE_GID=@DEVICE_GID@ \
 	  -DDEVICE_MODE=@DEVICE_MODE@
@@ -32,35 +36,39 @@ include ../make.tmpl
 .PHONY: install_dynamic install_static \
 	install_fs install_ioctl install_ioctl_static
 
-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)
 
 install_dynamic: install_@interface@
-	$(LN_S) -f libdevmapper.so.$(LIB_VERSION) $(libdir)/libdevmapper.so
+	$(LN_S) -f $(notdir $(LIB_SHARED)).$(LIB_VERSION) $(libdir)/$(notdir $(LIB_SHARED))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 444 libdevmapper.h \
 		$(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
 
-install_fs: fs/libdevmapper.so
+install_fs: fs/$(notdir $(LIB_SHARED))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
-		$(libdir)/libdevmapper.so.$(LIB_VERSION)
+		$(libdir)/$(notdir $(LIB_SHARED)).$(LIB_VERSION)
 
-install_ioctl: ioctl/libdevmapper.so
+install_ioctl: ioctl/$(notdir $(LIB_SHARED))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
-		$(libdir)/libdevmapper.so.$(LIB_VERSION)
+		$(libdir)/$(notdir $(LIB_SHARED)).$(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
 
lib/ioctl/libdm-iface.c +14 -8
diff -urpN device-mapper.1.01.00/lib/ioctl/libdm-iface.c device-mapper.1.01.00.klibc/lib/ioctl/libdm-iface.c
@@ -120,24 +120,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);
lib/libdm-file.c +4 -2
diff -urpN device-mapper.1.01.00/lib/libdm-file.c device-mapper.1.01.00.klibc/lib/libdm-file.c
@@ -16,10 +16,12 @@
 #include "lib.h"
 #include "libdm-file.h"
 
-#include <sys/file.h>
+#ifndef __KLIBC__
+# include <sys/file.h>
+# include <malloc.h>
+#endif
 #include <fcntl.h>
 #include <dirent.h>
-#include <malloc.h>
 
 static int _create_dir_recursive(const char *dir)
 {
make.tmpl.in +14 -3
diff -urpN device-mapper.1.01.00/make.tmpl.in device-mapper.1.01.00.klibc/make.tmpl.in
@@ -28,14 +28,20 @@ CFLAGS += @CFLAGS@
 CLDFLAGS += @CLDFLAGS@
 LDDEPS += @LDDEPS@
 LDFLAGS += @LDFLAGS@
+KLIBC_LDFLAGS += @KLIBC_LDFLAGS@
 SOFLAG += @SOFLAG@
 
 # Setup directory variables
 prefix = @prefix@
 exec_prefix = @exec_prefix@
 bindir = $(DESTDIR)@bindir@
-includedir = $(DESTDIR)@includedir@
-libdir = $(DESTDIR)@libdir@
+ifeq ("@KLIBC@", "no")
+  includedir = $(DESTDIR)@includedir@
+  libdir = $(DESTDIR)@libdir@
+else
+  includedir = $(DESTDIR)@KLIBC_LIBDIR@/../include
+  libdir = $(DESTDIR)@KLIBC_LIBDIR@
+endif
 sbindir = $(DESTDIR)@sbindir@
 infodir = $(DESTDIR)@infodir@
 mandir = $(DESTDIR)@mandir@
@@ -56,7 +62,12 @@ endif
 
 SUFFIXES = .c .d .o .so .a .po .pot .mo
 
-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
 
#1 lore raw
Quoted 6 lines · Martin Schlemmer

Hi,

This patch adds support for compiling device-mapper against klibc (as of klibc-0.213). Detecting klibc is still fairly crappy, but I will see if we can get that simplified via support from klibc side.

Ok, this is a new patch replacing the previous one. It needs klibc-0.217 or 1.0 at least to work.

Comments will be appreciated.

Thanks,

Signature · 18 lines
Martin Schlemmer



-- 
---------------------[ Ciphire Signature ]----------------------
From: [email protected] signed email body (356 characters)
Date: on 09 March 2005 at 11:57:53 UTC
To:   [email protected]
----------------------------------------------------------------
: Ciphire has secured this email against identity theft.
: Free download at www.ciphire.com. The garbled lines
: below are the sender's verifiable digital signature.
----------------------------------------------------------------
00fAAAAAEAAADB5C5CZAEAAPcCAAIAAgACACAjYe/qeWoHRrdDE3mOifT0WPgp92
kbkclxgX1lQsV9VwEAJOQiG+Djg3e7Ai63e8AMF0Hl/gle8q4Ud88Lecx5fcUpaV
5J3bEsvF9qOzLIbuIusij5fNCeJhZjBQGFEgYE9g==
------------------[ End Ciphire Signed Message ]----------------
aclocal.m4 +75 -0
diff -urpN device-mapper.1.01.00/aclocal.m4 device-mapper.1.01.00.klibc/aclocal.m4
@@ -0,0 +1,75 @@
+# 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 GNU gettext library is covered
+## by the GNU Library General Public License, and the rest of the GNU
+## gettext package package is covered by the GNU General Public License.
+## They are *not* in the public domain.
+
+# Authors:
+#   Martin Schlemmer <[email protected]>, 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],
+                              [Use this to link the tools to klibc. Set KLCC
+                               to the absolute file name of klcc if not in
+                               the PATH.])],
+              [KLIBC=yes], [KLIBC=no])
+
+if test "X$KLIBC" = Xyes; 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 "X$cross_compiling" = Xyes; 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)"
+
+  # 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_SUBST(KLIBC_PREFIX)
+AC_SUBST(KLIBC_BIN_DIR)
+AC_SUBST(KLIBC_SBIN_DIR)
+AC_SUBST(KLIBC_LIB_DIR)
+AC_SUBST(KLIBC_INCLUDE_DIR)
+])# AC_CHECK_KLIBC
+
configure.in +37 -19

88 lines not on this page · raw message

dmsetup/Makefile.in +18 -9
diff -urpN device-mapper.1.01.00/dmsetup/Makefile.in device-mapper.1.01.00.klibc/dmsetup/Makefile.in
@@ -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.so
-	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) \
-	      -L$(interfacedir) -L$(DESTDIR)/lib -ldevmapper $(LIBS)
+dmsetup: $(OBJECTS) $(interfacedir)/$(DM_LIBRARY)
+	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) -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)
+	$(CC) -o $@ $(OBJECTS) $(LDFLAGS) -static -L$(interfacedir) \
+	      -L$(DESTDIR)/lib $(DMLIBS) $(LIBS)
 
 install: $(INSTALL_TYPE)
 
lib/Makefile.in +22 -14
diff -urpN device-mapper.1.01.00/lib/Makefile.in device-mapper.1.01.00.klibc/lib/Makefile.in
@@ -21,8 +21,12 @@ SOURCES = libdm-common.c libdm-file.c $(
 
 INCLUDES = -I$(interface)
 
-LIB_STATIC = $(interface)/libdevmapper.a
-LIB_SHARED = $(interface)/libdevmapper.so
+ifeq ("@KLIBC@", "yes")
+  LIB_STATIC = $(interface)/libdevmapper_klibc.a
+else
+  LIB_STATIC = $(interface)/libdevmapper.a
+  LIB_SHARED = $(interface)/libdevmapper.so
+endif
 
 CFLAGS += -DDEVICE_UID=@DEVICE_UID@ -DDEVICE_GID=@DEVICE_GID@ \
 	  -DDEVICE_MODE=@DEVICE_MODE@
@@ -32,35 +36,39 @@ include ../make.tmpl
 .PHONY: install_dynamic install_static \
 	install_fs install_ioctl install_ioctl_static
 
-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)
 
 install_dynamic: install_@interface@
-	$(LN_S) -f libdevmapper.so.$(LIB_VERSION) $(libdir)/libdevmapper.so
+	$(LN_S) -f $(notdir $(LIB_SHARED)).$(LIB_VERSION) $(libdir)/$(notdir $(LIB_SHARED))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 444 libdevmapper.h \
 		$(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
 
-install_fs: fs/libdevmapper.so
+install_fs: fs/$(notdir $(LIB_SHARED))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
-		$(libdir)/libdevmapper.so.$(LIB_VERSION)
+		$(libdir)/$(notdir $(LIB_SHARED)).$(LIB_VERSION)
 
-install_ioctl: ioctl/libdevmapper.so
+install_ioctl: ioctl/$(notdir $(LIB_SHARED))
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
-		$(libdir)/libdevmapper.so.$(LIB_VERSION)
+		$(libdir)/$(notdir $(LIB_SHARED)).$(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
 
lib/ioctl/libdm-iface.c +14 -8
diff -urpN device-mapper.1.01.00/lib/ioctl/libdm-iface.c device-mapper.1.01.00.klibc/lib/ioctl/libdm-iface.c
@@ -120,24 +120,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);
lib/libdm-file.c +4 -2
diff -urpN device-mapper.1.01.00/lib/libdm-file.c device-mapper.1.01.00.klibc/lib/libdm-file.c
@@ -16,10 +16,12 @@
 #include "lib.h"
 #include "libdm-file.h"
 
-#include <sys/file.h>
+#ifndef __KLIBC__
+# include <sys/file.h>
+# include <malloc.h>
+#endif
 #include <fcntl.h>
 #include <dirent.h>
-#include <malloc.h>
 
 static int _create_dir_recursive(const char *dir)
 {
make.tmpl.in +15 -4
diff -urpN device-mapper.1.01.00/make.tmpl.in device-mapper.1.01.00.klibc/make.tmpl.in
@@ -34,9 +34,15 @@ SOFLAG += @SOFLAG@
 prefix = @prefix@
 exec_prefix = @exec_prefix@
 bindir = $(DESTDIR)@bindir@
-includedir = $(DESTDIR)@includedir@
-libdir = $(DESTDIR)@libdir@
-sbindir = $(DESTDIR)@sbindir@
+ifeq ("@KLIBC@", "no")
+  includedir = $(DESTDIR)@includedir@
+  libdir = $(DESTDIR)@libdir@
+  sbindir = $(DESTDIR)@sbindir@
+else
+  includedir = $(DESTDIR)@KLIBC_INCLUDE_DIR@
+  libdir = $(DESTDIR)@KLIBC_LIB_DIR@
+  sbindir = $(DESTDIR)@KLIBC_SBIN_DIR@
+endif
 infodir = $(DESTDIR)@infodir@
 mandir = $(DESTDIR)@mandir@
 localedir = $(DESTDIR)@LOCALEDIR@
@@ -56,7 +62,12 @@ endif
 
 SUFFIXES = .c .d .o .so .a .po .pot .mo
 
-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
 

---------------------[ Ciphire Signature ]----------------------

From: [email protected] signed 'text' (13928 bytes)
Date: on 09 March 2005 at 11:57:53 UTC
To:   [email protected]

----------------------------------------------------------------
: Ciphire has secured this email against identity theft. : Free download at www.ciphire.com. The garbled lines : below are the sender's verifiable digital signature.
----------------------------------------------------------------
01fAAAAAEAAADB5C5CaDYAADADAAIAAgACACAjYe/qeWoHRrdDE3mOifT0WPgp92 kbkclxgX1lQsV9VwEAJOQiG+Djg3e7Ai63e8AMF0Hl/gle8q4Ud88Lecx5fcUcYM C8IVEPhlhjiU316WuClbJp4eHYdJfcJ8naTC+h+A== --------------------[ End Ciphire Signature ]-------------------