This patch allows popt from CVS to be cross-compiled for Windows using
MinGW and Win32 API (not Cygwin).

It uses Gnulib to supply the missing functionality -- mainly glob(3)
and globfree(3).

Note that the patch isn't "complete".  As you can see from the
modification to autogen.sh you are expected to have a checkout of
gnulib itself in a directory adjacent to popt (../gnulib/).  That will
pull in the additional files from Gnulib.  A better explanation is
probably to read the Gnulib manual:

http://www.gnu.org/software/gnulib/manual/gnulib.html#Initial-import

All the Gnulib modules imported are LGPLv2+ (except for one which is
public domain).

If you have the MinGW cross-compiler installed, eg. from [1], then you
can compile popt for Windows by doing:

  PKG_CONFIG_PATH=/usr/i686-pc-mingw32/sys-root/mingw/lib/pkgconfig \
  ./autogen.sh \
    --host=i686-pc-mingw32 --prefix=/usr/i686-pc-mingw32/sys-root/mingw

  make -C lib fnmatch.h                   # BUG IN GNULIB?

  make

You'll get a DLL, and test{1,2,3}.exe which can be run under Wine (or
even on Windows :-).

For reference you can find our mingw32-popt RPM sources here:

http://hg.et.redhat.com/misc/fedora-mingw--devel/?cmd=manifest;manifest=6651a3a433544afe0cc67b0fcb5668d71d3ecfbf;path=/popt/

Rich.

[1] http://www.annexia.org/tmp/mingw/fedora-9/i386/

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
diff -urN --exclude CVS popt/autogen.sh popt.win/autogen.sh
--- popt/autogen.sh     2008-02-11 16:48:11.000000000 +0000
+++ popt.win/autogen.sh 2008-10-25 14:54:06.000000000 +0100
@@ -5,6 +5,8 @@
 
 THEDIR="`pwd`"
 
