@echo off
echo Configuring GNU gettext 0.19.2 for DJGPP v2.x...

Rem WARNING WARNING WARNING: This file needs to have DOS CRLF end-of-line
Rem format, or else stock DOS/Windows shells will refuse to run it.

Rem The SmallEnv tests protect against fixed and too small size
Rem of the environment in stock DOS shell.

Rem Find out if NLS is wanted or not,
Rem if dependency-tracking is wanted or not,
Rem if caching is wanted or not
Rem and where the sources are.
Rem We always default to NLS support,
Rem no dependency tracking
Rem and to in place configuration.
set ARGS=
set NLS=enabled
if not "%NLS%" == "enabled" goto SmallEnv
set CACHING=enabled
if not "%CACHING%" == "enabled" goto SmallEnv
set DEPENDENCY_TRACKING=disabled
if not "%DEPENDENCY_TRACKING%" == "disabled" goto SmallEnv
set LIBICONV_PREFIX=disabled
if not "%LIBICONV_PREFIX%" == "disabled" goto SmallEnv
set LIBINTL_PREFIX=disabled
if not "%LIBINTL_PREFIX%" == "disabled" goto SmallEnv
set HTML=enabled
if not "%HTML%" == "enabled" goto SmallEnv
set SILENT=enabled
if not "%SILENT%" == "enabled" goto SmallEnv
set ACL=disabled
if not "%ACL%" == "disabled" goto SmallEnv
set CURSES=disabled
if not "%CURSES%" == "disabled" goto SmallEnv
set THREADS=disabled
if not "%THREADS%" == "disabled" goto SmallEnv
set C++=enabled
if not "%C++%" == "enabled" goto SmallEnv
set LIBASPRINTF=enabled
if not "%LIBASPRINTF%" == "enabled" goto SmallEnv
set EMACS=enabled
if not "%EMACS%" == "enabled" goto SmallEnv
set XSRC=.
if not "%XSRC%" == "." goto SmallEnv

