:

########################################################################
. ./config.dat
if [ "Z$LCRZODIR" = "Z" ] ; then
  lcrzoisinstalled=1
  lcrzoconfig="lcrzo-config"
  lcrzoconfigc="\`lcrzo-config -c\`"
  lcrzoconfigl="\`lcrzo-config -l\`"
  echo "Info: ./config.dat does not contain LCRZODIR. This is normal if you installed lcrzo."
  echo "Info: ./config.dat ne contient pas LCRZODIR. C'est normal si vous avez installe lcrzo."
else
  lcrzoisinstalled=0
  LCRZOSRC=../$LCRZODIR/src/
  lcrzoconfig="$LCRZOSRC/lcrzo-config"
  lcrzoconfigc="\`$LCRZOSRC/lcrzo-config -c\` -I$LCRZOSRC"
  lcrzoconfigl="\`$LCRZOSRC/lcrzo-config -l\` -L$LCRZOSRC"
  echo "Info: LCRZODIR in ./config.dat indicates lcrzo.h and liblcrzo.a are in $LCRZOSRC"
  echo "Info: LCRZODIR de ./config.dat indique que lcrzo.h et liblcrzo.a sont dans $LCRZOSRC"
fi

########################################################################
# check if lcrzo is installed

if [ "Z$lcrzoisinstalled" = "Z1" ] ; then
  type lcrzo-config 2> /dev/null 1> /dev/null
  if [ "$?Z" != "0Z" ] ; then
    echo "Error: lcrzo-config wasn't found in the PATH($PATH). Did you install lcrzo ?"
    echo "Error: lcrzo-config n'a pas ete trouve dans le PATH($PATH). Avez-vous installe lcrzo ?"
    exit
  fi
else
  type $LCRZOSRC/lcrzo-config 2> /dev/null 1> /dev/null
  if [ "$?Z" != "0Z" ] ; then
    echo "Error: lcrzo-config wasn't found in $LCRZOSRC"
    echo "Erreur: lcrzo-config n'a pas ete trouve dans $LCRZOSRC"
    exit
  fi
fi


########################################################################
echo "Version"

LCRZODEF_VERSION=`$lcrzoconfig --version`
echo " Lcrzo version ${LCRZODEF_VERSION}"

# check if this version is obsolete
$lcrzoconfig --define VERSIONMAJOR 2> /dev/null 1> /dev/null
if [ "$?Z" != "0Z" ] ; then
    echo "Error: this version of lcrzo is too old. Please install a new one."
    echo "Erreur: cette version de lcrzo est trop vieille. Merci d'installer une recente."
  exit
fi

# set correct language
LCRZODEF_LANG=`$lcrzoconfig --define LANG`
if [ $LCRZODEF_LANG = 1 ] ; then
  toto=0
elif [ $LCRZODEF_LANG = 2 ] ; then
  toto=0
else
  echo "Warning : Unknown language : verify LCRZODEF_LANG"
  LCRZODEF_LANG=1
fi

# check if this version is sufficient to compile lcrzoex
LCRZODEF_VERSIONMAJOR=`$lcrzoconfig --define VERSIONMAJOR`
LCRZODEF_VERSIONMINOR=`$lcrzoconfig --define VERSIONMINOR`
# obtain the needed version
. ./version.sh
echo " Lcrzoex version ${LCRZOEXDEF_VERSION} (${LCRZOEXDEF_VERSIONMAJOR} ${LCRZOEXDEF_VERSIONMINOR})"
versioncorrespond=1
if test $LCRZODEF_VERSIONMAJOR != $LCRZOEXDEF_VERSIONMAJOR ; then
  versioncorrespond=0
fi
if test $LCRZODEF_VERSIONMINOR != $LCRZOEXDEF_VERSIONMINOR ; then
  versioncorrespond=0
