#!/bin/sh
#
# SPDX-FileCopyrightText: 2005 David Johnson
# SPDX-FileCopyrightText: 2005-2021 Dirk Meyer
# SPDX-License-Identifier: GPL-2.0-only
#
# $Id: Configure,v 1.276 2021/09/19 10:10:11 cvs Exp $
#

VERSION="3.33"
RELEASE=1

if [ $RELEASE -eq 1 ]; then
 VERSIONLONG="$VERSION"
else
 VERSIONLONG="$VERSION Beta"
fi

msg2()
{
 echo "${@}" | iconv -f utf-8 -t latin1
}

case "${LANG}" in
*.iso-8*|*.ISO-8*)
 msg="msg2"
 lynxopt="-dump"
 ;;
*)
 msg="echo"
 lynxopt="-dump -display_charset=utf-8"
 ;;
esac

usage()
{
 case "${LANG}" in
 fr*)
  ${msg} "Utilisation : Configure [ options ]
   -help        Afficher cette aide
   -error       Afficher les erreurs lors de l'exécution de Configure
   -debug       Compiler avec les informations de débogage
   -profiling   Compiler avec les informations du profil
   -warn        Compiler avec des alertes supplémentaires
   -geoip       Compiler avec le support GeoIP (pour l'IP par pays)
   -curl        Compiler avec le support Curl (pour la commande « FETCH »)
   -tls         Compiler avec GnuTLS lib (au lieu de OpenSSL)
   -upnp        Compiler avec le support UPnP avec miniupnpc (pour les routeurs NAT)
   -ruby        Compiler avec le support pour les scripts Ruby
   -kqueue      Compiler avec le support kqueue()
   -no-blowfish Compiler sans le support Blowfish
   -no-chroot   Compiler sans le support chroot()
   -no-openssl  Compiler sans le support OpenSSL
   -no-http     Compiler sans le serveur HTTP interne
   -no-admin    Compiler sans le serveur HTTP d'administration (nécessite le serveur HTTP interne)
   -no-telnet   Compiler sans le serveur Telnet
   -no-memsave  Compiler sans protection de mémoire
   -no-libs     Compiler un binaire statique
   TRANSLATION= Définir une traduction personnalisée
   PREFIX=      Définir le chemin d'installation (par défaut « /usr/local »)
   LOCALBASE=   Définir le chemin des « .h » et librairies (« /usr/local »)
   CC=gcc       Définir le compilateur (« gcc »)
   CFLAGS=      Définir les options du compilateur
   LDFLAGS=     Définir les options du compilateur pour la liaison
   SLDFLAGS=    Définir les options du compilateur pour la liaison statique seulement
   LIBS=        Définir les librairies personnalisées
   RUBY=        Définir l'interpréteur de Ruby (« ruby »)"
  ;;
 de*)
  ${msg} "Usage: Configure [ options ]
   -help        Dise Hilfe
   -error       Zeige alle Fehlermeldungen des Compilers
   -debug       Aktiviere Diagnosefuntionen in iroffer
   -profiling   Benutze 'profiling' Funktionen
   -warn        Aktiviere alle Warnungen beim Uebersetzen
   -geoip       Benutze GeoIP Bibliothek (für IP nach Land)
   -curl        Benutze Curl Bibliothek (für den FETCH-Befehl)
   -tls         Benutze GnuTLS Bibliothek (anstelle von OpenSSL)
   -upnp        Benutze miniupnpc Bibliothek (für UPNP-NAT Routers)
   -ruby        Benutze Ruby Skript Erweiterung
   -kqueue	Benutze kqueue()
   -no-blowfish Baue ohne Blowfish Verschlusselung
   -no-chroot   Baue ohne chroot()
   -no-openssl  Baue ohne OpenSSL Bibliothek
   -no-http     Baue ohne HTTP Server
   -no-admin    Baue ohne HTTP Admin
   -no-telnet   Baue ohne Telnet Server
   -no-memsave  Baue ohne Speicherschutz
   -no-libs     Baue ein statische Programm
   TRANSLATION=	Setze weitere Übersetzungen
   PREFIX=      Setze Installations-Pfad  (/usr/local)
   LOCALBASE=   Setze Pfad für Include-Dateien und Bibliotheken (/usr/local)
   CC=gcc       Setze Compiler (gcc)
   CFLAGS=      Setze Compiler Optionen
   LDFLAGS=     Setze Linker Optionen
   SLDFLAGS=    Setze Linker Optionen für das statische binden
   LIBS=        Setze weitere Bibliotheken
   RUBY=        Setze Ruby Interpreter (ruby)"
  ;;
 *)
  ${msg} "Usage: Configure [ options ]
   -help        This help
   -error       Print errors while running Configure
   -debug       Compile with debug symbols
   -profiling   Compile with profiling flags
   -warn        Compile with extra warning flags
   -geoip       Compile GeoIP lib (for IP to Country)
   -curl        Compile Curl lib (for the FETCH-Command)
   -tls         Compile with GnuTLS lib (instead of OpenSSL)
   -upnp        Compile with UPnP support with miniupnpc (for NAT Routers)
   -ruby        Compile with Ruby scripting support
   -kqueue	Compile with kqueue() support
   -no-blowfish Compile without Blowfish encryption
   -no-chroot   Compile without chroot() support
   -no-openssl  Compile without OpenSSL lib
   -no-http     Compile without HTTP server
   -no-admin    Compile without HTTP Admin
   -no-telnet   Compile without Telnet server
   -no-memsave  Compile without memory protection
   -no-libs     Compile an static binary
   TRANSLATION=	Set custom translations
   PREFIX=      Set installation prefix (/usr/local)
   LOCALBASE=   Set prefix for includes and libs (/usr/local)
   CC=gcc       Set Compiler (gcc)
   CFLAGS=      Set custom compiler flags
   LDFLAGS=     Set custom linker flags
   SLDFLAGS=    Set custom linker flags for static only
   LIBS=        Set custom libs
   RUBY=        Set ruby interpreter (ruby)"
  ;;
 esac
 exit 64
}

case "${LANG}" in
fr*)
 irt_start="Configuration pour"
 irt_again="Vous devriez relancer Configure avec le paramètre « -error » pour voir les détails."
 irt_noopenssl="ATTENTION : Utilisez « -no-openssl »"
 irt_multinet="ATTENTION : Multinet est maintenant par défaut, enlevez « -m »"
 irt_checkingos="Détermine le système d'exploitation... "
 irt_checkfor="Vérification pour"
 irt_checkif="Vérifie si"
 irt_error="***ERREUR*** :"
 irt_notsupported="Ce système d'exploitation n'est pas supporté"
 irt_noedit="Ce fichier est automatiquement généré, ne pas modifier !"
 irt_showerror="Affichage des erreurs lors de l'exécution"
 irt_configure="Configuration"
 irt_debugging="le débogage"
 irt_extrawarnings="les messages d'avertissements"
 irt_pedantic="les avertissements détaillés"
 irt_profiling="le profil"
 irt_with="avec"
 irt_without="sans"
 irt_blowfish="encodage Blowfish"
 irt_memory="protection de la mémoire"
 irt_found="trouvé"
 irt_notfound="non trouvé"
 irt_noexec="Vous n'êtes pas autorisé à exécuter"
 irt_nomake="Impossible de trouver « make » ou « gmake »"
 irt_nomake="Impossible de trouver « gcc » ou « cc »"
 irt_seeingif="Vérifie si"
 irt_seeinghow="Vérifie comment"
 irt_works="fonctionne"
 irt_worksinstead="travaille à la place"
 irt_asexpected="comme prévu"
 irt_nowork="ne semble pas fonctionner"
 irt_yes="oui"
 irt_no="non"
 irt_accepts="accepte"
 irt_unknown="inconnu"
 irt_neither1="ni"
 irt_neither2="ou"
 irt_neither3="fonctionnent"
 irt_seeing16bit="Vérifie comment définir un entier de 16 bits"
 irt_seeing32bit="Vérifie comment définir un entier de 32 bits"
 irt_seeing64bit="Vérifie comment définir un entier de 64 bits"
 irt_isdefined="est défini"
 irt_noipv6="échec, les IPv6 ne fonctionnent pas"
 irt_compiling="la compilation avec la norme « #include »"
 irt_nocompiling="n'a pas pu construire avec la norme « #include »"
 irt_large="large"
 irt_is="est"
 irt_boosting="augmenter à"
 irt_novalue="n'a pas pu le déterminer"
 irt_endianness="Détermination « endianness »"
 irt_endianbig="gros-boutiste"
 irt_endianlittle="petit-boutiste"
 irt_largefile="le support des gros fichiers"
 irt_nolargefile="Non. La taille maximale des fichiers sera de"
 irt_signedness="Détermine la version non signé de"
 irt_display_int64="afficher 64 bits en utilisant"
 irt_display_time="l'affichage « de time_t » en utilisant"
 irt_msssing1="absent"
 irt_msssing2="simulera"
 irt_exists="existe"
 irt_isneeded="est nécessaire"
 irt_notneeded="pas nécessaire"
 irt_needed="nécessaire"
 irt_nocrypt="n'a pas pu trouver « crypt() » avec ou sans « crypt.h »"
 irt_nolcrypt="Impossible à lier avec ou sans « -lcrypt » ou « -lcrypto »"
 irt_neither4="Non plus"
 irt_for="pour"
 irt_nopassword="va désactiver les mots de passe cryptés"
 irt_nochroot="va désactiver « chroot() »"
 irt_nosetuid="va désactiver « setuid() »"
 irt_nogetgrouplist="la liste des groupes seront incorrectes avec « setuid() »"
 irt_nosendfile="n'utilisera pas « sendfile() »"
 irt_nommap="n'utilisera « mmap() »"
 irt_creating="Création de"
 irt_done="Fait"
 irt_fdlimit="nom de « fd limit »"
 irt_nofdlimit="ne travaille pas"
 irt_nosignal="utilisera une gestion des signaux boiteuse"
 irt_values="les valeurs"
 irt_nosi_code="ne fera pas état de « si_code »"
 irt_nowait="ne fera pas état des codes de statuts de « wait() »"
 irt_tos="TOS peut être défini pour les sockets IP"
 irt_nogetaddrinfo="utilisera « gethostbyname() » à la place"
 irt_nogethostbyname="ne fera pas état des codes d'erreur"
 irt_nores_init="« res_init() » ne sera pas utilisé"
 irt_no_kqueue="« kqueue() » ne sera pas utilisé"
 irt_seeingif_lib="Vérifie si les librairies"
 irt_lib_exists="existent"
 irt_geoip6="prend en charge les IPv6"
 irt_nogeoip6="Désactive GeoIP pour l'IPv6. Si vous voulez utilisez cette fonction, mettez à jour « libGeoIP »"
 irt_nogeoip="Désactive la vérification GeoIP. Si vous voulez utilisez cette fonction, installez « libGeoIP »"
 irt_noupnp="Désactive la fonction UPnP. Si vous voulez utilisez cette fonction, installez « libminiupnpc »"
 irt_nocurl="Désactive la commande « FETCH ». Si vous voulez utiliser cette fonction, installez « libcurl »"
 irt_curlssl="Note : Votre « libcurl » est lié avec"
 irt_nossl="Désactive les fonctions SSL. Si vous voulez utiliser cette fonction, installez « OpenSSL »"
 irt_notls="Désactive les fonctions SSL. Si vous voulez utiliser cette fonction, installez « GnuTLS »"
 irt_badssl1="Votre « libcurl » est liée avec"
 irt_badssl2="S'il vous plaît, configurez"
 irt_badssl3="S'il vous plaît, configurez sans"
 irt_noruby="Désactiver l'extension Ruby. Si vous voulez utiliser cette fonction, installez « libruby »"
 irt_make1="Type"
 irt_make2="à compiler"
 irt_noerror="Aucune erreur ou avertissement ne doit apparaître lors de la compilation, si c'est le cas, quelque chose ne va pas"
 ;;
