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, -- Martin Schlemmer
diff -urpN device-mapper.1.01.00/configure.in device-mapper.1.01.00.klibc/configure.in
--- device-mapper.1.01.00/configure.in 2005-01-06 00:00:39.000000000 +0200
+++ device-mapper.1.01.00.klibc/configure.in 2005-03-06 14:31:01.000000000 +0200
@@ -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)
diff -urpN device-mapper.1.01.00/dmsetup/Makefile.in device-mapper.1.01.00.klibc/dmsetup/Makefile.in
--- device-mapper.1.01.00/dmsetup/Makefile.in 2004-07-03 20:17:32.000000000 +0200
+++ device-mapper.1.01.00.klibc/dmsetup/Makefile.in 2005-03-06 14:58:40.000000000 +0200
@@ -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 \
diff -urpN device-mapper.1.01.00/lib/Makefile.in device-mapper.1.01.00.klibc/lib/Makefile.in
--- device-mapper.1.01.00/lib/Makefile.in 2005-01-06 20:22:44.000000000 +0200
+++ device-mapper.1.01.00.klibc/lib/Makefile.in 2005-03-06 14:20:10.000000000 +0200
@@ -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
diff -urpN device-mapper.1.01.00/lib/ioctl/libdm-iface.c device-mapper.1.01.00.klibc/lib/ioctl/libdm-iface.c
--- device-mapper.1.01.00/lib/ioctl/libdm-iface.c 2005-01-13 00:10:14.000000000 +0200
+++ device-mapper.1.01.00.klibc/lib/ioctl/libdm-iface.c 2005-03-06 14:00:40.000000000 +0200
@@ -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);
diff -urpN device-mapper.1.01.00/lib/libdm-file.c device-mapper.1.01.00.klibc/lib/libdm-file.c
--- device-mapper.1.01.00/lib/libdm-file.c 2005-01-06 20:22:44.000000000 +0200
+++ device-mapper.1.01.00.klibc/lib/libdm-file.c 2005-03-06 12:43:18.000000000 +0200
@@ -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)
{
diff -urpN device-mapper.1.01.00/make.tmpl.in device-mapper.1.01.00.klibc/make.tmpl.in
--- device-mapper.1.01.00/make.tmpl.in 2004-07-03 20:17:32.000000000 +0200
+++ device-mapper.1.01.00.klibc/make.tmpl.in 2005-03-06 14:33:10.000000000 +0200
@@ -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
Attachment:
signature.asc
Description: This is a digitally signed message part