From 44d88a2cf487a4247ac00f77f1957f8701c3f22f Mon Sep 17 00:00:00 2001
From: Alberto Massari <amassari@apache.org>
Date: Mon, 15 Mar 2004 17:06:58 +0000
Subject: [PATCH] - Added support for MinGW (bug#23176) - Look for getopt in
 more places, and use getops properly if not found (bug#18668)

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@175831 13f79535-47bb-0310-9956-ffa450edef68
---
 samples/runConfigure     | 135 ++++++++++++++++++------------
 src/xercesc/runConfigure | 175 +++++++++++++++++++++++++--------------
 tests/runConfigure       | 135 ++++++++++++++++++------------
 3 files changed, 281 insertions(+), 164 deletions(-)

diff --git a/samples/runConfigure b/samples/runConfigure
index f910efcf8..597b51567 100755
--- a/samples/runConfigure
+++ b/samples/runConfigure
@@ -85,7 +85,8 @@ platforms"
     echo "       where options may be any of the following:"
     echo "       -p <platform> (accepts 'aix', 'beos', 'linux', 'freebsd', 'netbsd',
             'solaris', 'hp-10', 'hp-11', 'openserver', 'unixware',
-            'os400', 'irix', 'ptx', 'tru64', 'macosx', 'cygwin')
+            'os400', 'irix', 'ptx', 'tru64', 'macosx', 'cygwin', 'qnx',
+            'interix', 'mingw-msys')
             [required: no default]"
     echo "       -c <C compiler name> (e.g. gcc, cc, xlc_r, icc or ecc)"
     echo "            [default is make default; cc for gnu make]"
@@ -126,71 +127,100 @@ if test $1 = "-h"; then
    exit ${ERROR_EXIT_CODE}
 fi
 
-# Check the command line parameters
-if test -x /usr/bin/getopt; then
-getoptErr=`getopt p:c:x:dr:b:l:z:h $*`
-else
-getoptErr=`getopts p:c:x:dr:b:l:z:h `$*``
-fi
-if [ $? != 0 ]
-   then
-   usage
-   exit ${ERROR_EXIT_CODE}
-fi
-
-# Now get the command line parameters
-if test -x /usr/bin/getopt; then
-set -- `getopt p:c:x:dr:b:l:z:h $*`
-else
-set -- `getopts p:c:x:dr:b:l:z:h `$*``
-fi
-
 # Set up the default values for each parameter
 debug=off                # by default debug is off
 transcoder=native        # by default use native transcoder
 thread=none              # by default no need to have threads
 bitsToBuild=32           # by default 32 bit build assumed
-while [ $# -gt 0 ]
-   do
-   case $1 in
-   -p)
-        platform=$2; shift 2;;
 
-   -c)
-        ccompiler=$2; shift 2;;
+# Check the command line parameters
+if test -x /usr/bin/getopt; then
+   getoptErr=`getopt p:c:x:dr:b:l:z:h $*`
+   if [ $? != 0 ]
+      then
+      usage
+      exit ${ERROR_EXIT_CODE}
+   fi
+   # Now get the command line parameters
+   set -- `getopt p:c:x:dr:b:l:z:h $*`
+   while [ $# -gt 0 ]
+      do
+      case $1 in
+      -p)
+         platform=$2; shift 2;;
 
-   -x)
-        cppcompiler=$2; shift 2;;
+      -c)
+         ccompiler=$2; shift 2;;
 
-   -d)
-        debug=on; shift;;
+      -x)
+         cppcompiler=$2; shift 2;;
 
-   -r)
-        thread=$2; shift 2;;
+      -d)
+         debug=on; shift;;
 
+      -r)
+         thread=$2; shift 2;;
 
-   -b)
-        bitsToBuild=$2; shift 2;;
+      -b)
+         bitsToBuild=$2; shift 2;;
 
-   -z)
-        compileroptions="$compileroptions $2"; shift 2;;
+      -z)
+         compileroptions="$compileroptions $2"; shift 2;;
 