Rem Loop over all arguments.
Rem Special arguments are: NLS, XSRC, CACHE, STATIC_LIBS, LIBICONV_PREFIX, LIBINTL_PREFIX and DEPS.
Rem All other arguments are stored into ARGS.
:ArgLoop
if "%1" == "nls" goto NextArgument
if "%1" == "NLS" goto NextArgument
if "%1" == "no-nls" goto NoNLS
if "%1" == "no-NLS" goto NoNLS
if "%1" == "NO-NLS" goto NoNLS
goto CachingOption
:NoNLS
if "%1" == "no-nls" set NLS=disabled
if "%1" == "no-NLS" set NLS=disabled
if "%1" == "NO-NLS" set NLS=disabled
if not "%NLS%" == "disabled" goto SmallEnv
goto NextArgument
:CachingOption
if "%1" == "cache" goto NextArgument
if "%1" == "CACHE" goto NextArgument
if "%1" == "no-cache" goto NoCaching
if "%1" == "no-CACHE" goto NoCaching
if "%1" == "NO-CACHE" goto NoCaching
goto DependencyOption
:NoCaching
if "%1" == "no-cache" set CACHING=disabled
if "%1" == "no-CACHE" set CACHING=disabled
if "%1" == "NO-CACHE" set CACHING=disabled
if not "%CACHING%" == "disabled" goto SmallEnv
goto NextArgument
:DependencyOption
if "%1" == "no-dep" goto NextArgument
if "%1" == "no-DEP" goto NextArgument
if "%1" == "NO-DEP" goto NextArgument
if "%1" == "dep" goto _DependencyTraking
if "%1" == "DEP" goto _DependencyTraking
goto LibiconvPrefixOption
:_DependencyTraking
if "%1" == "dep" set DEPENDENCY_TRACKING=enabled
if "%1" == "DEP" set DEPENDENCY_TRACKING=enabled
if not "%DEPENDENCY_TRACKING%" == "enabled" goto SmallEnv
goto NextArgument
:LibiconvPrefixOption
if "%1" == "no-libiconvprefix" goto NextArgument
if "%1" == "no-LIBICONVPREFIX" goto NextArgument
if "%1" == "NO-LIBICONVPREFIX" goto NextArgument
if "%1" == "libiconvprefix" goto WithLibiconvPrefix
if "%1" == "LIBICONVPREFIX" goto WithLibiconvPrefix
goto LibintlPrefixOption
:WithLibiconvPrefix
if "%1" == "libiconvprefix" set LIBICONV_PREFIX=enabled
if "%1" == "LIBICONVPREFIX" set LIBICONV_PREFIX=enabled
if not "%LIBICONV_PREFIX%" == "enabled" goto SmallEnv
goto NextArgument
:LibintlPrefixOption
if "%1" == "no-libintlprefix" goto NextArgument
if "%1" == "no-LIBINTLPREFIX" goto NextArgument
if "%1" == "NO-LIBINTLPREFIX" goto NextArgument
if "%1" == "libintlprefix" goto _WithLibintlPrefix
if "%1" == "LIBINTLPREFIX" goto _WithLibintlPrefix
goto HTMLOption
:_WithLibintlPrefix
if "%1" == "libintlprefix" set LIBINTL_PREFIX=enabled
if "%1" == "LIBINTLPREFIX" set LIBINTL_PREFIX=enabled
if not "%LIBINTL_PREFIX%" == "enabled" goto SmallEnv
:HTMLOption
if "%1" == "withhtml" goto NextArgument
if "%1" == "withHTML" goto NextArgument
if "%1" == "WITHHTML" goto NextArgument
if "%1" == "withouthtml" goto _WithoutHTML
if "%1" == "withoutHTML" goto _WithoutHTML
if "%1" == "WITHOUTHTML" goto _WithoutHTML
goto SilentOption
:_WithoutHTML
if "%1" == "withouthtml" set HTML=disabled
if "%1" == "withoutHTML" set HTML=disabled
if "%1" == "WITHOUTHTML" set HTML=disabled
if not "%HTML%" == "disabled" goto SmallEnv
goto NextArgument
:SilentOption
if "%1" == "silent" goto NextArgument
if "%1" == "SILENT" goto NextArgument
if "%1" == "no-silent" goto NoSILENT
if "%1" == "no-SILENT" goto NoSILENT
if "%1" == "NO-SILENT" goto NoSILENT
goto AclOption
:NoSILENT
if "%1" == "no-silent" set SILENT=disabled
if "%1" == "no-SILENT" set SILENT=disabled
if "%1" == "NO-SILENT" set SILENT=disabled
if not "%SILENT%" == "disabled" goto SmallEnv
goto NextArgument
:AclOption
if "%1" == "no-acl" goto NextArgument
if "%1" == "no-ACL" goto NextArgument
if "%1" == "NO-ACL" goto NextArgument
if "%1" == "acl" goto _ACL
if "%1" == "Acl" goto _ACL
if "%1" == "ACL" goto _ACL
goto CursesOption
:_ACL
if "%1" == "acl" set ACL=enabled
if "%1" == "Acl" set ACL=enabled
if "%1" == "ACL" set ACL=enabled
if not "%ACL%" == "enabled" goto SmallEnv
goto NextArgument
:CursesOption
if "%1" == "no-curses" goto NextArgument
if "%1" == "no-CURSES" goto NextArgument
if "%1" == "NO-CURSES" goto NextArgument
if "%1" == "curses" goto _CURSES
if "%1" == "Curses" goto _CURSES
if "%1" == "CURSES" goto _CURSES
goto ThreadsOption
:_CURSES
if "%1" == "curses" set CURSES=enabled
if "%1" == "Curses" set CURSES=enabled
if "%1" == "CURSES" set CURSES=enabled
if not "%CURSES%" == "enabled" goto SmallEnv
goto NextArgument
:ThreadsOption
if "%1" == "no-threads" goto NextArgument
if "%1" == "no-THREADS" goto NextArgument
if "%1" == "NO-THREADS" goto NextArgument
if "%1" == "threads" goto _THREADS
if "%1" == "Threads" goto _THREADS
if "%1" == "THREADS" goto _THREADS
goto CXXOption
:_THREADS
if "%1" == "threads" set THREADS=enabled
if "%1" == "Threads" set THREADS=enabled
if "%1" == "THREADS" set THREADS=enabled
if not "%THREADS%" == "enabled" goto SmallEnv
goto NextArgument
:CXXOption
if "%1" == "c++" goto NextArgument
if "%1" == "C++" goto NextArgument
if "%1" == "no-c++" goto NoCXX
if "%1" == "no-C++" goto NoCXX
if "%1" == "NO-C++" goto NoCXX
goto LibasprintfOption
:NoCXX
if "%1" == "no-c++" set C++=disabled
if "%1" == "no-C++" set C++=disabled
if "%1" == "NO-C++" set C++=disabled
if not "%C++%" == "disabled" goto SmallEnv
goto NextArgument
:LibasprintfOption
if "%1" == "libasprintf" goto NextArgument
if "%1" == "Libasprintf" goto NextArgument
if "%1" == "no-libasprintf" goto NoLibasprintf
if "%1" == "no-Libasprintf" goto NoLibasprintf
if "%1" == "NO-Libasprintf" goto NoLibasprintf
goto EmacsOption
:NoLibasprintf
if "%1" == "no-libasprintf" set LIBASPRINTF=disabled
if "%1" == "no-Libasprintf" set LIBASPRINTF=disabled
if "%1" == "NO-Libasprintf" set LIBASPRINTF=disabled
if not "%LIBASPRINTF%" == "disabled" goto SmallEnv
goto NextArgument
:EmacsOption
if "%1" == "emacs" goto NextArgument
if "%1" == "EMACS" goto NextArgument
if "%1" == "no-emacs" goto NoEMACS
if "%1" == "no-EMACS" goto NoEMACS
if "%1" == "NO-EMACS" goto NoEMACS
goto SrcDirOption
:NoEMACS
if "%1" == "no-emacs" set EMACS=disabled
if "%1" == "no-EMACS" set EMACS=disabled
if "%1" == "NO-EMACS" set EMACS=disabled
if not "%EMACS%" == "disabled" goto SmallEnv
goto NextArgument
:SrcDirOption
echo %1 | grep -q "/"
if errorlevel 1 goto CollectArgument
set XSRC=%1
if not "%XSRC%" == "%1" goto SmallEnv
goto NextArgument
:CollectArgument
if "%ARGS%" == "" goto AddFirstArgToList
set _ARGS=%ARGS% %1
goto AddArgToList
:AddFirstArgToList
set _ARGS=%1
:AddArgToList
if not "%_ARGS%" == "%ARGS% %1" if not "%_ARGS%" == "%ARGS%%1" goto SmallEnv
echo %_ARGS% | grep -q "[^ ]"
if not errorlevel 0 set ARGS=%_ARGS%
set _ARGS=
:NextArgument
shift
if not "%1" == "" goto ArgLoop