de*)
 irt_start="Konfiguriere für"
 irt_again="Bitte starte Configure zusätzlich mit dem Parameter '-error' für die Fehlermeldungen."
 irt_noopenssl="WARNUNG: Bitte den Parameter '-no-openssl' benutzen"
 irt_multinet="WARNUNG: Multinet ist immer aktiv, entfernde den Parameter -m"
 irt_checkingos="Prüfe Betriebssystem... "
 irt_checkfor="Prüfe auf"
 irt_checkif="Prüfe ob"
 irt_error="***FEHLER***:"
 irt_notsupported="Das Betriebssystem ist nicht unterstützt"
 irt_noedit="Automatisch erstellt, nicht aendern"
 irt_showerror="Zeige Fehlermeldungen beim Konfigurieren"
 irt_configure="Konfiguriere"
 irt_debugging="debugging"
 irt_extrawarnings="zusätzliche Warnungen"
 irt_pedantic="pedantische Warnungen"
 irt_profiling="profiling"
 irt_with="mit"
 irt_without="ohne"
 irt_blowfish="blowfish Verschlüsselung"
 irt_memory="memory protection"
 irt_found="gefunden"
 irt_notfound="nicht gefunden"
 irt_noexec="Du kannst das Programm nicht ausführen"
 irt_nomake="Kann weder 'make' noch 'gmake' finden"
 irt_nocc="Kann weder 'gcc' noch 'cc' finden"
 irt_seeingif="Prüfe ob"
 irt_seeinghow="Prüfe wie"
 irt_works="funktioniert"
 irt_worksinstead="funtioniert anstelle"
 irt_asexpected="wie erwartet"
 irt_nowork="funktioniert offenbar nicht"
 irt_yes="ja"
 irt_no="nein"
 irt_accepts="erkennt"
 irt_unknown="Unbekannt"
 irt_neither1="weder"
 irt_neither2="noch"
 irt_neither3="funktioniert"
 irt_seeing16bit="Prüfe wie ein 16 Bit Integer definiert wird"
 irt_seeing32bit="Prüfe wie ein 32 Bit Integer definiert wird"
 irt_seeing64bit="Prüfe wie ein 64 Bit Integer definiert wird"
 irt_isdefined="ist definiert"
 irt_noipv6="Nein, IPv6 wird nicht funktionieren"
 irt_compiling="das Übersetzen mit den Standard #include's"
 irt_nocompiling="Kann nicht mit den Standard #include's übersetzen"
 irt_large="groß"
 irt_is="ist"
 irt_boosting="Vergrößere auf"
 irt_novalue="kann den Wert nicht ermitteln"
 irt_endianness="Ermittle Byte-Reihenfolge"
 irt_endianbig="Big-Endian"
 irt_endianlittle="Little-Endian"
 irt_largefile="Zugriff auf große Dateien"
 irt_nolargefile="Nein.  Maximale Dategröße ist"
 irt_signedness="Ermittle den Vorzeichentyp von"
 irt_display_int64="die Ausgabe von 64bit definiert wird mit"
 irt_display_time="die Ausgabe von time_t definiert wird mit"
 irt_msssing1="fehlt"
 irt_msssing2="benutze Ersatz"
 irt_exists="existiert"
 irt_isneeded="benötigt wird"
 irt_notneeded="wird nicht benötigt"
 irt_needed="wird benötigt"
 irt_nocrypt="kann crypt() weder mit noch ohne crypt.h finden"
 irt_nolcrypt="kannt weder mit noch ohne -lcrypt oder -lcrypto binden"
 irt_neither4="Keines"
 irt_for="für"
 irt_nopassword="kann keine Passwörter verschlüsseln"
 irt_nochroot="kann kein chroot() verwenden"
 irt_nosetuid="kann kein setuid() verwenden"
 irt_nogetgrouplist="Gruppen Rechte sind unvolstä#ndig bei setuid()"
 irt_nosendfile="Kann sendfile() nicht benutzen"
 irt_nommap="Kann mmap() nicht benutzen"
 irt_creating="Erzeuge"
 irt_done="fertig"
 irt_fdlimit="Name von fd limit"
 irt_nofdlimit="beide funktionieren nicht"
 irt_nosignal="Benutze einfache signal handlers"
 irt_values="Werte"
 irt_nosi_code="Kann keinen 'si_code' ausgeben."
 irt_nowait="kann keinen Status von wait() ausgeben"
 irt_tos="TOS für IP sockets gesetzt werden kann"
 irt_nogetaddrinfo="Benutze statt dessen gethostbyname()"
 irt_nogethostbyname="Kann Fehler nicht ausgeben"
 irt_nores_init="Kann res_init() nicht benutzen"
 irt_no_kqueue="Kann kqueue() nicht benutzen"
 irt_seeingif_lib="Prüfe ob"
 irt_lib_exists="Bibliothek existiert"
 irt_geoip6="hat IPv6 Funktionen"
 irt_nogeoip6="Benutze GeoIP nicht für IPv6. Für diese Funktion musst du eine neuer Version von 'libGeoIP' installieren"
 irt_nogeoip="Benutze GeoIP nicht. Für diese Funktion musst du 'libGeoIP' installieren"
 irt_noupnp="Benutze UPNP nicht. Für diese Funktion musst du 'libminiupnpc' installieren"
 irt_nocurl="Kein FETCH-Befehl. Für diese Funktion musst du 'libcurl' installieren"
 irt_curlssl="Hinweis: Deine 'libcurl' benutzt"
 irt_nossl="Benutze kein SSL. Für diese Funktion musst du 'OpenSSL' installieren"
 irt_notls="Benutze kein SSL. Für diese Funktion musst du 'GNU TLS' installieren"
 irt_badssl1="Deine 'libcurl' benutzt"
 irt_badssl2="Bitte konfiguriere"
 irt_badssl3="Bitte konfiguriere ohne"
 irt_noruby="Kann die RUBY-Erweiterung nicht benutzen. Für diese Funktion musst du 'libruby'installieren"
 irt_make1="Zum Übersetzen jetzt"
 irt_make2="eingeben"
 irt_noerror="Keine Fehler oder Warnungen sollten beim Übersetzen auftreten. Falls doch ist das ein Fehler"
 ;;