-   -l)
-        linkeroptions="$linkeroptions $2"; shift 2;;
+      -l)
+         linkeroptions="$linkeroptions $2"; shift 2;;
 
-   -h)
-        usage
-        exit ${ERROR_EXIT_CODE};;
+      -h)
+         usage
+         exit ${ERROR_EXIT_CODE};;
 
-   --)
-        shift; break;;
+      --)
+         shift; break;;
 
-   *)
-       echo "unknown option $1"
-       usage
-       exit ${ERROR_EXIT_CODE};;
-   esac
-done
+      *)
+         echo "unknown option $1"
+         usage
+         exit ${ERROR_EXIT_CODE};;
+      esac
+   done
+else
+   while getopts "p:c:x:dr:b:l:z:h" switch; do
+      case $switch in
+      p)
+         platform=$OPTARG;;
+
+      c)
+         ccompiler=$OPTARG;;
+
+      x)
+         cppcompiler=$OPTARG;;
+
+      d)
+         debug=on;;
+
+      r)
+         thread=$OPTARG;;
+
+      b)
+         bitsToBuild=$OPTARG;;
+
+      z)
+         compileroptions="$compileroptions $OPTARG";;
+
+      l)
+         linkeroptions="$linkeroptions $OPTARG";;
+
+      h)
+         usage
+         exit ${ERROR_EXIT_CODE};;
+
+      *)
+         echo "unknown option -$switch $OPTARG"
+         usage
+         exit ${ERROR_EXIT_CODE};;
+      esac
+   done
+fi
 
 echo "Generating makefiles with the following options ..."
 echo "Platform: $platform"
@@ -205,7 +235,7 @@ echo "Extra link options: $linkeroptions"
 # Now check if the options are correct or not, bail out if incorrect
 #
 case $platform in
-   aix | openserver | unixware | beos | linux | freebsd | netbsd | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64 | macosx | cygwin)
+   aix | openserver | unixware | beos | linux | freebsd | netbsd | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64 | macosx | cygwin | qnx | interix | mingw-msys)
        # platform has been recognized
        ;;
    *)
@@ -344,6 +374,9 @@ else
             exit ${ERROR_EXIT_CODE};;
         esac
         fi
+    elif test $platform = "mingw-msys"; then
+        threadingLibs=""
+        threadingDefines=""
     fi
 fi
 
diff --git a/src/xercesc/runConfigure b/src/xercesc/runConfigure
index 32919b262..ac1372535 100755
--- a/src/xercesc/runConfigure
+++ b/src/xercesc/runConfigure
@@ -88,7 +88,7 @@ usage()
     echo "       -p <platform> (accepts 'aix', 'beos', 'linux', 'freebsd', 
             'netbsd', 'solaris', 'hp-10', 'hp-11', 'openserver', 'unixware', 
             'os400', 'irix', 'ptx', 'tru64', 'macosx', 'cygwin', 'qnx',
-            'interix')
+            'interix', 'mingw-msys')
             [required; no default]"
     echo "       -c <C compiler name> (e.g. gcc, cc, xlc_r, qcc, icc or ecc) 
             [default is make default; cc for gnu make]"
@@ -140,25 +140,6 @@ if test $1 = "-h"; then
    exit ${ERROR_EXIT_CODE}
 fi
 
-# Check the command line parameters
-if test -x /usr/bin/getopt; then
-getoptErr=`getopt p:c:x:dm:n:t:r:b:l:z:P:C:h $*`
-else
-getoptErr=`getopts p:c:x:dm:n:t:r:b:l:z:P:C:h `$*``
-fi
-if [ $? != 0 ]
-   then
-   usage
-   exit ${ERROR_EXIT_CODE}
-fi
-
-# Now get the command line parameters
-if test -x /usr/bin/getopt; then
-set -- `getopt p:c:x:dm:n:t:r:b:l:z:P:C:h $*`
-else
-set -- `getopts p:c:x:dm:n:t:r:b:l:z:P:C:h `$*``
-fi
-
 # Set up the default values for each parameter
 debug=off                # by default debug is off
 transcoder=native        # by default use native transcoder