Rem Create an arguments file for the configure script.
echo --srcdir=%XSRC% > args
:if "%CACHING%" == "enabled"              echo --cache-file=%XSRC%/djgpp/config.cache >> args
if "%CACHING%" == "enabled"              echo --cache-file=./config.cache >> args
if "%DEPENDENCY_TRACKING%" == "enabled"  echo --enable-dependency-tracking >> args
if "%DEPENDENCY_TRACKING%" == "disabled" echo --disable-dependency-tracking >> args
if "%LIBICONV_PREFIX%" == "enabled"      echo --with-libiconv-prefix >> args
if "%LIBICONV_PREFIX%" == "disabled"     echo --without-libiconv-prefix >> args
if "%LIBINTL_PREFIX%" == "enabled"       echo --with-libintl-prefix >> args
if "%LIBINTL_PREFIX%" == "disabled"      echo --without-libintl-prefix >> args
if "%HTML%" == "enabled"                 echo --enable-html >> args
if "%HTML%" == "disabled"                echo --disable-html >> args
if "%SILENT%" == "enabled"               echo --enable-silent-rules >> args
if "%SILENT%" == "disabled"              echo --disable-silent-rules >> args
if "%ACL%" == "enabled"                  echo --enable-acl >> args
if "%ACL%" == "disabled"                 echo --disable-acl >> args
if "%CURSES%" == "enabled"               echo --enable-curses >> args
if "%CURSES%" == "disabled"              echo --disable-curses >> args
if "%THREADS%" == "enabled"              echo --enable-threads >> args
if "%THREADS%" == "disabled"             echo --disable-threads >> args
if "%C++%" == "enabled"                  echo --enable-c++ >> args
if "%C++%" == "disabled"                 echo --disable-c++ >> args
if "%LIBASPRINTF%" == "enabled"          echo --enable-libasprintf >> args
if "%LIBASPRINTF%" == "disabled"         echo --disable-libasprintf >> args
if "%EMACS%" == "enabled"                echo --with-emacs >> args
if "%EMACS%" == "disabled"               echo --without-emacs >> args
if not "%ARGS%" == ""                    echo %ARGS% >> args

