Re: [xml] Windows CE port for current stable libxml2



Daniel Veillard wrote:

The only thing I will point out is that it touches some of the trio
files so maybe this need to be reflected by the upstream trio project
(if still alive :-)

Alive enough to take patches :)

I have upgraded the trio project with the changes, albeit with a few
changes, e.g. I have eliminated the need for wincecompat.h which is
a libxml file. Thanks Andreas.

The patch does not include the configuration file that is
also needed (I had to disable a few features which won't build
and I don't need). I think it would be best to add a
configuration file like include/win32config.h named
include/winCEconfig.h?


I'm not too fond of adding one file per Windows version honnestly
Can't this really be merged considering there is ways to sort it
out at the preprocessor level ?

This may be a good time to draw attention to a project of mine called
cDetect [1].

cDetect is an alternative to Autoconf, where the feature detection is
written in ANSI C. This means that it only requires a C compiler (which
you are going to need anyways), and it works in the same way on both
Unix and Windows.

cDetect is still in alpha (or beta) stage, mainly because I still have
to iron out some details in the API. This means that cDetect is not
quite ready for prime time yet, but eventually it will be.

I have attached an example of how the libxml feature detection could
look, just to give you an idea (it is an older example that I used to
develop the API). The example will not compile as further files are
needed, but I can provide these if you are interested.

[1] http://cdetect.sourceforge.net/
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */

#include "cdetect.c"
#include "cdetect/autoconf.c"
/* #include "cdetect/automake.c" */
#include "cdetect/libxml.c"

const int libxml_major_version = 2;
const int libxml_minor_version = 6;
const int libxml_micro_version = 22;

/*
 * Register command-line options
 */

void libxml_register(void)
{
    config_build_register("libxml-in.txt", "libxml-out.txt");

    config_option_register_group("Optional Features");
    config_option_register("enable-ipv6", 0, "yes", "yes", "Enables compilation of IPv6 code");
    config_option_register_group("Optional Packages");
    config_option_register("with-c14n", 0, "yes", "yes", "Add Canonicalization support");
    config_option_register("with-catalog", 0, "yes", "yes", "Add Catalog support");
    config_option_register("with-debug", 0, "yes", "yes", "Add debugging module");
    config_option_register("with-docbook", 0, "yes", "yes", "Add Docbook SGML support");
    config_option_register("with-fexceptions", 0, "no", "yes", "Allow GCC to use C++ exceptions");
    config_option_register("with-ftp", 0, "yes", "yes", "Add FTP support");
    config_option_register("with-history", 0, "no", "yes", "Add history support to xmllint shell");
    config_option_register("with-html", 0, "yes", "yes", "Add HTML support");
    config_option_register("with-html-dir", 0, "${datadir}/doc", "", "Path to base HTML directory");
    config_option_register("with-html-subdir", 0, "${PACKAGE}-${VERSION}/html", "", "Directory used under 
html-dir");
    config_option_register("with-http", 0, "yes", "yes", "Add HTTP support");
    config_option_register("with-iconv", 0, "", "", "Add ICONV support");
    config_option_register("with-iso8859x", 0, "yes", "yes", "Add ISO-8859-X support if not ICONV");
    config_option_register("with-mem-debug", 0, "no", "yes", "Add the memory debugging module");
    config_option_register("with-minimum", 0, "no", "yes", "Build a minimally sized library");
    config_option_register("with-modules", 0, "yes", "yes", "Add dynamic modules support");
    config_option_register("with-output", 0, "yes", "yes", "Add serialization support");
    config_option_register("with-pattern", 0, "yes", "yes", "Add xmlPattern selection interface");
    config_option_register("with-push", 0, "yes", "yes", "Add push parser interface");
    config_option_register("with-python", 0, "/usr/local/python", "", "Build Python bindings if found");
    config_option_register("with-reader", 0, "yes", "yes", "Add xmlReader parsing interface");
    config_option_register("with-readline", 0, "", "no", "Use readline");
    config_option_register("with-regexps", 0, "yes", "yes", "Add Regular Expressions support");
    config_option_register("with-run-debug", 0, "no", "yes", "Add run-time debugging module");
    config_option_register("with-sax1", 0, "yes", "yes", "Add SAX version 1 interface");
    config_option_register("with-schemas", 0, "yes", "yes", "Add Schemas and Relax-NG support");
    config_option_register("with-schematron", 0, "yes", "yes", "Add Schematron support");
    config_option_register("with-threads", 0, "yes", "yes", "Add multi-thread support");
    config_option_register("with-thread-alloc", 0, "no", "yes", "Add per-thread memory");
    config_option_register("with-tree", 0, "yes", "yes", "Add DOM-like tree manipulation interface");
    config_option_register("with-valid", 0, "yes", "yes", "Add DTD validation support");
    config_option_register("with-writer", 0, "yes", "yes", "Add xmlWriter saving interface");
    config_option_register("with-xinclude", 0, "yes", "yes", "Add XInclude support");
    config_option_register("with-xpath", 0, "yes", "yes", "Add XPath support");
    config_option_register("with-xptr", 0, "yes", "yes", "Add XPointer support");
    config_option_register("with-zlib", 0, "", "yes", "Use libz");
}

/*
 * Resolve dependencies between command-line options
 */

void libxml_dependencies(void)
{
    const char *option;

    if (config_equal(config_option_get("with-schemas"), "yes")) {
        config_option_set("with-pattern", "yes");
        config_option_set("with-regexp", "yes");
    }

    if (config_equal(config_option_get("with-schematron"), "yes")) {
        config_option_set("with-pattern", "yes");
        config_option_set("with-xpath", "yes");
    }

    if (config_equal(config_option_get("with-reader"), "yes")) {
        config_option_set("with-push", "yes");
    }

    if (config_equal(config_option_get("with-xptr"), "yes")) {
        config_option_set("with-xpath", "yes");
    }

    if (config_equal(config_option_get("with-minimum"), "yes")) {
        config_option_get("with-c14n") || config_option_set("with-c14n", "no");
        config_option_get("with-catalog") || config_option_set("with-catalog", "no");
        config_option_get("with-debug") || config_option_set("with-debug", "no");
        config_option_get("with-docbook") || config_option_set("with-docbook", "no");
        config_option_get("with-fexceptions") || config_option_set("with-fexceptions", "no");
        config_option_get("with-ftp") || config_option_set("with-ftp", "no");
        config_option_get("with-history") || config_option_set("with-history", "no");
        config_option_get("with-html") || config_option_set("with-html", "no");
        config_option_get("with-http") || config_option_set("with-http", "no");
        config_option_get("with-iconv") || config_option_set("with-iconv", "no");
        config_option_get("with-iso8859x") || config_option_set("with-iso8859x", "no");
        config_option_get("with-legacy") || config_option_set("with-legacy", "no");
        config_option_get("with-mem-debug") || config_option_set("with-mem-debug", "no");
        config_option_get("with-modules") || config_option_set("with-modules", "no");
        config_option_get("with-output") || config_option_set("with-output", "no");
        config_option_get("with-pattern") || config_option_set("with-pattern", "no");
        config_option_get("with-python") || config_option_set("with-python", "no");
        config_option_get("with-reader") || config_option_set("with-reader", "no");
        config_option_get("with-readline") || config_option_set("with-readline", "no");
        config_option_get("with-regexp") || config_option_set("with-regexp", "no");
        config_option_get("with-run-debug") || config_option_set("with-run-debug", "no");
        config_option_get("with-sax1") || config_option_set("with-sax1", "no");
        config_option_get("with-schemas") || config_option_set("with-schemas", "no");
        config_option_get("with-schematron") || config_option_set("with-schematron", "no");
        config_option_get("with-threads") || config_option_set("with-threads", "no");
        config_option_get("with-thread-alloc") || config_option_set("with-thread-alloc", "no");
        config_option_get("with-tree") || config_option_set("with-tree", "no");
        config_option_get("with-valid") || config_option_set("with-valid", "no");
        config_option_get("with-writer") || config_option_set("with-writer", "no");
        config_option_get("with-xinclude") || config_option_set("with-xinclude", "no");
        config_option_get("with-xpath") || config_option_set("with-xpath", "no");
        config_option_get("with-xptr") || config_option_set("with-xptr", "no");
    }

    /* Add include and library path for readline */
    option = config_option_get("with-readline");
    if ((option != 0) && (*option != 0) && !config_equal(option, "yes") && !config_equal(option, "no")) {
        config_tool_define_format("CPPFLAGS", "@CPPFLAGS=@ -I%s/include", option);
        config_tool_define_format("LDFLAGS", "@LDFLAGS=@ -L%s/lib", option);
    }

    /* Add include and library path for zlib */
    option = config_option_get("with-zlib");
    if ((option != 0) && (*option != 0) && !config_equal(option, "yes") && !config_equal(option, "no")) {
        config_tool_define_format("CPPFLAGS", "@CPPFLAGS=@ -I%s/include", option);
        config_tool_define_format("LDFLAGS", "@LDFLAGS=@ -L%s/lib", option);
    }
}

/*
 * Build library version
 */

void libxml_build_version(void)
{
    config_tool_define_format("LIBXML_MAJOR_VERSION", "%d", libxml_major_version);
    config_tool_define_format("LIBXML_MINOR_VERSION", "%d", libxml_minor_version);
    config_tool_define_format("LIBXML_MICRO_VERSION", "%d", libxml_micro_version);
    config_tool_define("LIBXML_MICRO_VERSION_SUFFIX", "");
    config_tool_define("LIBXML_VERSION", "@LIBXML_MAJOR_VERSION  @LIBXML_MINOR_VERSION  
@LIBXML_MICRO_VERSION@@LIBXML_MICRO_VERSION_SUFFIX@");
    config_tool_define_format("LIBXML_VERSION_INFO",
                              "%d:@LIBXML_MICRO_VERSION@:@LIBXML_MICRO_VERSION@",
                              libxml_major_version + libxml_minor_version);
    config_tool_define_format("LIBXML_VERSION_NUMBER",
                              "%d",
                              libxml_major_version * 10000 + libxml_minor_version * 100 + 
libxml_micro_version);
    /* Extract minor CVS revision number of ChangeLog */
    config_tool_define_command("LIBXML_VERSION_EXTRA",
                               "grep ChangeLog CVS/Entries | cut -d/ -f3 | sed -e 
's/.*\\.\\(.*\\)/-CVS\\1/'");
}

/*
 * Determine system tools
 */

void libxml_check_tools(void)
{
    ac_prog_install();
    /* FIXME: ac_prog_cpp(); */
    config_tool_check("RM", "rm")
        || config_tool_define("RM", "/bin/rm");
    config_tool_check("MV", "mv")
        || config_tool_define("MV", "/bin/mv");
    config_tool_check("TAR", "gtar")
        || config_tool_check("TAR", "tar")
        || config_tool_define("MV", "/bin/tar");
    config_tool_check("PERL", "perl")
        || config_tool_define("PERL", "/usr/bin/perl");
    config_tool_check("XMLLINT", "xmllint")
        || config_tool_define("XMLLINT", "/usr/bin/xmllint");
    config_tool_check("XSLTPROC", "xsltproc")
        || config_tool_define("XSLTPROC", "/usr/bin/xsltproc");
}

/*
 * Determine system headers
 */

void libxml_check_headers(void)
{
    /* FIXME: AC_HEADER_DIRENT */
    ac_header_stdc();
    config_header_check("fcntl.h");
    config_header_check("unistd.h");
    config_header_check("ctype.h");
    config_header_check("dirent.h");
    config_header_check("errno.h");
    config_header_check("malloc.h");
    config_header_check("stdarg.h");
    config_header_check("sys/stat.h");
    config_header_check("sys/types.h");
    config_header_check("time.h");
    config_header_check("ansidecl.h");
    config_header_check("ieeefp.h");
    config_header_check("nan.h");
    config_header_check("math.h");
    config_header_check("limits.h");
    config_header_check("fp_class.h");
    config_header_check("stdlib.h");
    config_header_check_depend("sys/socket.h", "sys/types.h");
    config_header_check_depend("netinet/in.h", "sys/types.h");
    config_header_check_depend("arpa/inet.h", "sys/types.h");
    config_header_check("netdb.h");
    config_header_check("sys/time.h");
    config_header_check("sys/select.h");
    config_header_check("sys/mman.h");
    config_header_check("sys/timeb.h");
    config_header_check("signal.h");
    config_header_check_depend("arpa/nameser.h", "sys/types.h");
    ac_header_resolv();
    config_header_check("dl.h");
    config_header_check("dlfcn.h");
}

/*
 * Determine system functions
 */

void libxml_check_functions(void)
{
    int formatting = 0;

    /* FIXME: AC_FUNC_STRFTIME */
    config_function_check("strdup");
    config_function_check("strndup");
    config_function_check("strerror");
    config_function_check("finite");
    config_function_check("isnand");
    config_function_check("fp_class");
    config_function_check("class");
    config_function_check("fpclass");
    config_function_check("strftime");
    config_function_check("localtime");
    config_function_check("gettimeofday");
    config_function_check("ftime");
    config_function_check("stat");
    config_function_check("_stat");
    config_function_check("signal");

    formatting += config_function_check("printf");
    formatting += config_function_check("sprintf");
    formatting += config_function_check("fprintf");
    formatting += config_function_check("snprintf");
    formatting += config_function_check("vfprintf");
    formatting += config_function_check("vsprintf");
    formatting += config_function_check("vsnprintf");
    formatting += config_function_check("sscanf");
    if (formatting < 8) {
        config_tool_define("WITH_TRIO", "1");
    }

    libxml_check_va_copy();

    config_function_check("gethostent")
        || config_function_check_library("gethostent", "nsl");
    config_function_check("setsockopt")
        || config_function_check_library("setsockopt", "socket")
        || config_function_check_library("setsockopt", "net");
    config_function_check("connect")
        || config_function_check_library("connect", "inet");

    libxml_check_socklen();

    config_function_check("isnan")
        || config_function_check_library("isnan", "m");
    config_function_check("isinf")
        || config_function_check_library("isinf", "m");
}

/*
 * Determine multithreading support
 */

void libxml_check_threads(void)
{
    if (config_equal(config_option_get("with-threads"), "yes")) {

        config_tool_define("WITH_THREADS", "0");
        config_tool_define("THREAD_CFLAGS", "");
        config_tool_define("THREAD_LIBS", "");
        config_tool_define("BASE_THREAD_LIBS", "");
        config_tool_define("TEST_THREADS", "");
        config_tool_define("THREADS_W32", "");

        config_header_check("pthread.h");
        if (config_function_check_library("pthread_join", "pthread")) {
            config_tool_define("WITH_THREADS", "1");
            config_tool_define("THREAD_LIBS", "-lpthread");
        }

        if (config_equal(config_kernel(), "mingw32")) {
            config_tool_define("WITH_THREADS", "1");
            config_tool_define("THREADS_W32", "Win32");
            config_tool_define("THREAD_CFLAGS", "@THREAD_CFLAGS@ -DHAVE_WIN32_THREADS");

        } else if (config_equal(config_kernel(), "cygwin")) {
            config_tool_define("THREAD_LIBS", "");

        } else if (config_equal(config_kernel(), "beos")) {
            config_tool_define("WITH_THREADS", "1");
            config_tool_define("THREAD_LIBS", "@THREAD_LIBS@ -DHAVE_BEOS_THREADS");

        } else if (config_equal(config_kernel(), "linux")) {
            if (config_equal(config_compiler(), "gcc")) {
                if (config_compiler_version() > config_version(3, 2, 0)) {
                    config_tool_define("THREAD_LIBS", "");
                    config_tool_define("BASE_THREAD_LIBS", "-lpthread");
                }
            }
        }

        if (config_tool_get("WITH_THREADS")) {
            config_tool_define("THREAD_CFLAGS", "@THREAD_CFLAGS@ -D_REENTRANT");
            config_tool_define("TEST_THREADS", "Threadtests");
        }
    }

    if (config_equal(config_option_get("with-threads-alloc"), "yes") &&
        config_tool_get("WITH_THREADS")) {
        config_tool_define("THREAD_CFLAGS", "@THREAD_CFLAGS@ -DLIBXML_THREAD_ALLOC_ENABLED");
    }
}

/*
 * Set required variables
 */

void libxml_end(void)
{
    /* Make sure that the following variables are defined */
    config_tool_get("CFLAGS") || config_tool_define("CFLAGS", "");
    config_tool_get("CPPFLAGS") || config_tool_define("CPPFLAGS", "");
    config_tool_get("LDFLAGS") || config_tool_define("LDFLAGS", "");
}

/*
 * Start here
 */

int main(int argc, char *argv[])
{
    config_begin();

    ac_register();
    libxml_register();

    if (config_options(argc, argv)) {

        libxml_dependencies();

        ac_prefix();
        ac_prog_shell();

        libxml_build_version();
/*         am_init_automake("libxml", config_tool_get("LIBXML_VERSION")); */

        libxml_check_tools();
        libxml_check_headers();
        libxml_check_functions();

        libxml_check_ipv6();
        libxml_compiler_workaround();
        libxml_check_python();
        libxml_check_threads();

        config_compiler_check();
        config_kernel_check();
        config_cpu_check();

        libxml_end();
    }
    config_end();
  
    return 0;
}
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */

/*
 * Checking for va_copy availability
 */

void libxml_check_va_copy(void)
{
    int success;

    success = config_compile_source("#include <stdarg.h>\nint main(void){va_list a1, a2; va_copy(a1,a2); 
return 0;}", "");
    config_function_define("va_copy", 0, success);
    config_report_bool("va_copy", success);

    if (!success) {
        success = config_compile_source("#include <stdarg.h>\nint main(void){va_list a1, a2; 
__va_copy(a1,a2); return 0;}", "");
        config_function_define("__va_copy", 0, success);
        config_report_bool("__va_copy", success);
    }
}

/*
 * Determine the socket length (socklen_t) data type
 */

void libxml_check_socklen(void)
{
    int success;

    success = config_compile_source("#include <stddef.h>\n#include <sys/types.h>\n#include 
<sys/socket.h>\nint main(void){(void)getsockopt(1, 1, 1, NULL, (socklen_t *)0); return 0;}", "");
    config_report_bool("type of socket length (socklen_t)", success);
    if (success) {
        config_macro_define("XML_SOCKLEN_T", "socklen_t");
    } else {
        success = config_compile_source("#include <stddef.h>\n#include <sys/types.h>\n#include 
<sys/socket.h>\nint main(void){(void)getsockopt(1, 1, 1, NULL, (size_t *)0); return 0;}", "");
        config_report_bool("type of socket length (size_t)", success);
        if (success) {
            config_macro_define("XML_SOCKLEN_T", "size_t");
        } else {
            success = config_compile_source("#include <stddef.h>\n#include <sys/types.h>\n#include 
<sys/socket.h>\nint main(void){(void)getsockopt(1, 1, 1, NULL, (int *)0); return 0;}", "");
            config_report_bool("type of socket length (int)", success);
            if (success) {
                config_macro_define("XML_SOCKLEN_T", "int");
            }
        }
    }
}

/*
 * Check for IPv6 availability
 */

void libxml_check_ipv6(void)
{
    int success;

    if (config_equal(config_option_get("enable-ipv6"), "yes")) {
        success = config_compile_source("#include <sys/socket.h>\n#include <sys/types.h>\nint 
main(void){struct sockaddr_storage ss;\n(void)socket(AF_INET6, SOCK_STREAM, 0); return 0;}", "");
        config_report_bool("IPv6 support", success);
        if (success) {
            config_macro_define("SUPPORT_IP6", "1");
            /* FIXME: ss_family etc. */
        }
    }
}

/*
 * Determine various compiler work-arounds
 */

void libxml_compiler_workaround(void)
{
    if (config_equal(config_compiler(), "gcc")) {

        /* FIXME: CFLAGS becomes "(null) <rest>" */

        if (config_equal(config_option_get("with-fexceptions"), "yes")) {
            config_tool_define("CFLAGS", "@CFLAGS=@ -fexceptions");
        }
        config_tool_define("CFLAGS", "@CFLAGS=@ -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type 
-Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow 
-Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes 
-Wnested-externs -Winline -Wredundant-decls");

        if (config_equal(config_cpu(), "alpha")) {
            if (config_equal(config_kernel(), "linux") || config_equal(config_kernel(), "osf1")) {
                config_tool_define("CFLAGS", "@CFLAGS=@ -mieee");
            }
        }
    } else {

        if (config_equal(config_kernel(), "hpux")) {
            config_tool_define("CFLAGS", "@CFLAGS=@ -Wp,-H30000");

        } else if (config_equal(config_kernel(), "osf1")) {
            config_tool_define("CFLAGS", "@CFLAGS=@ -ieee");

        } else if (config_equal(config_kernel(), "linux") && config_equal(config_cpu(), "alpha")) {
            config_tool_define("CFLAGS", "@CFLAGS=@ -ieee");
        }
    }

    /* FIXME: solaris & mpeix */
}

/*
 * Check for Python
 */

void libxml_check_python(void)
{
    /* FIXME */
    const char *python_path;
    const char *expected_version = "1.5";

    python_path = config_option_get("with-python");
    if (python_path != 0) {
        /* FIXME: first check does not work */
        /* FIXME: check python_path/bin/python and python_path */
        if (config_tool_check_filter("PYTHON", python_path, ac_path_python_filter, (void *)expected_version)) 
{
        } else {
            ac_path_python(expected_version);
        }
    }
}


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