@@ -168,61 +149,125 @@ thread=pthread           # by default use POSIX threads
 configureoptions=""
 bitsToBuild=32           # by default 32 bit build assumed
 
-while [ $# -gt 0 ]
-   do
-   case $1 in
-   -p)
-        platform=$2; shift 2;;
+# Check the command line parameters
+if test -x /usr/bin/getopt -o -x bin/getopt; then
+	getoptErr=`getopt p:c:x:dm:n:t:r:b:l:z:P:C:h $*`
+	if [ $? != 0 ]
+	   then
+	   usage
+	   exit ${ERROR_EXIT_CODE}
+	fi
+	# Now get the command line parameters
+	set -- `getopt p:c:x:dm:n:t:r:b:l:z:P:C:h $*`
+	while [ $# -gt 0 ]
+	   do
+	   case $1 in
+	   -p)
+			platform=$2; shift 2;;
 
-   -c)
-        ccompiler=$2; shift 2;;
+	   -c)
+			ccompiler=$2; shift 2;;
 
-   -x)
-        cppcompiler=$2; shift 2;;
+	   -x)
+			cppcompiler=$2; shift 2;;
 
-   -d)
-        debug=on; shift;;
+	   -d)
+			debug=on; shift;;
 
-   -m)
-        msgloader=$2; shift 2;;
+	   -m)
+			msgloader=$2; shift 2;;
 
-   -n)
-        netaccessor=$2; shift 2;;
+	   -n)
+			netaccessor=$2; shift 2;;
 
-   -t)
-        transcoder=$2; shift 2;;
+	   -t)
+			transcoder=$2; shift 2;;
 
-   -r)
-        thread=$2; shift 2;;
+	   -r)
+			thread=$2; shift 2;;
 
-   -b)
-        bitsToBuild=$2; shift 2;;
+	   -b)
+			bitsToBuild=$2; shift 2;;
 
-   -z)
-        compileroptions="$compileroptions $2"; shift 2;;
+	   -z)
+			compileroptions="$compileroptions $2"; shift 2;;
 
-   -l)
-        linkeroptions="$linkeroptions $2"; shift 2;;
+	   -l)
+			linkeroptions="$linkeroptions $2"; shift 2;;
 
-   -P)
-        configureoptions="$configureoptions --prefix=$2"; shift 2;;
+	   -P)
+			configureoptions="$configureoptions --prefix=$2"; shift 2;;
 
-   -C)
-        configureoptions="$configureoptions $2"; shift 2;;
+	   -C)
+			configureoptions="$configureoptions $2"; shift 2;;
 
-   -h)
-        usage
-        exit ${ERROR_EXIT_CODE};;
+	   -h)
+			usage
+			exit ${ERROR_EXIT_CODE};;
 
-   --)
-        shift; break;;
+	   --)
+			shift; break;;
 
-   *)
-       echo "unknown option $1"
-       usage
-       exit ${ERROR_EXIT_CODE};;
-   esac
-done
+	   *)
+		   echo "unknown option $1"
+		   usage
+		   exit ${ERROR_EXIT_CODE};;
+	   esac
+	done
+
+else
+	while getopts "p:c:x:dm:n:t:r:b:l:z:P:C:h" switch; do
+	   case $switch in
+	   p)
+			platform=$OPTARG;;
+
+	   c)
+			ccompiler=$OPTARG;;
+
+	   x)
+			cppcompiler=$OPTARG;;
+
+	   d)
+			debug=on;;
+
+	   m)
+			msgloader=$OPTARG;;
+
+	   n)
+			netaccessor=$OPTARG;;
+
+	   t)
+			transcoder=$OPTARG;;
+
+	   r)
+			thread=$OPTARG;;
+
+	   b)
+			bitsToBuild=$OPTARG;;
+
+	   z)
+			compileroptions="$compileroptions $OPTARG";;
+
+	   l)
+			linkeroptions="$linkeroptions $OPTARG";;
+
+	   P)
+			configureoptions="$configureoptions --prefix=$OPTARG";;
+
+	   C)
+			configureoptions="$configureoptions $OPTARG";;
+
+	   h)
+			usage
+			exit ${ERROR_EXIT_CODE};;
+
+	   *)
+		   echo "unknown option -$switch $OPTARG"
+		   usage
+		   exit ${ERROR_EXIT_CODE};;
+	   esac
+	done
+fi
 
 echo "Generating makefiles with the following options ..."
 echo "Platform: $platform"