echo --prefix=/dev/env/DJDIR >> args

set ARGS=
set CACHING=
set DEPENDENCY_TRACKING=
set LIBICONV_PREFIX=
set LIBINTL_PREFIX=
set HTML=
set SILENT=
set ACL=
set CURSES=
set THREADS=
set C++=
set LIBASPRINTF=
set EMACS=


if "%XSRC%" == "." goto InPlace

:NotInPlace
redir -e /dev/null update %XSRC%/configure.org ./configure
test -f ./configure
if errorlevel 1 update %XSRC%/configure ./configure

:InPlace
Rem Update configuration files
echo Updating configuration scripts...
test -f ./configure.org
if errorlevel 1 update configure configure.org
sed -f %XSRC%/djgpp/config.sed configure.org > filename.ext
if errorlevel 1 goto SedError
sed "/symlink /s/`//g" ./filename.ext > configure
dtou ./configure
touch -r configure.org ./configure
rm -f ./filename.ext

test -f %XSRC%/gettext-runtime/configure.org
if errorlevel 1 update %XSRC%/gettext-runtime/configure %XSRC%/gettext-runtime/configure.org
sed -f %XSRC%/djgpp/config.sed %XSRC%/gettext-runtime/configure.org > filename.ext
if errorlevel 1 goto SedError
sed "/symlink /s/`//g" ./filename.ext > configure.tmp
mv configure.tmp %XSRC%/gettext-runtime/configure
dtou %XSRC%/gettext-runtime/configure
touch -r %XSRC%/gettext-runtime/configure.org %XSRC%/gettext-runtime/configure
rm -f ./filename.ext

test -f %XSRC%/gettext-runtime/libasprintf/configure.org
if errorlevel 1 update %XSRC%/gettext-runtime/libasprintf/configure %XSRC%/gettext-runtime/libasprintf/configure.org
sed -f %XSRC%/djgpp/config.sed %XSRC%/gettext-runtime/libasprintf/configure.org > filename.ext
if errorlevel 1 goto SedError
sed "/symlink /s/`//g" ./filename.ext > configure.tmp
mv configure.tmp %XSRC%/gettext-runtime/libasprintf/configure 
dtou %XSRC%/gettext-runtime/libasprintf/configure
touch -r %XSRC%/gettext-runtime/libasprintf/configure.org %XSRC%/gettext-runtime/libasprintf/configure
rm -f ./filename.ext

test -f %XSRC%/gettext-tools/configure.org
if errorlevel 1 update %XSRC%/gettext-tools/configure %XSRC%/gettext-tools/configure.org
sed -f %XSRC%/djgpp/config.sed %XSRC%/gettext-tools/configure.org > filename.ext
if errorlevel 1 goto SedError
sed "/symlink /s/`//g" ./filename.ext > configure.tmp
mv configure.tmp %XSRC%/gettext-tools/configure
dtou %XSRC%/gettext-tools/configure
touch -r %XSRC%/gettext-tools/configure.org %XSRC%/gettext-tools/configure
rm -f ./filename.ext