*)
 irt_start="Configuring for"
 irt_again="You should re-run Configure with the '-error' argument to see the details."
 irt_noopenssl="WARNING: Please use '-no-openssl'"
 irt_multinet="WARNING: Multinet is now default, remove '-m'"
 irt_checkingos="Determining OS... "
 irt_checkfor="Checking for"
 irt_checkif="Checking if"
 irt_error="***ERROR***:"
 irt_notsupported="This OS is not supported"
 irt_noedit="Automatically Generated, Do Not Edit"
 irt_showerror="Printing Errors During Execution"
 irt_configure="Configuring"
 irt_debugging="debugging"
 irt_extrawarnings="extra warnings"
 irt_pedantic="pedantic warnings"
 irt_profiling="profiling"
 irt_with="with"
 irt_without="without"
 irt_blowfish="blowfish encryption"
 irt_memory="memory protection"
 irt_found="found"
 irt_notfound="not found"
 irt_noexec="You are not allowed to execute"
 irt_nomake="Couldn't find 'make' or' gmake'"
 irt_nocc="Couldn't find 'gcc' or' cc'"
 irt_seeingif="Seeing if"
 irt_seeinghow="Seeing how"
 irt_works="works"
 irt_worksinstead="works instead"
 irt_asexpected="as expected"
 irt_nowork="didn't seem to work"
 irt_yes="yes"
 irt_no="no"
 irt_accepts="accepts"
 irt_unknown="Unknown"
 irt_neither1="neither"
 irt_neither2="or"
 irt_neither3="worked"
 irt_seeing16bit="Seeing how to define a 16 bit integer"
 irt_seeing32bit="Seeing how to define a 32 bit integer"
 irt_seeing64bit="Seeing how to define a 64 bit integer"
 irt_isdefined="is defined"
 irt_noipv6="failed, IPv6 will not work"
 irt_compiling="compiling with standard #include's"
 irt_nocompiling="couldn't build with standard #include's"
 irt_large="large"
 irt_is="is"
 irt_boosting="Boosting up to"
 irt_novalue="couldn't determine it"
 irt_endianness="Determining endianness"
 irt_endianbig="Big-Endian"
 irt_endianlittle="Little-Endian"
 irt_largefile="large file support"
 irt_nolargefile="No.  Max filesize will be"
 irt_signedness="Determing the signedness of"
 irt_display_int64="to display 64bit using"
 irt_display_time="to display time_t using"
 irt_msssing1="missing"
 irt_msssing2="will emulate"
 irt_exists="exists"
 irt_isneeded="is needed"
 irt_notneeded="not needed"
 irt_needed="needed"
 irt_nocrypt="couldn't find crypt() neither with or without crypt.h"
 irt_nolcrypt="couldn't link with or without -lcrypt or -lcrypto"
 irt_neither4="Neither"
 irt_for="for"
 irt_nopassword="will disable encrypted passwords"
 irt_nochroot="will not be able to chroot()"
 irt_nosetuid="will not be able to setuid()"
 irt_nogetgrouplist="group list will be incorrect when setuid()-ing"
 irt_nosendfile="won't use sendfile()"
 irt_nommap="won't use mmap()"
 irt_creating="Creating"
 irt_done="Done"
 irt_fdlimit="name of fd limit"
 irt_nofdlimit="neither name work"
 irt_nosignal="will use lame signal handlers"
 irt_values="values"
 irt_nosi_code="won't report 'si_code'"
 irt_nowait="won't report wait() status codes"
 irt_tos="TOS can be set for IP sockets"
 irt_nogetaddrinfo="will use gethostbyname() instead"
 irt_negetaddrinfo="utilisera gethostbyname à la place"
 irt_nogethostbyname="won't report error codes"
 irt_nores_init="won't use res_init()"
 irt_no_kqueue="won't use kqueue()"
 irt_seeingif_lib="Seeing if"
 irt_lib_exists="library exists"
 irt_geoip6="has IPv6 support"
 irt_nogeoip6="Disabled the GeoIP for IPv6. If you want to use this feature, please update 'libGeoIP'"
 irt_nogeoip="Disabled the GeoIP-check. If you want to use this feature, please install 'libGeoIP'"
 irt_noupnp="Disabled the UPNP-feature. If you want to use this feature, please install 'libminiupnpc'"
 irt_nocurl="Disabled the FETCH-Command. If you want to use this feature, please install 'libcurl'"
 irt_curlssl="Notice: Your 'libcurl' is linked with"
 irt_nossl="Disabled the SSL Features. If you want to use this feature, please install 'OpenSSL'"
 irt_notls="Disabled the SSL Features. If you want to use this feature, please install 'GNU TLS'"
 irt_badssl1="Your 'libcurl' is linked with"
 irt_badssl2="Please configure"
 irt_badssl3="Please configure without"
 irt_noruby="Disabled the RUBY-extension. If you want to use this feature, please install 'libruby'"
 irt_make1="Type"
 irt_make2="to compile"
 irt_noerror="No errors or warnings should appear when compiling, if they do, something is wrong"
 ;;
esac

echo
${msg} "${irt_start} iroffer-dinoex $VERSIONLONG"

waserror()
{
 ${msg} "${irt_again}"
 echo
 exit 72
}

cygwin_version()
{
  IFS='.-'
  set -e
  echo "${ver}" | (
    read ver_A ver_B ver_C dummy
    echo "${ver_A}"
    echo "${ver_B}"
    echo "${ver_C}"
    # 2.x.x - 9.x.x, 1.6.x - 1.9.x, and 1.5.6 - 1.5.9 are ok
    if [ \( "$ver_A" -ge "2" \)                                         \
      -o \( "$ver_A" -eq "1" -a "$ver_B" -ge "6" \)                     \
      -o \( "$ver_A" -eq "1" -a "$ver_B" -eq "5" -a "$ver_C" -ge "6" \) \
       ]; then
     ${msg} "OK, $ver"
    else
     ${msg} "${irt_error} $ver < 1.5.6"
     waserror
    fi
  )
  set +e
  unset IFS
}

FEATURES=""
OPT_WARN2=false
OPT_ERRORS=false
OPT_DEBUG=false
OPT_WARN=false
OPT_PROF=false
OPT_GEOIP=false
OPT_KQUEUE=false
OPT_CURL=false
OPT_SSL=true
OPT_TLS=false
OPT_UPNP=false
OPT_RUBY=false
OPT_NOADMIN=false
OPT_NOBLOWFISH=false
OPT_NOCHROOT=false
OPT_NOHTTP=false
OPT_NOTELNET=false
OPT_NOMEMSAVE=false
OPT_STATIC=false
cctype="gcc"
ruby="ruby"
PREFIX="/usr/local"
LOCALBASE="/usr/local"
TRANSLATION="de it fr"

while test "${1}" != ""
do
 case "${1}" in
 -h*) usage ;;
 CC=*) cctype="${1#CC=}" ;;
 CFLAGS=*) CFLAGS="${1#CFLAGS=}" ;;
 LDFLAGS=*) LDFLAGS="${1#LDFLAGS=}" ;;
 SLDFLAGS=*) SLDFLAGS="${1#SLDFLAGS=}" ;;
 LIBS=*) LIBS="${1#LIBS=}" ;;
 LOCALBASE=*) LOCALBASE="${1#LOCALBASE=}" ;;
 PREFIX=*) PREFIX="${1#PREFIX=}" ;;
 RUBY=*) ruby="${1#RUBY=}" ;;
 WARN=*) OPT_WARN2="${1#WARN=}" ;;
 TRANSLATION=*) TRANSLATION="${TRANSLATION} ${1##TRANSLATION=}" ;;
 -e*) OPT_ERRORS=true ;;
 -d*) OPT_DEBUG=true ;;
 -w*) OPT_WARN=true ;;
 -p*) OPT_PROF=true ;;
 -g*) OPT_GEOIP=true ;;
 -k*) OPT_KQUEUE=true ;;
 -c*) OPT_CURL=true ;;
 -s*) ${msg} "${irt_noopenssl}"; echo ""; OPT_SSL=false ;; # old
 -t*) OPT_TLS=true; OPT_SSL=false ;;
 -u*) OPT_UPNP=true ;;
 -r*) OPT_RUBY=true;;
 -no-a*) OPT_NOADMIN=true ;;
 -no-b*) OPT_NOBLOWFISH=true ;;
 -no-c*) OPT_NOCHROOT=true ;;
 -no-h*) OPT_NOHTTP=true ;;
 -no-t*) OPT_NOTELNET=true ;;
 -no-o*) OPT_SSL=false ;;
 -no-m*) OPT_NOMEMSAVE=true ;;
 -no-l*) OPT_STATIC=true ;;
 -m) ${msg} "${irt_multinet}"; echo "" ;; # multinet
 *)  usage ;;
 esac
 shift
done

ostype=`uname`
${msg} "${irt_checkingos}${ostype}"
installgroup="root"
libs=""
rstatic=""

case "$ostype" in
 FreeBSD | OpenBSD | NetBSD )
  installgroup="wheel"
  ;;
 Darwin)
  rstatic="-lpthread -ldl -lz"
  ;;
 Linux | IRIX | IRIX64 | OSF1 | Rhapsody | AIX )
  # nothing fancy
  rstatic="-lpthread -ldl -lz"
  ;;
 GNU/kFreeBSD | GNU )
  ostype="Linux"
  rstatic="-lpthread -ldl -lz"
  ;;
 SunOS )
  libs="$libs -lsocket -lnsl -lresolv"
  ;;
 BSD/OS )
  ostype=BSD_OS
  ;;
 HP-UX )
  ostype=HPUX
  ;;
 CYGWIN* )
  ostype="${ostype%%_*}" # Strip Windows
  rstatic="-static-libgcc"
  exe=.exe

  # only 1.5.6 or later is supported
  ${msg} -n "${irt_checkfor} >= 1.5.6... "
  ver=`uname -r`
  ver="${ver%%(*}" # Strip
  VERSIONLONG="${VERSIONLONG} (Win32) $ver"
  cygwin_version "${ver}"
  ;;
 *)
  ${msg} "${irt_error} ${irt_notsupported}"
  waserror
  ;;
esac

${msg} "/* ${irt_noedit} */" > src/iroffer_config.h
echo "" >> src/iroffer_config.h

${msg} "#define VERSIONLONG \"$VERSIONLONG\"" >> src/iroffer_config.h
echo "#define _OS_$ostype" >> src/iroffer_config.h

if $OPT_ERRORS; then
 ${msg} "${irt_showerror}"
else
 exec 2>/dev/null
fi

if $OPT_DEBUG; then
${msg} "${irt_start} ${irt_debugging}."
echo "#define DEBUG" >> src/iroffer_config.h
DEBUG="-g"
case "${cctype}" in
*cparser*)
 DEBUGFLAGS="
-Wchar-subscripts
-Wcomment
-Wendif-labels
-Wformat-security
-Wimplicit-int
-Wmain
-Wnested-externs
-Wnonnull
-Wparentheses
-Wredundant-decls
-Wreturn-type
-Wsystem-headers
-Wtrigraphs
-Wuninitialized -O
-Wunknown-pragmas
-Wunused
-Wunused-function
-Wunused-label
-Wunused-parameter
-Wunused-value
-Wunused-variable
"
 ;;
*)
 DEBUGFLAGS="
-Wchar-subscripts
-Wcomment
-Wendif-labels
-Wformat-security
-Wimplicit-int
-Winline
-Wmissing-braces
-Wmissing-format-attribute
-Wmain
-Wnested-externs
-Wnonnull
-Wparentheses
-Wredundant-decls
-Wreturn-type
-Wstrict-aliasing
-Wswitch
-Wsystem-headers
-Wtrigraphs
-Wuninitialized -O
-Wunknown-pragmas
-Wunused
-Wunused-function
-Wunused-label
-Wunused-parameter
-Wunused-value
-Wunused-variable
"
 ;;
esac
else
case "$CFLAGS" in
*-O*)
	;;
*)
	DEBUG="-O2"
	;;
esac
fi