@@ -243,7 +288,7 @@ echo "Extra configure options: $configureoptions"
 #
 
 case $platform in
-   aix | openserver | unixware | beos | linux | freebsd | netbsd | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64 | macosx | cygwin | qnx | interix)
+   aix | openserver | unixware | beos | linux | freebsd | netbsd | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64 | macosx | cygwin | qnx | interix | mingw-msys)
        # platform has been recognized
        ;;
    *)
@@ -393,6 +438,9 @@ else
             exit ${ERROR_EXIT_CODE};;
         esac
         fi
+    elif test $platform = "mingw-msys"; then
+        threadingLibs=""
+        threadingDefines=""
     fi
 fi
 
@@ -475,6 +523,9 @@ case $transcoder in
  	if test $platform = "cygwin"; then
  	    TRANSCODER=Cygwin ;
  	    transcodingDefines="-DXML_USE_CYGWIN_TRANSCODER" ;
+ 	elif test $platform = "mingw-msys"; then
+ 	    TRANSCODER=Cygwin ;
+ 	    transcodingDefines="-DXML_USE_CYGWIN_TRANSCODER" ;
  	elif test $platform = "freebsd"; then
            TRANSCODER=IconvFBSD ;
        fi ;;
@@ -628,7 +679,7 @@ export CXX
 #
 # these defines are required when building the DLL
 #
-buildDefines="-DPROJ_XMLPARSER  -DPROJ_XMLUTIL  -DPROJ_PARSERS  -DPROJ_SAX4C  -DPROJ_SAX2  -DPROJ_DOM  -DPROJ_VALIDATORS"
+buildDefines="-DPROJ_XMLPARSER  -DPROJ_XMLUTIL  -DPROJ_PARSERS  -DPROJ_SAX4C  -DPROJ_SAX2  -DPROJ_DOM -DPROJ_DEPRECATED_DOM -DPROJ_VALIDATORS"
 
 CXXFLAGS="$CXXFLAGS $compileroptions $debugflag $buildDefines $transcodingDefines $msgloaderDefines $threadingDefines $netaccessorDefines $bitstobuildDefines"
 export CXXFLAGS
diff --git a/tests/runConfigure b/tests/runConfigure
index 505fbde3e..8c2820645 100755
--- a/tests/runConfigure
+++ b/tests/runConfigure
@@ -84,7 +84,8 @@ usage()
     echo "       where options may be any of the following:"
     echo "       -p <platform> (accepts 'aix', 'beos', 'linux', 'freebsd', 'netbsd',
             'solaris', 'hp-10', 'hp-11', 'openserver', 'unixware',
-            'os400', 'irix', 'ptx', 'tru64', 'macosx', 'cygwin')
+            'os400', 'irix', 'ptx', 'tru64', 'macosx', 'cygwin', 'qnx',
+            'interix', 'mingw-msys')
             [required: no default]"
     echo "       -c <C compiler name> (e.g. gcc, cc, xlc_r, icc or ecc)"
     echo "            [default is make default; cc for gnu make]"
@@ -125,71 +126,100 @@ if test $1 = "-h"; then
    exit ${ERROR_EXIT_CODE}
 fi
 
-# Check the command line parameters
-if test -x /usr/bin/getopt; then
-getoptErr=`getopt p:c:x:dr:b:l:z:h $*`
-else
-getoptErr=`getopts p:c:x:dr:b:l:z:h `$*``
-fi
-if [ $? != 0 ]
-   then
-   usage
-   exit ${ERROR_EXIT_CODE}
-fi
-
-# Now get the command line parameters
-if test -x /usr/bin/getopt; then
-set -- `getopt p:c:x:dr:b:l:z:h $*`
-else
-set -- `getopts p:c:x:dr:b:l:z:h `$*``
-fi
-
 # Set up the default values for each parameter
 debug=off                # by default debug is off
 transcoder=native        # by default use native transcoder
 thread=pthread           # by default use POSIX threads
 bitsToBuild=32           # by default 32 bit build assumed
 
