# Verifysoft Technology GmbH
# 20 Jun 2017
#
# This is a makefile for patching Testwell CTC++ 8.2 on Cygwin systems.
#
# See the readme.txt for various installation alternatives, how you
# can run this makefile and what you need to do after having run this.
#
.SILENT:

SHELL   = /bin/bash -x
INSTALL = /usr/bin/install

# Base directory for CTC++ installation.
# This must always be existing Testwell CTC++ v8.2 %CTCHOME%
prefix      := $(dir $(shell which ctc.exe))
ifeq ($(shell uname -o),Cygwin)
    localprefix = /usr/local/bin
else
    localprefix = $prefix
endif


# Path for the CTC++ preprocessor, postprocessor, ctc2html, ctc2excel,
# ctcwrap, ctcxmlmerge, and ctc2dat
BINDIR      = $(prefix)
LOCALBINDIR      = $(localprefix)

# Path for libctc*.a
LIBDIR      = $(prefix)/Lib

# Path for the configuration directory (ctc.ini etc.)
INIDIR      = $(prefix)

# Path for ctc.h
INCDIR      = $(prefix)

# Path for man pages
MANDIR      = /usr/share/man

# Man page section
MANEXT      = 1

# Path for examples
EXAMPLEDIR  = $(INIDIR)/Examples

# Path for documentation files
DOCDIR      = $(INIDIR)/Doc

# Path for wrap directory
WRAPDIR     = $(INIDIR)/wrap

# Path for temporary files used by CTC++, and also by this makefile
CDIR      = $(INIDIR)/Doc

# Path for wrap directory
WRAPDIR     = $(INIDIR)/wrap

# Path for temporary files used by CTC++, and also by this makefile
TEMPDIR     = /tmp

# =================================================================

default:
	echo
	echo See readme.txt for the various installation alternatives. For example
	echo it could be done as follows:
	echo
	echo \ \ \ \ make install 
	echo
	echo The installation directory must exist and you need to have rights to
	echo write there. 
	echo

install: check binaries libraries config wrapdir ctcwrapp \
         manpages exampledir finis

check:
	if [[ "$$MACHTYPE" != *-cygwin ]] && \
	    [[ "$$MACHTYPE" != *-msys ]]  \
	    ; then \
		echo You must install from within shell/bash !;\
                echo This is for Cygwin/MingW; \
                exit 1; \
        fi
	if test "$(prefix)" = ""; then                                  \
	  echo The prefix directory must be defined!;                   \
	  exit 1;                                                       \
	fi
	if [ ! -d $(prefix) ]; then                                     \
	  echo The prefix directory $(prefix) does not exist!;          \
	  echo Please create it first or choose some other directory;   \
	  exit 1;                                                       \
	fi
	if test `pwd` = $(TEMPDIR) ; then                               \
	  echo This makefile must not be invoked from the TEMPDIR directory; \
	  exit 1;                                                       \
	fi
	for p in /bin /usr/bin /usr/local/bin ; do        \
	  [ -x $$p/perl -a ! -d $$p/perl ] && perldir=$$p;              \
	done;                                                           \
	if [ ! -x $$perldir/perl ]; then                                \
	    echo Install perl, then re-invoke me;                       \
	fi