if $OPT_WARN; then
${msg} "${irt_start} ${irt_extrawarnings}."
case "${cctype}" in
*cparser*)
 WARNS="-Wcast-qual
-Wformat
-Wimplicit
-Wmissing-prototypes
-Wmissing-noreturn
-Wpointer-arith
-Wreturn-type
-Wshadow
-Wsign-compare
-Wstrict-prototypes
-Wwrite-strings"
 ;;
*)
 WARNS="-Wbad-function-cast
-Wcast-qual
-Wformat
-Wimplicit
-Wmissing-declarations
-Wmissing-prototypes
-Wmissing-noreturn
-Wpointer-arith
-Wreturn-type
-Wshadow
-Wsign-compare
-Wstrict-prototypes
-Wwrite-strings"
 ;;
esac
fi

if $OPT_WARN2; then
${msg} "${irt_start} ${irt_pedantic}."
case "${cctype}" in
*cparser*)
 WARNS2="
-Wconversion
-Wfloat-equal
-Wpacked
-Wpadded
-Wswitch-default
-Wswitch-enum
-Wundef
-Wunreachable-code
"
        ;;
gcc4*)
 WARNS2="
-Wconversion
-Wc++-compat
-Wformat-nonliteral
-Wformat=2
-Wfloat-equal
-Wpacked
-Wpadded
-Wswitch-default
-Wswitch-enum
-Wundef
-Wunreachable-code
"
 ;;
*)
 WARNS2="
-Wconversion
-Wformat-nonliteral
-Wformat=2
-Wfloat-equal
-Wpacked
-Wpadded
-Wswitch-default
-Wswitch-enum
-Wundef
-Wunreachable-code
"
 ;;
esac
fi

if $OPT_PROF; then
 ${msg} "${irt_start} ${irt_profiling}."
 PROF="-pg"
fi

if $OPT_GEOIP; then
 ${msg} "${irt_start} GeoIP."
fi

if $OPT_CURL; then
 ${msg} "${irt_start} Curl."
fi

if ! $OPT_SSL; then
 ${msg} "${irt_configure} ${irt_without} SSL."
fi

if $OPT_TLS; then
 ${msg} "${irt_start} GNU TLS."
 OPT_SSL=false
fi

if $OPT_UPNP; then
 ${msg} "${irt_start} UPNP ${irt_with} lminiupnpc."
fi

if $OPT_NOHTTP; then
 ${msg} "${irt_configure} ${irt_without} HTTP Server."
 echo "#define WITHOUT_HTTP" >> src/iroffer_config.h
fi

if $OPT_NOADMIN; then
 ${msg} "${irt_configure} ${irt_without} HTTP Admin."
 echo "#define WITHOUT_HTTP_ADMIN" >> src/iroffer_config.h
fi

if $OPT_NOTELNET; then
 ${msg} "${irt_configure} ${irt_without} Telnet Server."
 echo "#define WITHOUT_TELNET" >> src/iroffer_config.h
fi

if $OPT_NOBLOWFISH; then
 ${msg} "${irt_configure} ${irt_without} ${irt_blowfish}."
 echo "#define WITHOUT_BLOWFISH" >> src/iroffer_config.h
fi

if $OPT_NOCHROOT; then
 ${msg} "${irt_configure} ${irt_without} ${irt_nochroot}."
 echo "#define NO_CHROOT" >> src/iroffer_config.h
fi

if $OPT_NOMEMSAVE; then
 ${msg} "${irt_configure} ${irt_without} ${irt_memory}."
 echo "#define WITHOUT_MEMSAVE" >> src/iroffer_config.h
fi

${msg} -n "${irt_checkfor} make... "
makebin="`type make | awk '{print $NF}'`"
gmakebin="`type gmake | awk '{print $NF}'`"
if [ -f "${makebin}" ]; then
 maketype="make"
 if [ -x "${makebin}" ]; then
  ${msg} "${irt_found} $maketype"
 else
  ${msg} "${irt_found} $maketype. ${irt_error} ${irt_noexec} $maketype"
  waserror
 fi
elif [ -f "${gmakebin}" ]; then
 maketype="gmake"
 if [ -x "${gmakebin}" ]; then
  ${msg} "${irt_found} $maketype"
 else
  ${msg} "${irt_found} $maketype. ${irt_error} ${irt_noexec} $maketype"
  waserror
 fi
else
 ${msg} "${irt_notfound}. ${irt_error} ${irt_nomake}"
 maketype="make"
 waserror
fi

${msg} -n "${irt_checkfor} gcc/cc... "
ccrun=`type $cctype | awk '{print $NF}'`
if [ -f "${ccrun}" ]; then
 if [ -x "${ccrun}" ]; then
  ${msg} "${irt_found} $cctype"
 else
  ${msg} "${irt_found} $cctype. ${irt_error} ${irt_noexec} $cctype"
  waserror
 fi
else
 cctype="cc"
 ccrun=`type $cctype | awk '{print $NF}'`
 if [ -f "${ccrun}" ]; then
  if [ -x "${ccrun}" ]; then
   ${msg} "${irt_found} $cctype"
  else
   ${msg} "${irt_found} $cctype. ${irt_error} ${irt_noexec} $cctype"
   waserror
  fi
 else
  ${msg} "${irt_notfound}. ${irt_error} ${irt_nocc}"
  cctype="gcc"
  waserror
 fi
fi

main1="
int
#ifdef __GNUC__
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
__attribute__ ((noreturn))
#endif
#endif
main (int argc, char **argv)
{
	(void)argc;
	(void)argv;
"

main2=" exit(0);
}"

main0="${main1}${main2}"

${msg} -n "${irt_seeingif} $cctype ${irt_works}... "
echo "
#include <stdlib.h>
${main0}" > config.temp.c
if $cctype -o config.temp $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_yes}"
else
 ${msg} " ${irt_error} $cctype ${irt_nowork}."
 waserror
fi

${msg} -n "${irt_seeingif} $cctype ${irt_accepts} '-Wall'... "
echo "
#include <stdlib.h>
${main0}" > config.temp.c
if $cctype -o config.temp -Wall $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_yes}"
 WARNS="-Wall $WARNS"
else
 ${msg} " ${irt_no}"
fi

${msg} -n "${irt_seeingif} $cctype ${irt_accepts} '-Werror'... "
echo "
#include <stdlib.h>
${main0}" > config.temp.c
if $cctype -o config.temp -Werror $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_yes}"
 WERROR="-Werror"
else
 ${msg} " ${irt_no}"
fi


${msg} -n "${irt_seeing16bit}... "
echo "
#include <stdlib.h>
#include <stdio.h>
${main1}
 printf(\"%d\", (int)sizeof( C_IR_INT16 ));
${main2}" > config.temp.c
if $cctype -o config.temp -DC_IR_INT16="short" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "2" ]; then
 echo "short"
 echo "typedef short ir_int16;" >> src/iroffer_config.h
 echo "typedef unsigned short ir_uint16;" >> src/iroffer_config.h
elif $cctype -o config.temp -DC_IR_INT16="int" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "2" ]; then
 echo "int"
 echo "typedef int ir_int16;" >> src/iroffer_config.h
 echo "typedef unsigned int ir_uint16;" >> src/iroffer_config.h
else
 ${msg} "${irt_unknown}. ${irt_error} ${irt_neither1} 'short' ${irt_neither2} 'int' ${irt_neither3}."
 waserror
fi


${msg} -n "${irt_seeing32bit}... "
echo "
#include <stdlib.h>
#include <stdio.h>
${main1}
 printf(\"%d\", (int)sizeof( C_IR_INT32 ));
${main2}" > config.temp.c
if $cctype -o config.temp -DC_IR_INT32="int" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "4" ]; then
 echo "int"
 echo "typedef int ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned int ir_uint32;" >> src/iroffer_config.h
elif $cctype -o config.temp -DC_IR_INT32="long" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "4" ]; then
 echo "long"
 echo "typedef long ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned long ir_uint32;" >> src/iroffer_config.h
elif $cctype -o config.temp -DC_IR_INT32="long long" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "4" ]; then
 echo "long long"
 echo "typedef long long ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned long long ir_uint32;" >> src/iroffer_config.h
elif $cctype -o config.temp -DC_IR_INT32="short" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "4" ]; then
 echo "short"
 echo "typedef short ir_int32;" >> src/iroffer_config.h
 echo "typedef unsigned short ir_uint32;" >> src/iroffer_config.h
else
 ${msg} "${irt_unknown}. ${irt_error} ${irt_neither1} 'short', 'int', 'long' ${irt_neither2} 'long long' ${irt_neither3}."
 waserror
fi

${msg} -n "${irt_seeing64bit}... "
echo "
#include <stdlib.h>
#include <stdio.h>
${main1}
 printf(\"%d\", (int)sizeof( C_IR_INT64 ));
${main2}" > config.temp.c
if $cctype -o config.temp -DC_IR_INT64="long" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "8" ]; then
 echo "long"
 echo "typedef long ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned long ir_uint64;" >> src/iroffer_config.h
elif $cctype -o config.temp -DC_IR_INT64="long long" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "8" ]; then
 echo "long long"
 echo "typedef long long ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned long long ir_uint64;" >> src/iroffer_config.h
elif $cctype -o config.temp -DC_IR_INT64="int" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "8" ]; then
 echo "int"
 echo "typedef int ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned int ir_uint64;" >> src/iroffer_config.h
elif $cctype -o config.temp -DC_IR_INT64="short" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "8" ]; then
 echo "short"
 echo "typedef short ir_int64;" >> src/iroffer_config.h
 echo "typedef unsigned short ir_uint64;" >> src/iroffer_config.h
else
 ${msg} "${irt_unknown}. ${irt_error} ${irt_neither1} 'short', 'int', 'long' ${irt_neither2} 'long long' ${irt_neither3}."
 waserror
fi

if [ "$ostype" = CYGWIN ]; then
 ${msg} -n "${irt_checkif} AF_INET6 ${irt_isdefined}... "
 echo "
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
${main1}
 printf(\"%d\", (int)AF_INET6);
${main2}" > config.temp.c
 if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_yes}"
 else
  ${msg} "${irt_noipv6}."
  echo "#define AF_INET6 23" >> src/iroffer_config.h
  CFLAGS="$CFLAGS -DUSE_IPV6=1"
 fi