+../gnulib/gnulib-tool --update
+
 libtoolize=`which glibtoolize 2>/dev/null`
 case $libtoolize in
 /*) ;;
diff -urN --exclude CVS popt/configure.ac popt.win/configure.ac
--- popt/configure.ac   2008-10-04 20:23:50.000000000 +0100
+++ popt.win/configure.ac       2008-10-25 14:57:59.000000000 +0100
@@ -1,4 +1,4 @@
-AC_PREREQ(2.57)
+AC_PREREQ([2.59])
 AC_INIT(popt, 1.15, [EMAIL PROTECTED])
 AC_CANONICAL_TARGET
 AC_CONFIG_SRCDIR([popt.h])
@@ -17,6 +17,7 @@
 ALL_LINGUAS="cs da de eo es fi fr ga gl hu id is it ja ko nb nl pl pt ro ru sk 
sl sv th tr uk vi wa zh_TW zh_CN"
 
 AC_PROG_CC
+gl_EARLY
 AC_PROG_INSTALL
 AC_PROG_LIBTOOL
 
@@ -44,7 +45,10 @@
 AC_ISC_POSIX
 AM_C_PROTOTYPES
 
-AC_CHECK_HEADERS(float.h glob.h langinfo.h libintl.h mcheck.h unistd.h)
+dnl Gnulib tests.
+gl_INIT
+
+AC_CHECK_HEADERS(float.h glob.h langinfo.h libintl.h mcheck.h unistd.h 
sys/ioctl.h)
 
 # For some systems we know that we have ld_version scripts.
 # Use it then as default.
@@ -68,7 +72,7 @@
 AC_CHECK_FUNC(setreuid, [], [
     AC_CHECK_LIB(ucb, setreuid, [if echo $LIBS | grep -- -lucb >/dev/null 
;then :; else LIBS="$LIBS -lc -lucb" USEUCB=y;fi])
 ])
-AC_CHECK_FUNCS(getuid geteuid iconv mtrace __secure_getenv setregid stpcpy 
strerror vasprintf)
+AC_CHECK_FUNCS(getuid geteuid iconv mtrace __secure_getenv setregid stpcpy 
strerror vasprintf random srandom)
 
 AM_GNU_GETTEXT([external])
 AM_ICONV_LINK
@@ -82,4 +86,4 @@
        [Full path to popt top_srcdir.])
 AC_SUBST(POPT_SOURCE_PATH)
 
-AC_OUTPUT([Doxyfile Makefile po/Makefile.in])
+AC_OUTPUT([Doxyfile Makefile lib/Makefile])
diff -urN --exclude CVS popt/.cvsignore popt.win/.cvsignore
--- popt/.cvsignore     2008-05-05 20:27:31.000000000 +0100
+++ popt.win/.cvsignore 2008-10-25 14:27:02.000000000 +0100
@@ -41,3 +41,4 @@
 *.lo
 *.swp
 popt-*.tar.gz
+link-warning.h
diff -urN --exclude CVS popt/m4/gnulib-cache.m4 popt.win/m4/gnulib-cache.m4
--- popt/m4/gnulib-cache.m4     1970-01-01 01:00:00.000000000 +0100
+++ popt.win/m4/gnulib-cache.m4 2008-10-25 14:27:02.000000000 +0100
@@ -0,0 +1,35 @@
+# Copyright (C) 2002-2008 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.
+#
+# Generated by gnulib-tool.
+#
+# This file represents the specification of how gnulib-tool is used.
+# It acts as a cache: It is written and read by gnulib-tool.
+# In projects using CVS, this file is meant to be stored in CVS,
+# like the configure.ac and various Makefile.am files.
+
+
+# Specification in the form of a command-line invocation:
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 
--doc-base=doc --tests-base=tests --aux-dir=. --libtool --macro-prefix=gl glob
+
+# Specification in the form of a few gnulib-tool.m4 macro invocations:
+gl_LOCAL_DIR([])
+gl_MODULES([
+  glob
+])
+gl_AVOID([])
+gl_SOURCE_BASE([lib])
+gl_M4_BASE([m4])
+gl_PO_BASE([])
+gl_DOC_BASE([doc])
+gl_TESTS_BASE([tests])
+gl_LIB([libgnu])
+gl_MAKEFILE_NAME([])
+gl_LIBTOOL
+gl_MACRO_PREFIX([gl])
+gl_PO_DOMAIN([])
diff -urN --exclude CVS popt/Makefile.am popt.win/Makefile.am
--- popt/Makefile.am    2008-09-18 19:08:58.000000000 +0100
+++ popt.win/Makefile.am        2008-10-25 14:56:28.000000000 +0100
@@ -8,9 +8,10 @@
        footer_no_timestamp.html libpopt.vers \
        testit.sh test-poptrc test3-data/0* \
        po/*.in po/*.po po/popt.pot \
-       popt.ps
+       popt.ps \
+       m4/gnulib-cache.m4
 
-SUBDIRS = po
+SUBDIRS = lib po
 
 INCLUDES = -I. -I$(top_srcdir)
 
diff -urN --exclude CVS popt/popt.c popt.win/popt.c
--- popt/popt.c 2008-05-05 18:38:33.000000000 +0100
+++ popt.win/popt.c     2008-10-25 14:38:29.000000000 +0100
@@ -725,6 +725,21 @@
 /[EMAIL PROTECTED] [EMAIL PROTECTED]/
 }
 
+/* Win32 typically lacks random/srandom, but has rand/srand which
+ * produces frankly rubbish random numbers and has RAND_MAX = 0x7FFF.
+ */
+#ifndef HAVE_RANDOM
+static int
+random ()
+{
+  return rand () << 15 | rand ();
+}
+#endif
+
+#ifndef HAVE_SRANDOM
+#define srandom srand
+#endif
+
 /[EMAIL PROTECTED]@*/
 static unsigned int seed = 0;
 
diff -urN --exclude CVS popt/popthelp.c popt.win/popthelp.c
--- popt/popthelp.c     2008-04-26 22:57:32.000000000 +0100
+++ popt.win/popthelp.c 2008-10-25 14:35:01.000000000 +0100
@@ -12,8 +12,10 @@
 
 #define        POPT_USE_TIOCGWINSZ
 #ifdef POPT_USE_TIOCGWINSZ
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
+#endif
 
 #define        POPT_WCHAR_HACK
 #ifdef         POPT_WCHAR_HACK

Reply via email to