test -f %XSRC%/gettext-tools/examples/configure.org
if errorlevel 1 update %XSRC%/gettext-tools/examples/configure %XSRC%/gettext-tools/examples/configure.org
sed -f %XSRC%/djgpp/config.sed %XSRC%/gettext-tools/examples/configure.org > filename.ext
if errorlevel 1 goto SedError
sed "/symlink /s/`//g" ./filename.ext > configure.tmp
mv configure.tmp %XSRC%/gettext-tools/examples/configure
dtou %XSRC%/gettext-tools/examples/configure
touch -r %XSRC%/gettext-tools/examples/configure.org %XSRC%/gettext-tools/examples/configure
rm -f ./filename.ext

Rem Make sure they have a config.site file
set CONFIG_SITE=%XSRC%/djgpp/config.site
if not "%CONFIG_SITE%" == "%XSRC%/djgpp/config.site" goto SmallEnv

Rem Make sure crucial file names are not munged by unpacking
test -f %XSRC%/gettext-tools/config.h.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/config.h.in %XSRC%/gettext-tools/config.h-in
test -f %XSRC%/gettext-tools/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/config.h %XSRC%/gettext-tools/config.h-in
test -f %XSRC%/gettext-tools/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/configh.in %XSRC%/gettext-tools/config.h-in
test -f %XSRC%/gettext-tools/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/config_h.in %XSRC%/gettext-tools/config.h-in
test -f %XSRC%/gettext-runtime/config.h.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/config.h.in %XSRC%/gettext-runtime/config.h-in
test -f %XSRC%/gettext-runtime/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/config.h %XSRC%/gettext-runtime/config.h-in
test -f %XSRC%/gettext-runtime/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/configh.in %XSRC%/gettext-runtime/config.h-in
test -f %XSRC%/gettext-runtime/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/config_h.in %XSRC%/gettext-runtime/config.h-in
test -f %XSRC%/gettext-runtime/libasprintf/config.h.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/libasprintf/config.h.in %XSRC%/gettext-runtime/libasprintf/config.h-in
test -f %XSRC%/gettext-runtime/libasprintf/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/libasprintf/config.h %XSRC%/gettext-runtime/libasprintf/config.h-in
test -f %XSRC%/gettext-runtime/libasprintf/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/libasprintf/configh.in %XSRC%/gettext-runtime/libasprintf/config.h-in
test -f %XSRC%/gettext-runtime/libasprintf/config.h-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/libasprintf/config_h.in %XSRC%/gettext-runtime/libasprintf/config.h-in
test -f %XSRC%/gettext-runtime/po/Makefile.am.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/po/Makefile.am.in %XSRC%/gettext-runtime/po/Makefile.am-in
test -f %XSRC%/gettext-runtime/po/Makefile.am-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/po/Makefile.am %XSRC%/gettext-runtime/po/Makefile.am-in
test -f %XSRC%/gettext-runtime/po/Makefile.in.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/po/Makefile.in.in %XSRC%/gettext-runtime/po/Makefile.in-in
test -f %XSRC%/gettext-runtime/po/Makefile.in-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-runtime/po/Makefile.in %XSRC%/gettext-runtime/po/Makefile.in-in
test -f %XSRC%/gettext-tools/po/Makefile.am.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/po/Makefile.am.in %XSRC%/gettext-tools/po/Makefile.am-in
test -f %XSRC%/gettext-tools/po/Makefile.am-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/po/Makefile.am %XSRC%/gettext-tools/po/Makefile.am-in
test -f %XSRC%/gettext-tools/po/Makefile.in.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/po/Makefile.in.in %XSRC%/gettext-tools/po/Makefile.in-in
test -f %XSRC%/gettext-tools/po/Makefile.in-in
if errorlevel 1 redir -e /dev/null mv -f %XSRC%/gettext-tools/po/Makefile.in %XSRC%/gettext-tools/po/Makefile.in-in
test -f %XSRC%/build-aux/snippet/c++defs.h
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/build-aux/snippet/c++defs.h %XSRC%/build-aux/snippet/cxxdefs.h
test -f %XSRC%/build-aux/csharpcomp.sh.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/build-aux/csharpcomp.sh.in %XSRC%/build-aux/csharpcomp.sh-in
test -f %XSRC%/build-aux/csharpexec.sh.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/build-aux/csharpexec.sh.in %XSRC%/build-aux/csharpexec.sh-in
test -f %XSRC%/build-aux/javacomp.sh.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/build-aux/javacomp.sh.in %XSRC%/build-aux/javacomp.sh-in
test -f %XSRC%/build-aux/javaexec.sh.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/build-aux/javaexec.sh.in %XSRC%/build-aux/javaexec.sh-in
test -f %XSRC%/build-aux/relocatable.sh.in
if not errorlevel 1 redir -e /dev/null mv -f %XSRC%/build-aux/relocatable.sh.in %XSRC%/build-aux/relocatable.sh-in