binaries:
	echo
	if [ ! -d $(BINDIR) ]; then                                     \
	  mkdir -p -m 755 $(BINDIR) &&                                  \
	  echo Created directory $(BINDIR);                             \
	fi
	cp -v ctc ctcpost ctcxmlmerge ctc2dat ctcdiff $(TEMPDIR);       \
	cd $(TEMPDIR);                                                  \
        mv -v ctc ctcpost ctcxmlmerge ctc2dat ctcdiff $(LOCALBINDIR);   \
	chmod 0755 $(LOCALBINDIR)/ctc &&                                \
	chmod 0755 $(LOCALBINDIR)/ctcpost &&                            \
	chmod 0755 $(LOCALBINDIR)/ctcxmlmerge &&                        \
	chmod 0755 $(LOCALBINDIR)/ctcdiff &&                            \
	chmod 0755 $(LOCALBINDIR)/ctc2dat
	for p in /bin /usr/bin /usr/local/bin; do                       \
	  [ -x $$p/perl -a ! -d $$p/perl ] && perldir=$$p;              \
	done;                                                           \
	if [ -x $$perldir/perl ]; then                                  \
	  sed < ctc2html > $(TEMPDIR)/ctc2html                          \
	  -e "s%/usr/local/lib/ctc%$(INIDIR)%"                          \
	  -e "s%^#!/usr/bin/perl$$%#!$$perldir/perl%";                  \
	  sed < ctc2excel > $(TEMPDIR)/ctc2excel                        \
	  -e "s%^#!/usr/bin/perl$$%#!$$perldir/perl%";                  \
	  cd $(TEMPDIR);                                                \
	  mv -v ctc2html $(LOCALBINDIR) &&                              \
	  chmod 0755 $(LOCALBINDIR)/ctc2html;                           \
	  mv -v ctc2excel $(LOCALBINDIR) &&                             \
	  chmod 0755 $(LOCALBINDIR)/ctc2excel;                          \
	else                                                            \
	  echo;                                                         \
	  echo "Could not find perl in /bin /usr/bin /usr/local/bin";   \
	  echo "Please edit the correct path to $(LOCALBINDIR)/ctc2html";\
	  echo "and to $(LOCALBINDIR)/ctc2excel";                       \
	  echo;                                                         \
	  cp -v ctc2excel $(LOCALBINDIR) &&                             \
	  chmod 0755 $(LOCALBINDIR)/ctc2excel;                          \
	  sed < ctc2html > $(TEMPDIR)/ctc2html                          \
	  -e "s%/usr/local/lib/ctc%$(INIDIR)%";                         \
	  cd $(TEMPDIR);                                                \
	  cp -v ctc2html $(LOCALBINDIR) &&                              \
	  chmod 0755 $(LOCALBINDIR)/ctc2html;                           \
	  rm ./ctc2html;                                                \
	fi

libraries:
	echo
	if [ ! -d $(LIBDIR) ]; then                                     \
	  mkdir -p -m 755 $(LIBDIR) &&                                  \
	  echo Created directory $(LIBDIR);                             \
	fi
	if [ -f libctccygwin.a ]; then                                  \
	  cp -v libctccygwin.a $(LIBDIR) &&                             \
	  chmod 0644 $(LIBDIR)/libctccygwin.a;                          \
	fi
	if [ -f libctccygwin64.a ]; then                                \
	  cp -v libctccygwin64.a $(LIBDIR) &&                           \
	  chmod 0644 $(LIBDIR)/libctccygwin64.a;                        \
	fi
	if [ -f libctclinux64.a ]; then                                 \
	  cp -v libctclinux64.a $(LIBDIR) &&                           \
	  chmod 0644 $(LIBDIR)/libctclinux64.a;                        \
	fi

config:
	echo
	if [ ! -d $(INIDIR) ]; then                                     \
	  mkdir -p -m 755 $(INIDIR) &&                                  \
	  echo Created directory $(INIDIR);                             \
	fi
	cp -v readme.txt $(INIDIR)/readme-cygwin.txt &&                 \
	chmod 0644 $(INIDIR)/readme-cygwin.txt
	cp -v version.txt $(INIDIR)/version-v8.2.b1.txt &&              \
	chmod 0644 $(INIDIR)/version-v8.2.b1.txt
	cp -v $(INIDIR)/ctc.ini $(TEMPDIR)/ctc.ini 
	if test `uname -m` == "x86_64" ; then                           \
	  sed < $(TEMPDIR)/ctc.ini > $(TEMPDIR)/ctc.ini.tmp             \
	  -e "s;^  # LIBRARY =;  LIBRARY = ;" ;                         \
	  mv $(TEMPDIR)/ctc.ini.tmp $(TEMPDIR)/ctc.ini;                 \
	fi;                                                             \
	if test `uname -o` == "Cygwin" ; then                           \
	if test `uname -m` == "x86_64" ; then                           \
	  sed < $(TEMPDIR)/ctc.ini > $(TEMPDIR)/ctc.ini.tmp             \
	  -e "s;-lctc64\b;-lctccygwin64;" ;                             \
	  mv $(TEMPDIR)/ctc.ini.tmp $(TEMPDIR)/ctc.ini;                 \
        else                                                            \
	  sed < $(TEMPDIR)/ctc.ini > $(TEMPDIR)/ctc.ini.tmp             \
	  -e "s;-lctc\b;-lctccygwin;" ;                                 \
	  mv $(TEMPDIR)/ctc.ini.tmp $(TEMPDIR)/ctc.ini;                 \
	fi;                                                             \
	fi;                                                             \
	cp -v $(TEMPDIR)/ctc.ini $(INIDIR) 