fi
if test $versioncorrespond -ne 1; then
  if [ $LCRZODEF_LANG = 1 ] ; then
    echo "Those versions do not correspond. You might encounter problems while compiling or running lcrzoex."
    echo "Press ENTER to continue."
  else
    echo "Ces versions ne correspondent pas. Vous risquez de rencontrer des problemes a la compilation ou a l'execution."
    echo "Pressez la touche ENTREE pour continuer."
  fi
  read toto
fi


########################################################################
if [ $LCRZODEF_LANG = 1 ] ; then
  echo "Set variables"
elif [ $LCRZODEF_LANG = 2 ] ; then
  echo "Affecte les variables"
fi
LCRZODEF_PROGCC=`$lcrzoconfig --define PROGCC`
LCRZODEF_PROGAR=`$lcrzoconfig --define PROGAR`
LCRZODEF_PROGRANLIB=`$lcrzoconfig --define PROGRANLIB`
if [ "Z$lcrzoisinstalled" = "Z1" ] ; then
  LCRZODEF_INSTINCLUDE=`lcrzo-config --define INSTINCLUDE`
  LCRZODEF_INSTLIB=`lcrzo-config --define INSTLIB`
else
  LCRZODEF_INSTINCLUDE=$LCRZOSRC
  LCRZODEF_INSTLIB=$LCRZOSRC
fi
LCRZODEF_INSTBIN=`$lcrzoconfig --define INSTBIN`
LCRZODEF_INSTMAN1=`$lcrzoconfig --define INSTMAN1`
LCRZODEF_INSTUSERGROUP=`$lcrzoconfig --define INSTUSERGROUP`
gccOpt="-Wall -ansi"


########################################################################
if [ $LCRZODEF_LANG = 1 ] ; then
  echo "Creation of lcrzoex_defs.h"
elif [ $LCRZODEF_LANG = 2 ] ; then
  echo "Creation de lcrzoex_defs.h"
fi
echo "#define LCRZOEXDEF_VERSION \"$LCRZOEXDEF_VERSION\"" > lcrzoex_defs.h
echo "#define LCRZOEXDEF_VERSIONMAJOR $LCRZOEXDEF_VERSIONMAJOR" >> lcrzoex_defs.h
echo "#define LCRZOEXDEF_VERSIONMINOR $LCRZOEXDEF_VERSIONMINOR" >> lcrzoex_defs.h


#########
# special end ; you should not use
if [ "$1." = "test." ] ; then
  return
fi


########################################################################
if [ $LCRZODEF_LANG = 1 ] ; then
  echo "Creation of makefile"
elif [ $LCRZODEF_LANG = 2 ] ; then
  echo "Creation du makefile"
fi
ss="shared/shared"
cat > ./Makefile <<EOF
#----------------------------------------------------------------------
# This file was generated with ./genemake
# Ce fichier a ete genere avec ./genemake

#----------------------------------------------------------------------
# variables modifiables
CC=$LCRZODEF_PROGCC
AR=$LCRZODEF_PROGAR
RANLIB=$LCRZODEF_PROGRANLIB
INSTINCLUDE=$LCRZODEF_INSTINCLUDE
INSTLIB=$LCRZODEF_INSTLIB
INSTBIN=$LCRZODEF_INSTBIN
INSTMAN1=$LCRZODEF_INSTMAN1

GCCOPTa=-g -O -Wtraditional -pedantic -W
GCCOPTb=-Wshadow -Wpointer-arith -Wid-clash-48 -Wundef -Wsign-compare
GCCOPTc=-Wwrite-strings -Wcast-align -Wstrict-prototypes -Wcast-qual
GCCOPTd=-Wnested-externs
GCCOPTe=-Wbad-function-cast
GCCOPTf=-Werror

GCCOPTx=\$(GCCOPTa) \$(GCCOPTb) \$(GCCOPTc) \$(GCCOPTd) \$(GCCOPTe) \$(GCCOPTf)
GCCOPTz=-Wmissing-prototypes -Wmissing-declarations