:# Beginn  Zusaetzliche zu veraendernde Dateinamen.
:test -f %XSRC%/man/gettext.in
:if not errorlevel redir -e /dev/null 1 mv -f %XSRC%/man/gettext..in %XSRC%/man/gettext.-in
:test -f %XSRC%/man/gettext.-in
:if errorlevel 1 redir -e /dev/null mv -f %XSRC%/man/gettext. %XSRC%/man/gettext.-in
:# Ende  Zusaetzliche zu veraendernde Dateinamen.

Rem Update libtool files
echo Updating libtool scripts...
test -f %XSRC%/build-aux/ltmain.org
if errorlevel 1 update %XSRC%/build-aux/ltmain.sh %XSRC%/build-aux/ltmain.org
sed -f %XSRC%/djgpp/ltmain.sed %XSRC%/build-aux/ltmain.org > ltmain.tmp
if errorlevel 1 goto SedError6
mv -f ltmain.tmp %XSRC%/build-aux/ltmain.sh
dtou %XSRC%/build-aux/ltmain.sh
touch -r %XSRC%/build-aux/ltmain.org %XSRC%/build-aux/ltmain.sh

Rem DOS specific fixes in gettext-tools/tests/init.sh 
echo DOS specific fixes in gettext-tools/tests/init.sh...
test -f %XSRC%/gettext-tools/tests/init.org
if errorlevel 1 update %XSRC%/gettext-tools/tests/init.sh %XSRC%/gettext-tools/tests/init.org
sed -f %XSRC%/djgpp/init_sh.sed %XSRC%/gettext-tools/tests/init.org > init.tmp
if errorlevel 1 goto SedError7
mv -f init.tmp %XSRC%/gettext-tools/tests/init.sh
dtou %XSRC%/gettext-tools/tests/init.sh
touch -r %XSRC%/gettext-tools/tests/init.org %XSRC%/gettext-tools/tests/init.sh