-while [ $# -gt 0 ]
-   do
-   case $1 in
-   -p)
-        platform=$2; shift 2;;
+# Check the command line parameters
+if test -x /usr/bin/getopt; then
+   getoptErr=`getopt p:c:x:dr:b:l:z:h $*`
+   if [ $? != 0 ]
+      then
+      usage
+      exit ${ERROR_EXIT_CODE}
+   fi
+   # Now get the command line parameters
+   set -- `getopt p:c:x:dr:b:l:z:h $*`
+   while [ $# -gt 0 ]
+      do
+      case $1 in
+      -p)
+         platform=$2; shift 2;;
 
-   -c)
-        ccompiler=$2; shift 2;;
+      -c)
+         ccompiler=$2; shift 2;;
 
-   -x)
-        cppcompiler=$2; shift 2;;
+      -x)
+         cppcompiler=$2; shift 2;;
 
-   -d)
-        debug=on; shift;;
+      -d)
+         debug=on; shift;;
 
-   -r)
-        thread=$2; shift 2;;
+      -r)
+         thread=$2; shift 2;;
 
-   -b)
-        bitsToBuild=$2; shift 2;;
+      -b)
+         bitsToBuild=$2; shift 2;;
 
-   -z)
-        compileroptions="$compileroptions $2"; shift 2;;
+      -z)
+         compileroptions="$compileroptions $2"; shift 2;;
 
-   -l)
-        linkeroptions="$linkeroptions $2"; shift 2;;
+      -l)
+         linkeroptions="$linkeroptions $2"; shift 2;;
 
-   -h)
-        usage
-        exit ${ERROR_EXIT_CODE};;
+      -h)
+         usage
+         exit ${ERROR_EXIT_CODE};;
 
-   --)
-        shift; break;;
+      --)
+         shift; break;;
 
-   *)
-       echo "unknown option $1"
-       usage
-       exit ${ERROR_EXIT_CODE};;
-   esac
-done
+      *)
+         echo "unknown option $1"
+         usage
+         exit ${ERROR_EXIT_CODE};;
+      esac
+   done
+else
+   while getopts "p:c:x:dr:b:l:z:h" switch; do
+      case $switch in
+      p)
+         platform=$OPTARG;;
+
+      c)
+         ccompiler=$OPTARG;;
+
+      x)
+         cppcompiler=$OPTARG;;
+
+      d)
+         debug=on;;
+
+      r)
+         thread=$OPTARG;;
+
+      b)
+         bitsToBuild=$OPTARG;;
+
+      z)
+         compileroptions="$compileroptions $OPTARG";;
+
+      l)
+         linkeroptions="$linkeroptions $OPTARG";;
+
+      h)
+         usage
+         exit ${ERROR_EXIT_CODE};;
+
+      *)
+         echo "unknown option -$switch $OPTARG"
+         usage
+         exit ${ERROR_EXIT_CODE};;
+      esac
+   done
+fi
 
 echo "Generating makefiles with the following options ..."
 echo "Platform: $platform"
@@ -204,7 +234,7 @@ echo "Extra link options: $linkeroptions"
 # Now check if the options are correct or not, bail out if incorrect
 #
 case $platform in
-   aix | openserver | unixware | beos | linux | freebsd | netbsd | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64 | macosx | cygwin | qnx)
+   aix | openserver | unixware | beos | linux | freebsd | netbsd | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64 | macosx | cygwin | qnx | interix | mingw-msys)
        # platform has been recognized
        ;;
    *)
@@ -343,6 +373,9 @@ else
             exit ${ERROR_EXIT_CODE};;
         esac
         fi
+    elif test $platform = "mingw-msys"; then
+        threadingLibs=""
+        threadingDefines=""
     fi
 fi
 
-- 
GitLab