#GCCOPT=$gccOpt \$(GCCOPTx) \$(GCCOPTz)
GCCOPT=$gccOpt

#----------------------------------------------------------------------
# we want only lcrzoex - on veut lcrzoex
all: lcrzoex

# shared objects
SHOBa=${ss}_conffile.o ${ss}_ftp.o ${ss}_dns.o ${ss}_http.o 
SHOBb=${ss}_lcrzoex.o ${ss}_md5.o ${ss}_misc.o ${ss}_nntp.o 
SHOBc=${ss}_para.o ${ss}_record.o ${ss}_router.o ${ss}_smtp.o 
SHOBd=${ss}_sniff.o ${ss}_sock.o ${ss}_syslog.o ${ss}_telnet.o
SHOBe=${ss}_toolbox.o
SHOB=\$(SHOBa) \$(SHOBb) \$(SHOBc) \$(SHOBd) \$(SHOBe)
${ss}_conffile.o: ${ss}_conffile.h ${ss}_conffile.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_conffile.c -o ${ss}_conffile.o
${ss}_ftp.o: ${ss}_ftp.h ${ss}_ftp.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_ftp.c -o ${ss}_ftp.o
${ss}_dns.o: ${ss}_dns.h ${ss}_dns.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_dns.c -o ${ss}_dns.o
${ss}_http.o: ${ss}_http.h ${ss}_http.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_http.c -o ${ss}_http.o
${ss}_md5.o: ${ss}_md5.h ${ss}_md5.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_md5.c -o ${ss}_md5.o
${ss}_misc.o: ${ss}_misc.h ${ss}_misc.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_misc.c -o ${ss}_misc.o
${ss}_lcrzoex.o: ${ss}_lcrzoex.h ${ss}_lcrzoex.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_lcrzoex.c -o ${ss}_lcrzoex.o
${ss}_nntp.o: ${ss}_nntp.h ${ss}_nntp.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_nntp.c -o ${ss}_nntp.o
${ss}_para.o: ${ss}_para.h ${ss}_para.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_para.c -o ${ss}_para.o
${ss}_record.o: ${ss}_record.h ${ss}_record.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_record.c -o ${ss}_record.o
${ss}_router.o: ${ss}_router.h ${ss}_router.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_router.c -o ${ss}_router.o
${ss}_smtp.o: ${ss}_smtp.h ${ss}_smtp.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_smtp.c -o ${ss}_smtp.o
${ss}_sniff.o: ${ss}_sniff.h ${ss}_sniff.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_sniff.c -o ${ss}_sniff.o
${ss}_sock.o: ${ss}_sock.h ${ss}_sock.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_sock.c -o ${ss}_sock.o
${ss}_syslog.o: ${ss}_syslog.h ${ss}_syslog.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_syslog.c -o ${ss}_syslog.o
${ss}_telnet.o: ${ss}_telnet.h ${ss}_telnet.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_telnet.c -o ${ss}_telnet.o
${ss}_toolbox.o: ${ss}_toolbox.h ${ss}_toolbox.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c ${ss}_toolbox.c -o ${ss}_toolbox.o

# program parts
PPa=lcrzoex.o lcrzoex__00001.o lcrzoex__00002.o 
PPb=lcrzoex__00003.o lcrzoex__00004.o lcrzoex__00005.o 
PPc=lcrzoex__00006.o lcrzoex__00007.o lcrzoex__00008.o
PPd=lcrzoex__00009.o
PP=\$(PPa) \$(PPb) \$(PPc) \$(PPd)
lcrzoex.o: lcrzoex.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex.c -o lcrzoex.o
lcrzoex__00001.o: lcrzoex__00001.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00001.c -o lcrzoex__00001.o
lcrzoex__00002.o: lcrzoex__00002.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00002.c -o lcrzoex__00002.o
lcrzoex__00003.o: lcrzoex__00003.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00003.c -o lcrzoex__00003.o
lcrzoex__00004.o: lcrzoex__00004.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00004.c -o lcrzoex__00004.o
lcrzoex__00005.o: lcrzoex__00005.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00005.c -o lcrzoex__00005.o
lcrzoex__00006.o: lcrzoex__00006.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00006.c -o lcrzoex__00006.o
lcrzoex__00007.o: lcrzoex__00007.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00007.c -o lcrzoex__00007.o
lcrzoex__00008.o: lcrzoex__00008.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00008.c -o lcrzoex__00008.o
lcrzoex__00009.o: lcrzoex__00009.c
	\$(CC) \$(GCCOPT) $lcrzoconfigc -c lcrzoex__00009.c -o lcrzoex__00009.o