fi

irheaders="
#include \"src/iroffer_config.h\"
#include \"src/iroffer_defines.h\"
#include \"src/iroffer_headers.h\"
#include \"src/iroffer_globals.h\"
"

irmain1="${irheaders}${main1}"

irmain0="${irmain1}${main2}"

${msg} -n "${irt_seeingif} ${irt_compiling} ${irt_works}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_yes}"
else
 ${msg} " ${irt_error} ${irt_nocompiling}."
 waserror
fi


${msg} -n "${irt_seeinghow} ${irt_large} FD_SETSIZE ${irt_is}... "
echo "${irheaders}
FD_SETSIZE
" > config.temp.c
if $cctype -o config.temp.p -E $WARNS $WERROR $CFLAGS config.temp.c; then
 setsize=`tail -2 config.temp.p |grep -v "config.temp"`
 setsize="${setsize%U}"
 echo -n " $setsize"

 if [ "$ostype" = CYGWIN -a $setsize -le 255 ]; then
   ${msg} ", ${irt_boosting} 255"
   echo "#define FD_SETSIZE 255" >> src/iroffer_config.h
 else
   echo
 fi
else
 ${msg} " ${irt_error} ${irt_novalue}."
 waserror
fi

${msg} -n "${irt_endianness}... "
echo "${irmain1}
 printf(\"%s\", (100 == ntohl(100)) ? \"big\" : \"little\");
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "big" ]; then
 ${msg} "${irt_endianbig}"
 echo "#define IR_ENDIAN_BIG" >> src/iroffer_config.h
elif [ "`./config.temp`" = "little" ]; then
 ${msg} "${irt_endianlittle}"
 echo "#define IR_ENDIAN_LITTLE" >> src/iroffer_config.h
else
 ${msg} "${irt_unknown}. ${irt_error}."
 waserror
fi


${msg} -n "${irt_seeingif} ${irt_largefile} ${irt_works}... "
echo "${irmain1}
 int fd;
 int array[ ((int)sizeof(off_t)) - 7 ];
 fd=open(\"foo\", O_RDWR | O_CREAT | ADDED_OPEN_FLAGS, CREAT_PERMISSIONS);
 lseek(fd, 2L, SEEK_SET);
 array[0] = 0;
 (void)array;
 close(fd);
${main2}" > config.temp.c
if $cctype -o config.temp -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_yes}"
 echo "#define _FILE_OFFSET_BITS 64" >> src/iroffer_config.h
 echo "#define _LARGEFILE_SOURCE" >> src/iroffer_config.h
else
 ${msg} "${irt_nolargefile}."
fi

${msg} -n "${irt_signedness} 'addrlen'... "
echo "${irmain1}
 int a=1; struct sockaddr_in b; SIGNEDSOCK int c;
 getsockname(a,(struct sockaddr *)&b,&c);
${main2}" > config.temp.c
if $cctype -o config.temp -DSIGNEDSOCK=signed $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "signed"
 echo "#define SIGNEDSOCK signed" >> src/iroffer_config.h
elif $cctype -o config.temp -DSIGNEDSOCK=unsigned $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "unsigned"
 echo "#define SIGNEDSOCK unsigned" >> src/iroffer_config.h
else
 ${msg} "${irt_unknown}. ${irt_error} ${irt_neither1} 'signed' ${irt_neither2} 'unsigned' ${irt_neither3}."
 echo "#define SIGNEDSOCK signed" >> src/iroffer_config.h
 waserror
fi