manpages:
	echo
	if [ -f $(MANDIR)/man$(MANEXT)/ctc.old.$(MANEXT) ]; then        \
	  rm $(MANDIR)/man$(MANEXT)/ctc.old.$(MANEXT) &&                \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctc.old.$(MANEXT); \
	fi
	if [ -f $(MANDIR)/man$(MANEXT)/ctcpost.old.$(MANEXT) ]; then    \
	  rm $(MANDIR)/man$(MANEXT)/ctcpost.old.$(MANEXT) &&            \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctcpost.old.$(MANEXT); \
	fi
	if [ -f $(MANDIR)/man$(MANEXT)/ctc2html.old.$(MANEXT) ]; then   \
	  rm $(MANDIR)/man$(MANEXT)/ctc2html.old.$(MANEXT) &&           \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctc2html.old.$(MANEXT); \
	fi
	if [ -f $(MANDIR)/man$(MANEXT)/ctc2excel.old.$(MANEXT) ]; then  \
	  rm $(MANDIR)/man$(MANEXT)/ctc2excel.old.$(MANEXT) &&          \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctc2excel.old.$(MANEXT); \
	fi
	if [ -f $(MANDIR)/man$(MANEXT)/ctcxmlmerge.old.$(MANEXT) ]; then \
	  rm $(MANDIR)/man$(MANEXT)/ctcxmlmerge.old.$(MANEXT) &&         \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctcxmlmerge.old.$(MANEXT); \
	fi
	if [ -f $(MANDIR)/man$(MANEXT)/ctcwrap.old.$(MANEXT) ]; then    \
	  rm $(MANDIR)/man$(MANEXT)/ctcwrap.old.$(MANEXT) &&            \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctcwrap.old.$(MANEXT); \
	fi
	if [ -f $(MANDIR)/man$(MANEXT)/ctc2dat.old.$(MANEXT) ]; then    \
	  rm $(MANDIR)/man$(MANEXT)/ctc2dat.old.$(MANEXT) &&            \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctc2dat.old.$(MANEXT); \
	fi
	if [ -f $(MANDIR)/man$(MANEXT)/ctcdiff.old.$(MANEXT) ]; then    \
	  rm $(MANDIR)/man$(MANEXT)/ctcdiff.old.$(MANEXT) &&            \
	  echo Found and removed obsolete $(MANDIR)/man$(MANEXT)/ctcdiff.old.$(MANEXT); \
	fi
	sed < ctc.1 > $(TEMPDIR)/ctc.$(MANEXT)                          \
	-e "s;^\.TH CTC++ 1;.TH CTC++ $(MANEXT);"                       \
	-e "s;ctcpost (1);ctcpost ($(MANEXT));"                         \
	-e "s;ctc2html (1);ctc2html ($(MANEXT));"                       \
	-e "s;ctc2excel (1);ctc2excel ($(MANEXT));"                     \
	-e "s;ctcxmlmerge (1);ctcxmlmerge ($(MANEXT));"                 \
	-e "s;ctcwrap (1);ctcwrap ($(MANEXT));"                         \
	-e "s;ctc2dat (1);ctc2dat ($(MANEXT));"                         \
	-e "s;ctcdiff (1);ctcdiff ($(MANEXT));"                         \
	-e "s;/usr/local/lib/libctc.a;$(LIBDIR)/libctc.a;"              \
	-e "s;/usr/local/lib/libctc64.a;$(LIBDIR)/libctc64.a;"          \
	-e "s;/usr/local/include/ctc.h;$(INCDIR)/ctc.h;"                \
	-e "s;/usr/local/bin;$(LOCALBINDIR);"
	sed < ctcpost.1 > $(TEMPDIR)/ctcpost.$(MANEXT)                  \
	-e "s;^\.TH ctcpost 1;.TH ctcpost $(MANEXT);"                   \
	-e "s;ctc (1);ctc ($(MANEXT));"                                 \
	-e "s;ctc2html (1);ctc2html ($(MANEXT));"                       \
	-e "s;ctc2excel (1);ctc2excel ($(MANEXT));"                     \
	-e "s;ctcxmlmerge (1);ctcxmlmerge ($(MANEXT));"                 \
	-e "s;ctcwrap (1);ctcwrap ($(MANEXT));"                         \
	-e "s;ctcdiff (1);ctcdiff ($(MANEXT));"                         \
	-e "s;ctc2dat (1);ctc2dat ($(MANEXT));"                         \
	-e "s;/usr/local/bin;$(LOCALBINDIR);"
	sed < ctc2html.1 > $(TEMPDIR)/ctc2html.$(MANEXT)                \
	-e "s;^\.TH ctc2html 1;.TH ctc2html $(MANEXT);"                 \
	-e "s;ctc (1);ctc ($(MANEXT));"                                 \
	-e "s;ctcpost (1);ctcpost ($(MANEXT));"                         \
	-e "s;ctc2excel (1);ctc2excel ($(MANEXT));"                     \
	-e "s;ctcwrap (1);ctcwrap ($(MANEXT));"                         \
	-e "s;ctcdiff (1);ctcdiff ($(MANEXT));"                         \
	-e "s;ctc2dat (1);ctc2dat ($(MANEXT));"                         \
	-e "s;ctcxmlmerge (1);ctcxmlmerge ($(MANEXT));"
	sed < ctc2excel.1 > $(TEMPDIR)/ctc2excel.$(MANEXT)              \
	-e "s;^\.TH ctc2excel 1;.TH ctc2excel $(MANEXT);"               \
	-e "s;ctc (1);ctc ($(MANEXT));"                                 \
	-e "s;ctcpost (1);ctcpost ($(MANEXT));"                         \
	-e "s;ctc2html (1);ctc2html ($(MANEXT));"                       \
	-e "s;ctcwrap (1);ctcwrap ($(MANEXT));"                         \
	-e "s;ctcdiff (1);ctcdiff ($(MANEXT));"                         \
	-e "s;ctc2dat (1);ctc2dat ($(MANEXT));"                         \
	-e "s;ctcxmlmerge (1);ctcxmlmerge ($(MANEXT));"
	sed < ctcxmlmerge.1 > $(TEMPDIR)/ctcxmlmerge.$(MANEXT)          \
	-e "s;^\.TH ctcxmlmerge 1;.TH ctcxmlmerge $(MANEXT);"           \
	-e "s;ctc (1);ctc ($(MANEXT));"                                 \
	-e "s;ctcpost (1);ctcpost ($(MANEXT));"                         \
	-e "s;ctc2html (1);ctc2html ($(MANEXT));"                       \
	-e "s;ctc2excel (1);ctc2excel ($(MANEXT));"                     \
	-e "s;ctcwrap (1);ctcwrap ($(MANEXT));"                         \
	-e "s;ctcdiff (1);ctcdiff ($(MANEXT));"                         \
	-e "s;ctc2dat (1);ctc2dat ($(MANEXT));"                         \
	-e "s;/usr/local/bin;$(LOCALBINDIR);"
	sed < ctcwrap.1 > $(TEMPDIR)/ctcwrap.$(MANEXT)                  \
	-e "s;^\.TH ctcwrap 1;.TH ctcwrap $(MANEXT);"                   \
	-e "s;ctc (1);ctc ($(MANEXT));"                                 \
	-e "s;ctcpost (1);ctcpost ($(MANEXT));"                         \
	-e "s;ctc2html (1);ctc2html ($(MANEXT));"                       \
	-e "s;ctc2excel (1);ctc2excel ($(MANEXT));"                     \
	-e "s;ctcdiff (1);ctcdiff ($(MANEXT));"                         \
	-e "s;ctc2dat (1);ctc2dat ($(MANEXT));"                         \
	-e "s;ctcxmlmerge (1);ctcxmlmerge ($(MANEXT));"                 \
	-e "s;/usr/local/bin;$(LOCALBINDIR);"                           \
	-e "s;/usr/local/lib/ctc/wrap;$(WRAPDIR);"
	sed < ctc2dat.1 > $(TEMPDIR)/ctc2dat.$(MANEXT)                  \
	-e "s;^\.TH ctc2dat 1;.TH ctc2dat $(MANEXT);"                   \
	-e "s;ctc (1);ctc ($(MANEXT));"                                 \
	-e "s;ctcpost (1);ctcpost ($(MANEXT));"                         \
	-e "s;ctc2html (1);ctc2html ($(MANEXT));"                       \
	-e "s;ctc2excel (1);ctc2excel ($(MANEXT));"                     \
	-e "s;ctcdiff (1);ctcdiff ($(MANEXT));"                         \
	-e "s;ctcxmlmerge (1);ctcxmlmerge ($(MANEXT));"                 \
	-e "s;ctcwrap (1);ctcwrap ($(MANEXT));"
	sed < ctcdiff.1 > $(TEMPDIR)/ctcdiff.$(MANEXT)                  \
	-e "s;^\.TH ctc2dat 1;.TH ctc2dat $(MANEXT);"                   \
	-e "s;ctc (1);ctc ($(MANEXT));"                                 \
	-e "s;ctcpost (1);ctcpost ($(MANEXT));"                         \
	-e "s;ctc2html (1);ctc2html ($(MANEXT));"                       \
	-e "s;ctc2excel (1);ctc2excel ($(MANEXT));"                     \
	-e "s;ctc2dat (1);ctc2dat ($(MANEXT));"                         \
	-e "s;ctcxmlmerge (1);ctcxmlmerge ($(MANEXT));"                 \
	-e "s;ctcwrap (1);ctcwrap ($(MANEXT));"
	if [ ! -d $(MANDIR) ]; then                                     \
	  mkdir -p -m 755 $(MANDIR) &&                                  \
	  echo Created directory $(MANDIR);                             \
	fi
	if [ ! -d $(MANDIR)/man$(MANEXT) ]; then                        \
	  mkdir -p -m 755 $(MANDIR)/man$(MANEXT) &&                     \
	  echo Created directory $(MANDIR)/man$(MANEXT);                \
	fi
	cd $(TEMPDIR);                                                  \
	cp -v ctc.$(MANEXT) $(MANDIR)/man$(MANEXT) &&                   \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctc.$(MANEXT);                \
	cp -v ctcpost.$(MANEXT) $(MANDIR)/man$(MANEXT) &&               \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctcpost.$(MANEXT);            \
	cp -v ctc2html.$(MANEXT) $(MANDIR)/man$(MANEXT) &&              \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctc2html.$(MANEXT);           \
	cp -v ctc2excel.$(MANEXT) $(MANDIR)/man$(MANEXT) &&             \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctc2excel.$(MANEXT);          \
	cp -v ctcxmlmerge.$(MANEXT) $(MANDIR)/man$(MANEXT) &&           \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctcxmlmerge.$(MANEXT);        \
	cp -v ctc2dat.$(MANEXT) $(MANDIR)/man$(MANEXT) &&               \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctc2dat.$(MANEXT);            \
	cp -v ctcdiff.$(MANEXT) $(MANDIR)/man$(MANEXT) &&               \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctcdiff.$(MANEXT);            \
	cp -v ctcwrap.$(MANEXT) $(MANDIR)/man$(MANEXT) &&               \
	chmod 0644 $(MANDIR)/man$(MANEXT)/ctcwrap.$(MANEXT);            \
	rm ./ctc.$(MANEXT);                                             \
	rm ./ctcpost.$(MANEXT);                                         \
	rm ./ctc2html.$(MANEXT);                                        \
	rm ./ctc2excel.$(MANEXT);                                       \
	rm ./ctcxmlmerge.$(MANEXT);                                     \
	rm ./ctc2dat.$(MANEXT);                                         \
	rm ./ctcdiff.$(MANEXT);                                         \
	rm ./ctcwrap.$(MANEXT)