# program compilation - compilation du programme
lcrzoex: \$(SHOB) \$(PP)
	\$(CC) -o lcrzoex \$(SHOB) \$(PP) $lcrzoconfigl
	@echo ""
EOF

if [ $LCRZODEF_LANG = 2 ] ; then
cat >> Makefile <<EOF
	@echo "OK - Vous pouvez maintenant installer lcrzoex avec 'make install'"
EOF
else
cat >> Makefile <<EOF
	@echo "OK - You can now install lcrzoex with 'make install'"
EOF
fi

cat >> Makefile <<EOF

# installation : when everything is ok - a faire quand tout est ok
install: lcrzoex
	cp lcrzoex \$(INSTBIN)
	chown ${LCRZODEF_INSTUSERGROUP} \$(INSTBIN)/lcrzoex
	chmod 555 \$(INSTBIN)/lcrzoex
EOF

if [ $LCRZODEF_LANG = 1 ] ; then
  echo "	cp ../doc/man/lcrzoex_en.1 \$(INSTMAN1)/lcrzoex.1" >> ./Makefile
elif [ $LCRZODEF_LANG = 2 ] ; then
  echo "	cp ../doc/man/lcrzoex_fr.1 \$(INSTMAN1)/lcrzoex.1" >> ./Makefile
fi

# we start again - on recommence
cat >> ./Makefile <<EOF
	chmod 444 \$(INSTMAN1)/lcrzoex.1
	@echo ""
EOF

if [ $LCRZODEF_LANG = 2 ] ; then
cat >> Makefile <<EOF
	@echo "OK - Vous pouvez maintenant executer lcrzoex avec './lcrzoex' (ou 'lcrzoex' si \$(INSTBIN) est dans votre PATH)"
	@echo "Je vous conseille de commencer par 'lcrzoex 157', comme indique dans ../INSTALLUNIX_FR.TXT"
EOF
else
cat >> Makefile <<EOF
	@echo "OK - You can now run lcrzoex with './lcrzoex' (or 'lcrzoex' if \$(INSTBIN) is in your PATH)"
	@echo "I suggest you to start with 'lcrzoex 157', as explained ../INSTALLUNIX_EN.TXT"
EOF
fi

cat >> Makefile <<EOF

# desinstallation
uninstall: 
	rm -rf \$(INSTBIN)/lcrzoex
	rm -rf \$(INSTMAN1)/lcrzoex.1

# generic compilation - compilation generique
#%: %.c \$(SHOB) 
#	\$(CC) \$(GCCOPT) $lcrzoconfigc -o \$@ \$< $lcrzoconfigl

# cleaning - menage
clean:
	rm -f \$(SHOB)
	rm -f \$(PP)
	rm -f lcrzoex core lcrzoex.core
cleanall: clean
	rm -f lcrzoex_defs.h Makefile

EOF


########################################################################
########################################################################
if [ $LCRZODEF_LANG = 1 ] ; then
  echo "End of genemake"
elif [ $LCRZODEF_LANG = 2 ] ; then
  echo "Fin de genemake"
fi

###########
echo ""
if [ $LCRZODEF_LANG = 2 ] ; then
  echo "OK - Vous pouvez maintenant compiler avec 'make'"
else
  echo "OK - You can now compile with 'make'"
fi