${msg} -n "${irt_seeinghow} ${irt_display_int64} printf... "
echo "${irmain1}
 ir_int64 a = 1000000000;
 a = a*10;
 printf(\"%\" LLPRINTFMT \"i\",a);
${main2}" > config.temp.c
if $cctype -o config.temp -DLLPRINTFMT=\"L\" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "10000000000" ]; then
 echo "L"
 echo "#define LLPRINTFMT \"L\"" >> src/iroffer_config.h
elif $cctype -o config.temp -DLLPRINTFMT=\"l\" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "10000000000" ]; then
 echo "l"
 echo "#define LLPRINTFMT \"l\"" >> src/iroffer_config.h
elif $cctype -o config.temp -DLLPRINTFMT=\"ll\" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "10000000000" ]; then
 echo "ll"
 echo "#define LLPRINTFMT \"ll\"" >> src/iroffer_config.h
else
 ${msg} "${irt_unknown}. ${irt_error} ${irt_neither1} 'll', 'l', ${irt_neither2} 'L' ${irt_neither3}."
 echo "#define LLPRINTFMT \"L\"" >> src/iroffer_config.h
 waserror
fi


${msg} -n "${irt_seeinghow} ${irt_display_time} printf... "
echo "${irmain1}
 time_t a = 1000000000;
 a = a*10;
 printf(\"%\" TTPRINTFMT, a);
${main2}" > config.temp.c
if $cctype -o config.temp -DTTPRINTFMT=\"Li\" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "10000000000" ]; then
 echo "Li"
 echo "#define TTPRINTFMT \"Li\"" >> src/iroffer_config.h
elif $cctype -o config.temp -DTTPRINTFMT=\"li\" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "10000000000" -o "`./config.temp`" = "1410065408" ]; then
 echo "li"
 echo "#define TTPRINTFMT \"li\"" >> src/iroffer_config.h
elif $cctype -o config.temp -DTTPRINTFMT=\"lli\" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "10000000000" ]; then
 echo "lli"
 echo "#define TTPRINTFMT \"lli\"" >> src/iroffer_config.h
elif $cctype -o config.temp -DTTPRINTFMT=\"i\" $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && [ "`./config.temp`" = "10000000000" -o "`./config.temp`" = "1410065408" ]; then
 echo "i"
 echo "#define TTPRINTFMT \"i\"" >> src/iroffer_config.h
else
 ${msg} "${irt_unknown}. ${irt_error} ${irt_neither1} 'Li', 'lli', 'li' ${irt_neither2} 'i' ${irt_neither3}."
 echo "#define TTPRINTFMT \"\"" >> src/iroffer_config.h
 waserror
fi


${msg} -n "${irt_checkfor} snprintf()... "
echo "${irmain1}
 char *s=0; snprintf(s,10,\"blah\");
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_found}"
else
 echo "#define NO_SNPRINTF" >> src/iroffer_config.h
 ${msg} "${irt_msssing1}, ${irt_msssing2}"
fi

${msg} -n "${irt_checkfor} strcasecmp()... "
echo "${irmain1}
 (void)strcasecmp(\"blah\",\"blah\");
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_found}"
else
 echo "#define NO_STRCASECMP" >> src/iroffer_config.h
 ${msg} "${irt_msssing1}, ${irt_msssing2}."
fi

${msg} -n "${irt_checkfor} strcasestr()... "
echo "${irmain1}
 (void)strcasestr(\"blah\",\"blah\");
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_found}"
else
 echo "#define NO_STRCASESTR" >> src/iroffer_config.h
 echo "#define strcasestr(a,b) strstr(a,b)" >> src/iroffer_config.h
 ${msg} "${irt_msssing1}, ${irt_msssing2}."
fi

${msg} -n "${irt_checkfor} strsignal()... "
echo "${irmain1}
 strsignal(1);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_found}"
else
 echo "#define NO_STRSIGNAL" >> src/iroffer_config.h
 ${msg} "${irt_msssing1}, ${irt_msssing2}."
fi

${msg} -n "${irt_seeingif} 'sys/mman.h' ${irt_exists}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp.o -c -DHAS_SYS_MMAN_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_SYS_MMAN_H" >> src/iroffer_config.h
 ${msg} "${irt_found}"
else
 ${msg} "${irt_notfound}"
fi

${msg} -n "${irt_seeingif} 'sys/sendfile.h' ${irt_exists}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp.o -c -DHAS_SYS_SENDFILE_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_SYS_SENDFILE_H" >> src/iroffer_config.h
 ${msg} "${irt_found}"
else
 ${msg} "${irt_notfound}"
fi

${msg} -n "${irt_seeingif} 'sys/vfs.h' ${irt_exists}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp.o -c -DHAS_SYS_VFS_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_SYS_VFS_H" >> src/iroffer_config.h
 ${msg} "${irt_found}"
else
 ${msg} "${irt_notfound}"
fi

${msg} -n "${irt_seeingif} 'sys/statfs.h' ${irt_exists}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp.o -c -DHAS_SYS_STATFS_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_SYS_STATFS_H" >> src/iroffer_config.h
 ${msg} "${irt_found}"
else
 ${msg} "${irt_notfound}"
fi

${msg} -n "${irt_seeingif} 'sys/param.h' ${irt_exists}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp.o -c -DHAS_SYS_PARAM_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_SYS_PARAM_H" >> src/iroffer_config.h
 ${msg} "${irt_found}"
else
 ${msg} "${irt_notfound}"
fi

${msg} -n "${irt_seeingif} 'sys/mount.h' ${irt_exists}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp.o -c -DHAS_SYS_MOUNT_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_SYS_MOUNT_H" >> src/iroffer_config.h
 ${msg} "${irt_found}"
else
 ${msg} "${irt_notfound}"
fi

${msg} -n "${irt_seeingif} 'sys/statvfs.h' ${irt_exists}... "
echo "${irmain0}" > config.temp.c
if $cctype -o config.temp.o -c -DHAS_SYS_STATVFS_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_SYS_STATVFS_H" >> src/iroffer_config.h
 ${msg} "${irt_found}"
else
 ${msg} "${irt_notfound}"
fi

${msg} -n "${irt_checkfor} statvfs()... "
echo "${irmain1}
 struct statvfs stf; statvfs(\"\",&stf);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_found}"
else
 echo "#define NO_STATVFS" >> src/iroffer_config.h
 ${msg} "${irt_msssing1}"
fi

${msg} -n "${irt_checkfor} statfs()... "
echo "${irmain1}
 struct statfs stf; statfs(\"\",&stf);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_found}"
else
 echo "#define NO_STATFS" >> src/iroffer_config.h
 ${msg} "${irt_msssing1}"
fi

${msg} -n "${irt_seeingif} 'crypt.h' ${irt_isneeded}... "
echo "${irmain1}
 crypt(\"aaaaaaaa\",\"aa\");
${main2}" > config.temp.c
if $cctype -o config.temp.o -c $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_notneeded}"
elif $cctype -o config.temp.o -c -DHAS_CRYPT_H $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
 echo "#define HAS_CRYPT_H" >> src/iroffer_config.h
 ${msg} "${irt_needed}"
else
 ${msg} "${irt_msssing1}. ${irt_error} ${irt_nocrypt}."
 echo "#define HAS_CRYPT_H" >> src/iroffer_config.h
 waserror
fi

${msg} -n "${irt_seeingif} '-lcrypt' ${irt_isneeded}... "
if $cctype -o config.temp config.temp.o $WARNS $WERROR $CFLAGS $LDFLAGS $libs $LIBS; then
 ${msg} "${irt_notneeded}"
elif $cctype -o config.temp config.temp.o -lcrypt $WARNS $WERROR $CFLAGS $LDFLAGS $libs $LIBS; then
 libs="$libs -lcrypt"
 ${msg} "${irt_needed}"
else
 ${msg} "${irt_neither4}!"
 ${msg} -n "${irt_seeingif} '-lcrypto' ${irt_worksinstead}... "
 if $cctype -o config.temp config.temp.o -lcrypto $WARNS $WERROR $CFLAGS $LDFLAGS $libs $LIBS; then
  libs="$libs -lcrypto"
  ${msg} "${irt_yes}"
 else
  ${msg} "${irt_msssing1}. ${irt_error} ${irt_nolcrypt}"
  libs="$libs -lcrypt"
  waserror
 fi
fi

${msg} -n "${irt_seeingif} crypt() ${irt_works} ${irt_asexpected}... "
echo "${irmain1}
 char *pwout;
 pwout = crypt(\"testtest\",\"LH\");
 if (pwout && !strcmp(\"LHD/pLKwfn0.k\", pwout)) {
   fputs(\"result: <plain> \", stderr);
   exit(0);
 }
 if (pwout && !strcmp(\"\$1\$LH\$l9z.KKYlyrg6tmiWYw85h0\", pwout)) {
   fputs(\"result: <md5> \", stderr);
   exit(0);
 }
 if (pwout && !strcmp(\"\$2a\$04\$L.....................6oC9YEWGQG17v9bdZ7bATu6dyyWPzMy\", pwout)) {
   fputs(\"result: <blf> \", stderr);
   exit(0);
 }
 fprintf(stderr, \"result: <unknown> hash = %s \", pwout);
 exit(1);
}
" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS && ./config.temp; then
 ${msg} "${irt_yes}"
else
 ${msg} "${irt_no}, ${irt_nopassword}."
 echo "#define NO_CRYPT" >> src/iroffer_config.h
fi

if ! $OPT_NOCHROOT; then
  ${msg} -n "${irt_checkfor} chroot()... "
  echo "${irmain1}
 (void)chroot(\".\");
${main2}" > config.temp.c
  if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
  else
    echo "#define NO_CHROOT" >> src/iroffer_config.h
    ${msg} "${irt_msssing1}, ${irt_nochroot}."
  fi
fi

if ! $OPT_NOCHROOT; then
  ${msg} -n "${irt_seeingif_lib} NSS ${irt_lib_exists} (${irt_for} chroot)... "
  echo "${irmain0}" > config.temp.c
  if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS -lnss_files -lnss_dns $libs $LIBS; then
    NSSLIBS="-lnss_files -lnss_dns"
    ${msg} "${irt_found}"
  else
    NSSLIBS=""
    ${msg} "${irt_msssing1}"
  fi
fi

${msg} -n "${irt_checkfor} setuid()... "
echo "${irmain1}
 setuid(0);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
else
echo "#define NO_SETUID" >> src/iroffer_config.h
${msg} "${irt_msssing1}, ${irt_nosetuid}."
fi

${msg} -n "${irt_checkfor} getgrouplist()... "
echo "${irmain1}
 getgrouplist (NULL, 0, NULL, NULL);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
else
echo "#define NO_GETGROUPLIST" >> src/iroffer_config.h
${msg} "${irt_msssing1}, ${irt_nogetgrouplist}."
fi

if [ "x$ostype" = "xLinux" ]; then
${msg} -n "${irt_checkfor} Linux-style sendfile()... "
echo "${irmain1}
 int     out_fd = 0;
 int     in_fd = 0;
 off_t   offset = 0;
 size_t  count = 0;
 ssize_t ret_val;
 ret_val = sendfile(out_fd, in_fd, &offset, count);
 (void)ret_val;
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
echo "#define HAVE_LINUX_SENDFILE" >> src/iroffer_config.h
${msg} "${irt_found}"
else
${msg} "${irt_msssing1}, ${irt_nosendfile}."
fi
fi

if [ "x$ostype" = "xFreeBSD" ]; then
${msg} -n "${irt_checkfor} FreeBSD-style sendfile()... "
echo "${irmain1}
 int     in_fd = 0;
 int     out_fd = 0;
 off_t   offset = 0;
 off_t   offset2 = 0;
 size_t  count = 0;
 struct sf_hdtr hdr = {};
 int ret_val;
 ret_val = sendfile(in_fd, out_fd, offset, count,
                    &hdr, &offset2, 0);
 (void)ret_val;
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
echo "#define HAVE_FREEBSD_SENDFILE" >> src/iroffer_config.h
${msg} "${irt_found}"
else
${msg} "${irt_msssing1}, ${irt_nosendfile}."
fi
fi

${msg} -n "${irt_checkfor} mmap()/munmap()... "
echo "${irmain1}
 mmap(NULL,0,PROT_READ,MAP_SHARED,0,0);
 munmap(NULL,0);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
echo "#define HAVE_MMAP" >> src/iroffer_config.h
${msg} "${irt_found}"
else
${msg} "${irt_msssing1}, ${irt_nommap}."
fi


${msg} -n "${irt_checkfor} ${irt_fdlimit}... "
echo "${irmain1}
 struct rlimit rlim;
 getrlimit(RLIMIT_NOFILE, &rlim);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
echo "RLIMIT_NOFILE"
else
echo "${irmain1}
 struct rlimit rlim;
 getrlimit(RLIMIT_OFILE, &rlim);
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
echo "RLIMIT_OFILE"
echo "#define USE_OFILE" >> src/iroffer_config.h
else
${msg} "${irt_unknown}. ${irt_error} ${irt_nofdlimit}."
waserror
fi
fi

${msg} -n "${irt_checkfor} siginfo_t/sa_sigaction... "
echo "${irmain1}
 siginfo_t si;
 struct sigaction sa;
 sa.sa_sigaction = NULL;
 si.si_code = 0;
 bzero(&si, sizeof(si));
 bzero(&sa, sizeof(sa));
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
else
echo "#define NO_SIGINFO" >> src/iroffer_config.h
${msg} "${irt_msssing1}, ${irt_nosignal}."
fi

${msg} -n "${irt_checkfor} 'si_code' ${irt_values}... "
echo "${irmain1}
 siginfo_t si;
 si.si_code = BUS_ADRALN;
 si.si_code = BUS_ADRERR;
 si.si_code = BUS_OBJERR;
 si.si_code = ILL_ILLOPC;
 si.si_code = ILL_ILLOPN;
 si.si_code = ILL_ILLADR;
 si.si_code = ILL_ILLTRP;
 si.si_code = ILL_PRVOPC;
 si.si_code = ILL_PRVREG;
 si.si_code = ILL_COPROC;
 si.si_code = ILL_BADSTK;
 si.si_code = FPE_INTDIV;
 si.si_code = FPE_INTOVF;
 si.si_code = FPE_FLTDIV;
 si.si_code = FPE_FLTOVF;
 si.si_code = FPE_FLTUND;
 si.si_code = FPE_FLTRES;
 si.si_code = FPE_FLTINV;
 si.si_code = FPE_FLTSUB;
 si.si_code = SEGV_MAPERR;
 si.si_code = SEGV_ACCERR;
 bzero(&si, sizeof(si));
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
else
echo "#define NO_SIGCODES" >> src/iroffer_config.h
${msg} "${irt_msssing1}, ${irt_nosi_code}."
fi

${msg} -n "${irt_checkfor} wait() status ${irt_values}... "
echo "${irmain1}
 int status = 0;
 if (WIFEXITED(status) ||
     WIFSIGNALED(status) ||
     WEXITSTATUS(status) ||
     WTERMSIG(status)) {
  (void)status;
 }
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
else
echo "#define NO_WSTATUS_CODES" >> src/iroffer_config.h
${msg} "${irt_msssing1}, ${irt_nowait}."
fi


${msg} -n "${irt_seeingif} ${irt_tos}... "
echo "${irmain1}
 int fd = 0;
 int tempc = 0x8; /* IPTOS_THROUGHPUT */
 setsockopt(fd, IPPROTO_IP, IP_TOS, &tempc, sizeof(int));
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_yes}"
else
echo "#define CANT_SET_TOS" >> src/iroffer_config.h
${msg} "${irt_no}"
fi

${msg} -n "${irt_checkfor} getaddrinfo()... "
echo "${irmain1}
 struct addrinfo hints, *res0;
 int error;

 memset(&hints, 0, sizeof(hints));
 hints.ai_family = PF_UNSPEC;
 hints.ai_socktype = SOCK_STREAM;
 error = getaddrinfo(\"www.kame.net\", \"http\", &hints, &res0);
 (void)error;
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
else
echo "#define NO_GETADDRINFO" >> src/iroffer_config.h
${msg} "${irt_msssing1}, ${irt_nogetaddrinfo}."
fi

${msg} -n "${irt_checkfor} gethostbyname() error ${irt_values}... "
echo "${irmain1}
 int i;
 switch (h_errno) {
 case HOST_NOT_FOUND:
 case NO_ADDRESS:
#if NO_ADDRESS != NO_DATA
 case NO_DATA:
#endif
 case NO_RECOVERY:
 case TRY_AGAIN:
  i = 1;
  break;
 default:
  i = 0;
 }
 exit(i);
}
" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
else
echo "#define NO_HOSTCODES" >> src/iroffer_config.h
${msg} "${irt_msssing1}, ${irt_nogethostbyname}."
fi

${msg} -n "${irt_checkfor} res_init() ... "
echo "${irheaders}
#include <resolv.h>
${main1}
  res_init();
${main2}" > config.temp.c
if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
${msg} "${irt_found}"
echo "#define WITH_RESINIT" >> src/iroffer_config.h
else
${msg} "${irt_msssing1}, ${irt_nores_init}."
fi

if $OPT_KQUEUE; then
 ${msg} -n "${irt_checkfor} kqueue() ... "
 echo "${irheaders}
#include <sys/event.h>
int ir_kqueue_fd;
${main1}
 ir_kqueue_fd = kqueue ();
${main2}" > config.temp.c
 if $cctype -o config.temp $WARNS $WERROR $CFLAGS config.temp.c $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  echo "#define USE_KQUEUE" >> src/iroffer_config.h
 else
  ${msg} "${irt_msssing1}, ${irt_no_kqueue}."
 fi
fi

if $OPT_GEOIP; then
 ${msg} -n "${irt_seeingif_lib} GeoIP2 ${irt_lib_exists}... "
 echo "${irheaders}
#include <maxminddb.h>
${main1}
 MMDB_open(NULL, MMDB_MODE_MMAP, NULL);
${main2}" > config.temp.c
 if $cctype -o config.temp -DUSE_MAXMINDDB $WARNS $WERROR $CFLAGS "-I${LOCALBASE}/include" config.temp.c "-L${LOCALBASE}/lib" -lmaxminddb $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  echo "#define USE_MAXMINDDB" >> src/iroffer_config.h
  FEATURES="${FEATURES},geoip2"
  MAXMINDDBLIB="-lmaxminddb"
  MAXMINDDBINC="-I${LOCALBASE}/include"
  MAXMINDDBLDF="-L${LOCALBASE}/lib"
 fi
fi

if $OPT_GEOIP; then
 ${msg} -n "${irt_seeingif_lib} GeoIP ${irt_lib_exists}... "
 echo "${irheaders}
#include <GeoIP.h>
${main1}
 GeoIP_country_code_by_addr(NULL, NULL);
${main2}" > config.temp.c
 if $cctype -o config.temp -DUSE_GEOIP $WARNS $WERROR $CFLAGS "-I${LOCALBASE}/include" config.temp.c "-L${LOCALBASE}/lib" -lGeoIP $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  echo "#define USE_GEOIP" >> src/iroffer_config.h
  FEATURES="${FEATURES},geoip"
  GEOLIB="-lGeoIP"
  GEOINC="-I${LOCALBASE}/include"
  GEOLDF="-L${LOCALBASE}/lib"
  ${msg} -n "${irt_seeingif} ${irt_geoip6}... "
  echo "${irheaders}
#include <GeoIP.h>
${main1}
 struct in6_addr remoteip; inet_pton(AF_INET6, 0, &remoteip); GeoIP_country_code_by_ipnum_v6(NULL, remoteip);
${main2}" > config.temp.c
  if $cctype -o config.temp -DUSE_GEOIP6 $WARNS $WERROR $CFLAGS ${GEOINC} config.temp.c ${GEOLDF} ${GEOLIB} $LDFLAGS $libs $LIBS; then
   FEATURES="${FEATURES}6"
   ${msg} "${irt_found}"
   echo "#define USE_GEOIP6" >> src/iroffer_config.h
  else
   ${msg} "${irt_notfound}"
   ${msg} "***${irt_nogeoip6}.***"
  fi
 else
  ${msg} "${irt_notfound}"
  ${msg} "***${irt_nogeoip}.***"
 fi
fi

if $OPT_UPNP; then
 ${msg} -n "${irt_seeingif_lib} miniupnpc ${irt_lib_exists}... "
 echo "${irheaders}
#include <miniupnpc/miniwget.h>
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/upnpcommands.h>
${main1}
#if MINIUPNPC_API_VERSION >= 14
 upnpDiscover(2000, NULL, NULL, 0, 0, 2U, NULL);
#else
#ifdef UPNPDISCOVER_SUCCESS
 upnpDiscover(2000, NULL, NULL, 0, 0, NULL);
#else
 upnpDiscover(2000, NULL, NULL, 0);
#endif /* UPNPDISCOVER_SUCCESS */
#endif
${main2}" > config.temp.c
 if $cctype -o config.temp -DUSE_UPNP $WARNS $WERROR $CFLAGS "-I${LOCALBASE}/include" config.temp.c "-L${LOCALBASE}/lib" -lminiupnpc $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  echo "#define USE_UPNP" >> src/iroffer_config.h
  FEATURES="${FEATURES},upnp"
  UPNPLIB="-lminiupnpc"
  UPNPINC="-I${LOCALBASE}/include"
  UPNPLDF="-L${LOCALBASE}/lib"
 else
  ${msg} "${irt_notfound}"
  ${msg} "***${irt_noupnp}.***"
 fi
fi

if $OPT_CURL; then
 ${msg} -n "${irt_seeingif_lib} libcurl ${irt_lib_exists} (${irt_for} FETCH-Command)... "
 echo "${irheaders}
#include <curl/curl.h>
${main1}
 curl_global_cleanup();
${main2}" > config.temp.c
 if $cctype -o config.temp -DUSE_CURL $WARNS $CFLAGS `curl-config  --cflags` config.temp.c "-L${LOCALBASE}/lib" `curl-config  --libs` $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  echo "#define USE_CURL" >> src/iroffer_config.h
  FEATURES="${FEATURES},curl"
  CURLLIB=`curl-config  --libs`
  CURLINC=`curl-config  --cflags`
  CURLLDF="-L${LOCALBASE}/lib"
  CURLSLIB=`curl-config --static-libs`
  curlssl=`ldd config.temp | grep libssl`
  if test "${curlssl}" != ""; then
   ${msg} "${irt_curlssl} OpenSSL."
  else
   curltls=`ldd config.temp | grep libgnutls`
   if test "${curltls}" != ""; then
    ${msg} "${irt_curlssl} GNU TLS."
   fi
  fi
 else
  ${msg} "${irt_notfound}"
  ${msg} "***${irt_nocurl}.***"
 fi
fi

if $OPT_SSL; then
 ${msg} -n "${irt_seeingif_lib} OpenSSL ${irt_lib_exists}... "
 echo "${irmain0}" > config.temp.c
 if $cctype -o config.temp -DUSE_OPENSSL $WARNS $CFLAGS "-I${LOCALBASE}/include" config.temp.c "-L${LOCALBASE}/lib" -lssl -lcrypto $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  ${msg} "${irt_start} OpenSSL."
  echo "#define USE_OPENSSL" >> src/iroffer_config.h
  FEATURES="${FEATURES},openssl"
  SSLLIB="-lssl -lcrypto"
  SSLINC="-I${LOCALBASE}/include"
  SSLLDF="-L${LOCALBASE}/lib"
 else
  ${msg} "${irt_notfound}"
  ${msg} "***${irt_nossl}."
 fi
 if test "${curltls}" != ""; then
  ${msg} "*** ${irt_badssl1} 'GNU TLS', ${irt_badssl2} '-tls'"
  waserror
 fi
fi


if $OPT_TLS; then
 ${msg} -n "${irt_seeingif_lib} GNU TLS ${irt_lib_exists}... "
 echo "${irmain0}" > config.temp.c
 if $cctype -o config.temp -DUSE_GNUTLS $WARNS $CFLAGS "-I${LOCALBASE}/include" config.temp.c "-L${LOCALBASE}/lib" -lgnutls $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  echo "#define USE_GNUTLS" >> src/iroffer_config.h
  FEATURES="${FEATURES},gnutls"
  SSLLIB="-lgnutls"
  SSLINC="-I${LOCALBASE}/include"
  SSLLDF="-L${LOCALBASE}/lib"
 else
  ${msg} "${irt_notfound}"
  ${msg} "***${irt_notls}."
 fi
 if test "${curlssl}" != ""; then
  ${msg} "*** ${irt_badssl1} 'OpenSSL', ${irt_badssl3} '-tls'."
  waserror
 fi
fi

if $OPT_WARN; then
WERROR2=$WERROR
fi

if $OPT_RUBY; then
 rubyldf=`${ruby} -r rbconfig -e "print RbConfig::CONFIG[ 'LIBS' ]"`
 libruby=`${ruby} -r rbconfig -e "print RbConfig::CONFIG[ 'LIBRUBYARG_SHARED' ]"`
 libsruby=`${ruby} -r rbconfig -e "print RbConfig::CONFIG[ 'LIBRUBYARG_STATIC' ]"`
 archdir=`${ruby} -r rbconfig -e "print RbConfig::CONFIG[ 'archdir' ]"`
 rubyhdrdir=`${ruby} -r rbconfig -e "print RbConfig::CONFIG[ 'rubyhdrdir' ]"`
 sitearch=`${ruby} -r rbconfig -e "print RbConfig::CONFIG[ 'sitearch' ]"`
 rubyarchhdrdir=`${ruby} -r rbconfig -e "print RbConfig::CONFIG[ 'rubyarchhdrdir' ]"`
 rubyversion=`${ruby} -e "print RUBY_VERSION.sub(/\.[0-9]*$/,'').sub(/\./,'')"`
 if test "${rubyhdrdir}" = "nil"
 then
  incruby="-I${archdir}"
 else
  incruby="-I${rubyhdrdir} -I${rubyhdrdir}/${sitearch} -I${rubyarchhdrdir}"
 fi
 ${msg} -n "${irt_seeingif_lib} libruby ${irt_lib_exists} (${irt_for} RUBY-Scripts)... "
 echo "
#include \"ruby.h\"
${main1}
 ruby_init(); ruby_finalize();
${main2}" > config.temp.c
 if $cctype -o config.temp -DUSE_RUBY $WARNS $CFLAGS ${incruby} config.temp.c ${libruby} ${rubyldf} $LDFLAGS $libs $LIBS; then
  ${msg} "${irt_found}"
  ${msg} "${irt_start} Ruby."
  echo "#define USE_RUBY" >> src/iroffer_config.h
  echo "#define USE_RUBYVERSION ${rubyversion}" >> src/iroffer_config.h
  FEATURES="${FEATURES},ruby"
  RUBYLIB="${libruby} ${rubyldf}"
  RUBYSLIB="${libsruby} ${rubyldf} $rstatic"
  RUBYINC="${incruby}"
  RUBYLDF="-L${LOCALBASE}/lib"
  WERROR2=""
 else
  ${msg} "${irt_notfound}"
  ${msg} "***${irt_noruby}.***"
 fi
fi

rm -f config.temp*

if test "${FEATURES}" != ""; then
 FEATURES=" - ${FEATURES#,}"
fi
echo "#define FEATURES \"${FEATURES}\"" >> src/iroffer_config.h
${msg} "${irt_creating} src/iroffer_config.h... ${irt_done}"

${msg} -n "${irt_creating} Makefile... "

modules="iroffer_admin iroffer_dccchat iroffer_display iroffer_main \
 iroffer_misc iroffer_statefile iroffer_transfer iroffer_upload \
 plumb_md5 dinoex_admin dinoex_main dinoex_misc dinoex_http \
 dinoex_upload dinoex_transfer dinoex_geoip dinoex_maxminddb dinoex_ssl \
 dinoex_curl dinoex_irc dinoex_queue dinoex_telnet dinoex_badip \
 dinoex_jobs dinoex_kqueue dinoex_ruby dinoex_user dinoex_chat \
 dinoex_config crc32 upnp blowfish strnatcmp iroffer_utilities \
 dinoex_utilities"

make_srclist()
{
 for c in ${modules}
 do
  c="src/${c}.c"
  echo "		${c} \\"
 done
 echo "		-all-comments -index-all -xref-all -Ocxref $1\\"
 echo "		-Niroffer \$(CPPFLAGS)"
}

make_makefile()
{
 ${msg} "# ${irt_noedit} #"
 echo
 echo VERSION=$VERSION
 echo CC=$cctype
 echo CONFIG_EXE=$exe
 echo CONFIG_LDLIBS=$GEOLIB $MAXMINDDBLIB $CURLLIB $UPNPLIB $SSLLIB $libs $LIBS
 echo CONFIG_LDFLAGS=$PROF $DEBUG $SSLLDF $GEOLDF $MAXMINDDBLDF $CURLLDF $UPNPLDF $RUBYLDF $LDFLAGS
 echo CONFIG_CFLAGS=$PROF $DEBUG $DEBUGFLAGS $WERROR2 $WARNS $WARNS2 $CFLAGS
 echo CONFIG_CPPFLAGS=$SSLINC $GEOINC $MAXMINDDBINC $CURLINC $UPNPINC $RUBYINC $CPPFLAGS
 echo CONFIG_CHROOT=$NSSLIBS
 echo CONFIG_SHARED=$RUBYLIB
 echo CONFIG_STATIC=$RUBYSLIB $CURLSLIB $SLDFLAGS -static
 echo INSTALL_GROUP=$installgroup
 echo INSDIR?=$PREFIX/bin
 echo IRLANG?=en
 echo IRSRC?=src
 echo IRNAME?=iroffer
 if $OPT_STATIC; then
   echo "TARGET_STATIC=\$(IRNAME)_static\$(CONFIG_EXE)"
 fi
 if test -n "$NSSLIBS"; then
   echo "TARGET_CHROOT=\$(IRNAME)_chroot\$(CONFIG_EXE)"
 fi
 echo 'OBJDIR = o.$(IRLANG)/.mkdir'
 echo
 echo "IROFFER_OBJECTS= \\"
 for c in ${modules}
 do
  echo "	o.\$(IRLANG)/${c}.o \\"
 done
 echo
 echo "HEADERS= \\"
 for h in src/*.h
 do
  h="${h#src/}"
  echo "	\$(IRSRC)/${h} \\"
 done
 echo "	Makefile"
 echo
 echo '
LDLIBS    = $(CONFIG_LDLIBS)
LDFLAGS   = $(CONFIG_LDFLAGS)
CFLAGS    = $(CONFIG_CFLAGS)
CPPFLAGS  = -I$(IRSRC) $(CONFIG_CPPFLAGS)
'
 echo 'all: $(IRNAME)$(CONFIG_EXE) $(TARGET_STATIC) $(TARGET_CHROOT) $(OBJDIR)'
 echo '
$(IRNAME)$(CONFIG_EXE): $(OBJDIR) $(IROFFER_OBJECTS)
	$(CC) $(LDFLAGS) $(IROFFER_OBJECTS) $(LOADLIBES) $(LDLIBS) $(CONFIG_SHARED) -o $(IRNAME)

$(IRNAME)_chroot$(CONFIG_EXE): $(OBJDIR) $(IROFFER_OBJECTS)
	$(CC) $(LDFLAGS) $(IROFFER_OBJECTS) $(LOADLIBES) $(LDLIBS) $(CONFIG_SHARED) $(CONFIG_CHROOT) -o $(IRNAME)_chroot

$(IRNAME)_static$(CONFIG_EXE): $(OBJDIR) $(IROFFER_OBJECTS)
	$(CC) $(LDFLAGS) $(IROFFER_OBJECTS) $(LOADLIBES) $(LDLIBS) $(CONFIG_STATIC) -o $(IRNAME)_static

obj: $(OBJDIR)

$(OBJDIR):
	mkdir -p o.$(IRLANG)
	touch $(OBJDIR)
'
 for c in ${modules}
 do
  o="o.\$(IRLANG)/${c}.o"
  c="\$(IRSRC)/${c}.c"
  case ${c} in
  */iroffer_statefile.c)
   echo "${o}: ${c} \$(HEADERS) \$(OBJDIR) \$(IRSRC)/dinoex_statefile.c"
   echo "	\$(CC) -c \$(CPPFLAGS) \$(CFLAGS) -o ${o} ${c}"
   ;;
  *)
   echo "${o}: ${c} \$(HEADERS) \$(OBJDIR)"
   echo "	\$(CC) -c \$(CPPFLAGS) \$(CFLAGS) -o ${o} ${c}"
   ;;
  esac
 done
 echo "
src-doc:
	rm -rf cxref
	mkdir -p cxref
	cxref -CPP \${CC} \\"
 make_srclist
 echo "	cxref -CPP \${CC} \\"
 make_srclist "-html "
 echo "	ln -s iroffer.html cxref/index.html"
 echo '

cleanobj:
	rm -rf obj o.* $(IRNAME) $(IRNAME).exe \
		$(IRNAME)_static $(IRNAME)_static.exe \
		$(IRNAME)_chroot $(IRNAME)_chroot.exe \

clean: cleanobj
	$(MAKE) IRNAME=iroffer-de cleanobj
	$(MAKE) IRNAME=iroffer-it cleanobj
	$(MAKE) IRNAME=iroffer-fr cleanobj

clobber: clean
	rm -rf src.* *.sed

'
 for html in doc/INSTALL-*.html
 do
    txt="${html%.html}.txt"
    echo "${txt}: ${html}
	lynx ${lynxopt} ${html} > ${txt}
"
 done
 echo '

man:
	groff -t -e -mandoc -Tascii iroffer.1

doc:	\'
 for html in doc/INSTALL-*.html
 do
    txt="${html%.html}.txt"
    echo "	${txt} \\"
 done
 for man in iroffer.1 xdcc.7
 do
    echo "	doc/${man}.txt \\"
    echo "	doc/${man}.ps \\"
    echo "	doc/${man}.html \\"
 done
 for man in iroffer.1 xdcc.7
 do
   echo "

doc/${man}.html: ${man}
	groff -t -e -mandoc -Thtml ${man} > doc/${man}.html

doc/${man}.txt: ${man}
	groff -t -e -mandoc -Tascii ${man} > doc/${man}.txt

doc/${man}.ps: ${man}
	groff -t -e -mandoc -Tps ${man} > doc/${man}.ps
"
 done
 echo '

install: all
	if test ! -d $(DESTDIR)$(INSDIR) ; then mkdir -p $(DESTDIR)$(INSDIR); fi
	install -o root -g $(INSTALL_GROUP) -m 0755 $(IRNAME)$(CONFIG_EXE) $(DESTDIR)$(INSDIR)/$(IRNAME)$(CONFIG_EXE)

installuser: all
	install -m 0755 $(IRNAME)$(CONFIG_EXE) $(DESTDIR)$(INSDIR)/$(IRNAME)$(CONFIG_EXE)

uninstall:
	rm $(DESTDIR)$(INSDIR)/$(IRNAME)$(CONFIG_EXE)

en:	all

install-en: install

'
 allbuild="en"
 allinstall="install-en"
 for l in ${TRANSLATION}
 do
  allbuild="${allbuild} ${l}"
  allinstall="${allinstall} install-${l}"
  echo "${l}:"
  echo "	./Lang ${l}"
  echo "	\$(MAKE) IRLANG=${l} IRSRC=src.${l} IRNAME=iroffer-${l} all"
  echo
  echo "install-${l}: ${l}"
  echo "	\$(MAKE) IRLANG=${l} IRSRC=src.${l} IRNAME=iroffer-${l} install"
  echo
 done
 echo "
all-lang:	${allbuild}

install-all-lang: ${allinstall}

# end"
}

make_makefile > Makefile

${msg} "${irt_done}"
echo
case "${LANG}" in
de*)
 ${msg} "${irt_make1} \"$maketype de\" ${irt_make2}"
  ;;
fr*)
 ${msg} "${irt_make1} \"$maketype fr\" ${irt_make2}"
  ;;
it*)
 ${msg} "${irt_make1} \"$maketype it\" ${irt_make2}"
  ;;
*)
 ${msg} "${irt_make1} \"$maketype\" ${irt_make2}"
  ;;
esac
${msg} "${irt_noerror}"
echo

# end