Rem This is required because DOS/Windows are case-insensitive
Rem to file names, and "make install" will do nothing if Make
Rem finds a file called `install'.
if exist INSTALL ren INSTALL INSTALL.txt

Rem Set SHELL to a sane default or some configure tests stop working
Rem if the package is configured across partitions.
if not "%SHELL%" == "" goto HomeName
set SHELL=/bin/sh
if not "%SHELL%" == "/bin/sh" goto SmallEnv
echo No SHELL found in the environment, using default value

:HomeName
Rem Set HOME to a sane default so configure stops complaining.
if not "%HOME%" == "" goto HostName
set HOME=%XSRC%/djgpp
if not "%HOME%" == "%XSRC%/djgpp" goto SmallEnv
echo No HOME found in the environment, using default value

:HostName
Rem Set HOSTNAME so it shows in config.status
if not "%HOSTNAME%" == "" goto hostdone
if "%windir%" == "" goto msdos
set OS=MS-Windows
if not "%OS%" == "MS-Windows" goto SmallEnv
goto haveos
:msdos
set OS=MS-DOS
if not "%OS%" == "MS-DOS" goto SmallEnv
:haveos
if not "%USERNAME%" == "" goto haveuname
if not "%USER%" == "" goto haveuser
echo No USERNAME and no USER found in the environment, using default values
set HOSTNAME=Unknown PC
if not "%HOSTNAME%" == "Unknown PC" goto SmallEnv
goto userdone
:haveuser
set HOSTNAME=%USER%'s PC
if not "%HOSTNAME%" == "%USER%'s PC" goto SmallEnv
goto userdone
:haveuname
set HOSTNAME=%USERNAME%'s PC
if not "%HOSTNAME%" == "%USERNAME%'s PC" goto SmallEnv
:userdone
set _HOSTNAME=%HOSTNAME%, %OS%
if not "%_HOSTNAME%" == "%HOSTNAME%, %OS%" goto SmallEnv
set HOSTNAME=%_HOSTNAME%
:hostdone
set _HOSTNAME=
set OS=

Rem install-sh is required by the configure script but clashes with the
Rem various Makefile install-foo targets, so we MUST have it before the
Rem script runs and rename it afterwards
test -f %XSRC%/install-sh
if not errorlevel 1 goto NoRen0
test -f %XSRC%/install-sh.sh
if not errorlevel 1 mv -f %XSRC%/install-sh.sh %XSRC%/install-sh
:NoRen0

if "%NLS%" == "disabled" goto WithoutNLS

:WithNLS
test -d %XSRC%/gettext-runtime/po
if errorlevel 1 goto WithoutNLS
test -d %XSRC%/gettext-tools/po
if errorlevel 1 goto WithoutNLS

Rem Check for the needed libraries and binaries.
Rem binaries and libraries provided by libiconv.
test -f /dev/env/DJDIR/include/libcharset.h
if errorlevel 1 goto MissingNLSTools
test -f /dev/env/DJDIR/lib/libcharset.a
if errorlevel 1 goto MissingNLSTools
test -f /dev/env/DJDIR/include/iconv.h
if errorlevel 1 goto MissingNLSTools
test -f /dev/env/DJDIR/lib/libiconv.a
if errorlevel 1 goto MissingNLSTools


Rem Recreate the files in the %XSRC%/po subdir with our ported tools.
redir -e /dev/null rm %XSRC%/gettext-runtime/po/*.gmo
redir -e /dev/null rm %XSRC%/gettext-runtime/po/gettext-runtime.pot
:redir -e /dev/null rm %XSRC%/gettext-runtime/po/cat-id-tbl.c
:redir -e /dev/null rm %XSRC%/gettext-runtime/po/stamp-cat-id
redir -e /dev/null rm %XSRC%/gettext-tools/po/*.gmo
redir -e /dev/null rm %XSRC%/gettext-tools/po/gettext-tools.pot
:redir -e /dev/null rm %XSRC%/gettext-tools/po/cat-id-tbl.c
:redir -e /dev/null rm %XSRC%/gettext-tools/po/stamp-cat-id

Rem Update the arguments file for the configure script.
echo --enable-nls --with-included-gettext >> args
goto ConfigurePackage

:MissingNLSTools
echo Needed DJGPP ports of the required libs/tools for NLS support not found.
echo Configuring without NLS.
:WithoutNLS
Rem Update the arguments file for the configure script.
echo --disable-nls >> args

:ConfigurePackage
echo Running the ./configure script...
sh ./configure @args
:if errorlevel 1 goto RunConfigStatus
:rm args
:echo Done.
:goto EditFiles
::RunConfigStatus
:cd gettext-tools
:test -f ./config.status
:if errorlevel 1 goto CfgError
:echo Running the ./gettext-tools/config.status script (manually)...
:redir -e /dev/null sh ./config.status
:if errorlevel 1 goto CfgError
:cd ..
rm args
echo Done.

:EditFiles
echo Editing config.h...
test -f ./gettext-runtime/config.h
update ./gettext-runtime/config.h ./gettext-runtime/config_h.org
sed -f %XSRC%/djgpp/config_h.sed ./gettext-runtime/config_h.org > config.h
if errorlevel 1 goto SedError2
mv -vf ./config.h ./gettext-runtime/config.h
test -f ./gettext-runtime/libasprintf/config.h
update ./gettext-runtime/libasprintf/config.h ./gettext-runtime/libasprintf/config_h.org
sed -f %XSRC%/djgpp/config_h.sed ./gettext-runtime/libasprintf/config_h.org > config.h
if errorlevel 1 goto SedError2
mv -vf ./config.h ./gettext-runtime/libasprintf/config.h
test -f ./gettext-tools/config.h
update ./gettext-tools/config.h ./gettext-tools/config_h.org
sed -f %XSRC%/djgpp/config_h.sed ./gettext-tools/config_h.org > config.h
if errorlevel 1 goto SedError2
mv -vf ./config.h ./gettext-tools/config.h
echo Done.

echo Editing gettext-runtime/gnulib-lib/Makefile...
update ./gettext-runtime/gnulib-lib/Makefile ./gettext-runtime/gnulib-lib/Makefile.org
sed -f %XSRC%/djgpp/Makefile.sed ./gettext-runtime/gnulib-lib/Makefile.org > Makefile.gnulib
if errorlevel 1 goto SedError3
mv Makefile.gnulib ./gettext-runtime/gnulib-lib/Makefile
echo Done.

echo Editing gettext-tools/doc/Makefile...
update ./gettext-tools/doc/Makefile ./gettext-tools/doc/Makefile.org
sed -f %XSRC%/djgpp/Makefile.sed ./gettext-tools/doc/Makefile.org > Makefile.doc
if errorlevel 1 goto SedError4
mv Makefile.doc ./gettext-tools/doc/Makefile
echo Done.

echo Editing gettext-tools/tests/Makefile...
update ./gettext-tools/tests/Makefile ./gettext-tools/tests/Makefile.org
sed -f %XSRC%/djgpp/Makefile.sed ./gettext-tools/tests/Makefile.org > Makefile.tst
if errorlevel 1 goto SedError5
mv Makefile.tst ./gettext-tools/tests/Makefile
echo Done.

:NextEdit
Rem Create po/LINGUAS file or the build fails.
update %XSRC%/gettext-runtime/po/LINGUAS ./gettext-runtime/po/LINGUAS  
update %XSRC%/gettext-tools/po/LINGUAS ./gettext-tools/po/LINGUAS  
update %XSRC%/gettext-tools/examples/po/LINGUAS ./gettext-tools/examples/po/LINGUAS  
goto End

:SedError
echo ./configure script editing failed!
goto End

:SedError2
echo config.h fixing failed!
goto End

:SedError3
echo gettext-runtime/gnulib-lib/Makefile fixing failed!
goto End

:SedError4
echo gettext-tools/doc/Makefile fixing failed!
goto End

:SedError5
echo gettext-tools/tests/Makefile fixing failed!
goto End

:SedError6
echo ./ltmain.sh editing failed!
goto End

:SedError7
echo ./init.sh fixing failed!
goto End

:CfgError
echo ./configure script exited abnormally!
goto End

:SmallEnv
echo Your environment size is too small.  Enlarge it and run me again.
echo Configuration NOT done!

:End
test -f %XSRC%/install-sh.sh
if not errorlevel 1 goto NoRen1
test -f %XSRC%/install-sh
if not errorlevel 1 mv -f %XSRC%/install-sh %XSRC%/install-sh.sh
:NoRen1
if "%SHELL%" == "/bin/sh" set SHELL=
if "%HOME%" == "%XSRC%/djgpp" set HOME=
set ARGS=
set CONFIG_SITE=
set HOSTNAME=
set NLS=
set CACHING=
set DEPENDENCY_TRACKING=
set SILENT=
set ACL=
set CURSES=
set THREADS=
set C++=
set LIBASPRINTF=
set EMACS=
set XSRC=