exampledir:
	echo
	if [ ! -d $(EXAMPLEDIR) ]; then                                 \
	  mkdir -p -m 755 $(EXAMPLEDIR) &&                              \
	  echo Created directory $(EXAMPLEDIR);                         \
	fi
	cd examples;                                                    \
	for DIR in Prime Stack Multilib ; do                            \
	  if [ ! -d $(EXAMPLEDIR)/$${DIR} ]; then                       \
	    mkdir -p -m 755 $(EXAMPLEDIR)/$${DIR} &&                    \
	    echo Created directory $(EXAMPLEDIR)/$${DIR};               \
	  fi;                                                           \
	  for FILE in $${DIR}/* ; do                                    \
	    cp -v $${FILE} $(EXAMPLEDIR)/$${DIR} &&                     \
	    chmod 0644 $(EXAMPLEDIR)/$${FILE};                          \
	  done;                                                         \
	  if [ -f $(EXAMPLEDIR)/$${DIR}/fulldemo.sh ]; then             \
	    chmod 0755 $(EXAMPLEDIR)/$${DIR}/fulldemo.sh;               \
	  fi;                                                           \
	done

wrapdir:
	echo
	if [ ! -d $(WRAPDIR) ]; then                                    \
	  mkdir -p -m 755 $(WRAPDIR) &&                                 \
	  echo Created directory $(WRAPDIR);                            \
	fi
	if [ -f $(WRAPDIR)/ctc ]; then                                  \
	  rm $(WRAPDIR)/ctc;                                            \
	fi
	if [ -f $(WRAPDIR)/gcc ]; then                                  \
	  rm $(WRAPDIR)/gcc;                                            \
	fi
	if [ -f $(WRAPDIR)/cc ]; then                                   \
	  rm $(WRAPDIR)/cc;                                             \
	fi
	if [ -f $(WRAPDIR)/g++ ]; then                                  \
	  rm $(WRAPDIR)/g++;                                            \
	fi
	if [ -f $(WRAPDIR)/c++ ]; then                                  \
	  rm $(WRAPDIR)/c++;                                            \
	fi
	if [ -f $(WRAPDIR)/ld ]; then                                   \
	  rm $(WRAPDIR)/ld;                                             \
	fi
	if [ -f $(WRAPDIR)/ctcagent.old ]; then                         \
	  rm $(WRAPDIR)/ctcagent.old &&                                 \
	  echo Found and removed obsolete $(WRAPDIR)/ctcagent.old;      \
	fi
	if [ -f $(WRAPDIR)/wrap.old ]; then                             \
	  rm $(WRAPDIR)/wrap.old &&                                     \
	  echo Found and removed obsolete $(WRAPDIR)/wrap.old;          \
	fi
	for p in /bin /usr/bin /usr/local/bin ; do        \
	  [ -x $$p/perl -a ! -d $$p/perl ] && perldir=$$p;              \
	done;                                                           \
	if [ -x $$perldir/perl ]; then                                  \
	  sed < ctcagent > $(TEMPDIR)/ctcagent                          \
	  -e "s%^#!/usr/bin/perl$$%#!$$perldir/perl%";                  \
	  cd $(TEMPDIR);                                                \
	  cp -v ctcagent $(WRAPDIR) &&                                  \
	  chmod 0755 $(WRAPDIR)/ctcagent;                               \
	  rm ./ctcagent;                                                \
	else                                                            \
	  cp -v ctcagent $(WRAPDIR) &&                                  \
	  chmod 0755 $(WRAPDIR)/ctcagent;                               \
	  echo;                                                         \
	  echo "Could not find perl in /bin /usr/bin /usr/local/bin";   \
	  echo "Please edit the correct path to $(WRAPDIR)/ctcagent";   \
	  echo;                                                         \
	fi
	cd $(WRAPDIR) ;                                                 \
	cp -v ctcagent ctc ;                                            \
	cp -v ctcagent gcc ;                                            \
	cp -v ctcagent cc  ;                                            \
	cp -v ctcagent g++ ;                                            \
	cp -v ctcagent c++ ;                                            \
	cp -v ctcagent ld  ;

ctcwrapp:
	echo
	if [ ! -d $(LOCALBINDIR) ]; then                                \
	  mkdir -p -m 755 $(LOCALBINDIR) &&                             \
	  echo Created directory $(LOCALBINDIR);                        \
	fi
	if [ -f $(LOCALBINDIR)/ctcwrap.old ]; then                      \
	  rm $(LOCALBINDIR)/ctcwrap.old &&                              \
	  echo Found and removed obsolete $(LOCALBINDIR)/ctcwrap.old;   \
	fi
	for p in /bin /usr/bin /usr/local/bin; do        \
	  [ -x $$p/perl -a ! -d $$p/perl ] && perldir=$$p;              \
	done;                                                           \
	if [ -x $$perldir/perl ]; then                                  \
	  sed < ctcwrap > $(TEMPDIR)/ctcwrap                            \
	  -e "s;^#!/usr/bin/perl$$;#!$$perldir/perl;";                  \
	  cd $(TEMPDIR);                                                \
	  cp -v ctcwrap $(LOCALBINDIR) &&                               \
	  chmod 0755 $(LOCALBINDIR)/ctcwrap;                            \
	  rm ./ctcwrap;                                                 \
	else                                                            \
	  sed < ctcwrap > $(TEMPDIR)/ctcwrap                            \
	  -e "s;/usr/local/lib/ctc/wrap;$(WRAPDIR);";                   \
	  cd $(TEMPDIR);                                                \
	  cp -v ctcwrap $(LOCALBINDIR) &&                               \
	  chmod 0755 $(LOCALBINDIR)/ctcwrap;                            \
	  rm ./ctcwrap;                                                 \
	  echo;                                                         \
	  echo "Could not find perl in /bin /usr/bin /usr/local/bin";   \
	  echo "Please edit the correct path to $(LOCALBINDIR)/ctcwrap";\
	  echo;                                                         \
	fi


finis:
	echo
	echo \*\*\* Testwell CTC++/Cygwin installation makefile completed.
	echo
