# makefile for latexdraw, Stand 19.10.1995/23.12.1996/13.4.98/3.7.98/28.2.99
# latexdraw is compiled and all files installed
# use
# for hp-ux:       make installhp
# for sun solaris: make installsun
# for freebsd:     make installfreebsd
# for linux:       make installlinux
#
################################################################################
# you may want to change some of the following definitions for your installation
################################################################################

# directory prefix
PREFIX = /usr/local

# directory for binaries
BINDIR = $(PREFIX)/bin
SUNBINDIR = $(BINDIR)
HPBINDIR = $(BINDIR)
FREEBINDIR = $(BINDIR)
LINUXBINDIR = $(BINDIR)

# directory for style files
STYLEDIR = $(PREFIX)/teTeX/texmf/tex/lib/inputs/latexdraw
SUNSTYLEDIR = $(STYLEDIR)
HPSTYLEDIR = $(STYLEDIR)
FREESTYLEDIR = $(STYLEDIR)
LINUXSTYLEDIR = $(STYLEDIR)

# directory for man page
MANDIR = $(PREFIX)/teTeX/texmf/tex/man/man1
SUNMANDIR = $(MANDIR)
HPMANDIR = $(MANDIR)
FREEMANDIR = $(MANDIR)
LINUXMANDIR = $(MANDIR)

# directory for documenation
DOCDIR = $(PREFIX)/teTeX/texmf/tex/lib/inputs/latexdraw/doc
SUNDOCDIR = $(DOCDIR)
HPDOCDIR = $(DOCDIR)
FREEDOCDIR = $(DOCDIR)
LINUXDOCDIR = $(DOCDIR)

# compiler
CC = gcc

#thread path
SUNTHREAD_DIR   = /usr
HPTHREAD_DIR    = /usr/local/robotik/DIR/dce-threads
FREETHREAD_DIR  = /usr
LINUXTHREAD_DIR = /usr


# include directory
INC_DIR  =  -I/usr/local/include -I/usr/local/include/X11 \
           -I/usr/include -I/usr/include/X11 \
           -I/usr/X11R6/include -I/usr/X11R6/include/X11 \
           -I/usr/include/X11R5 -I/usr/include/X11R5/X11

SUNINC_DIR    =  $(INC_DIR) -I$(SUNTHREAD_DIR)/include
HPINC_DIR     =  $(INC_DIR) -I$(HPTHREAD_DIR)/include
FREEINC_DIR   =  $(INC_DIR) -I$(FREETHREAD_DIR)/include
LINUXINC_DIR  =  $(INC_DIR) -I$(LINUXTHREAD_DIR)/include

#lib path and libs
LIB_DIR  = -L/usr/local/lib -L/usr/lib -L/usr/ccs/lib -L/usr/X11R6/lib
SUNLIB_DIR    = $(LIB_DIR) -L$(SUNTHREAD_DIR)/lib
HPLIB_DIR     = $(LIB_DIR) -L$(HPTHREAD_DIR)/lib
FREELIB_DIR   = $(LIB_DIR) -L$(FREETHREAD_DIR)/lib
LINUXLIB_DIR  = $(LIB_DIR) -L$(LINUXTHREAD_DIR)/lib

#compile without threads
SUNLIBS    = -lX11 -lm -lc -lnsl -lsocket
SUNTHREADFLAG =
HPLIBS     = -lX11 -lm -lc
HPTHREADFLAG =
FREELIBS   = -lX11 -lm -lc
FREETHREADFLAG =
LINUXLIBS  = -lX11 -lm -lc
LINUXTHREADFLAG =

#compile with threads (uncomment if compilation with threads)
#SUNLIBS    = -lX11 -lm -lc_r -lnsl -lsocket
#SUNTHREADFLAG = -DTHREAD
HPLIBS     = -lX11 -lm -ldce -lc_r
HPTHREADFLAG = -DTHREAD
FREELIBS   = -lX11 -lm -lc_r
FREETHREADFLAG = -DTHREAD
#LINUXLIBS  = -lX11 -lm -lc -lpthread
#LINUXTHREADFLAG = -DTHREAD

################################################################################
# do not change the following definitions
################################################################################

# Name of source-file without extension .c
L = latexdraw

# digitizer not included
DIGI_H =
DIGI_C =
DIGIFLAG=

# digitizer included
# DIGI_H = digitizer.h
# DIGI_C = digitizer.c
# DIGIFLAG= -DTABLETT

# compile for SUNSolaris
sunbin solarisbin:
       $(CC) $(SUNINC_DIR) $(DIGIFLAG) $(SUNTHREADFLAG) -DSUN -o $(L) $(L).c \
             $(DIGI_C) $(SUNLIB_DIR) $(SUNLIBS)

# compile for HPUX
hpbin hpuxbin:
       $(CC) $(HPINC_DIR) $(DIGIFLAG) $(HPTHREADFLAG) -DHPUX -o $(L) $(L).c \
             $(DIGI_C) $(HPLIB_DIR) $(HPLIBS)

# compile for freeBSD
freebin freebsdbin:
       $(CC) $(FREEINC_DIR) $(DIGIFLAG) $(FREETHREADFLAG) -DFREE -o $(L) $(L).c \
             $(DIGI_C) $(FREELIB_DIR) $(FREELIBS)

# compile for linux
linuxbin:
       $(CC) $(LINUXINC_DIR) $(DIGIFLAG) $(LINUXTHREADFLAG) -DLINUX -o $(L) $(L).c \
             $(DIGI_C) $(LINUXLIB_DIR) $(LINUXLIBS)

# create compressed tar-file (latexdraw-<majorVersion>.<minorVersion>)
tar:
       awk 'BEGIN{LName="$(L)"; gef = 0;\
         x= "#define window_name   \"LaTeXdraw (Siegert, TUM, C";\
         lx=length(x);}\
        {if (gef == 1) next; \
         if (substr($$0,1,lx) != x) next;\
         fin=match($$0,"\\)"); \
         LName= LName "-" substr($$0,lx+1,fin-1-lx) ".tar";\
         gef = 1; next;\
         }END{ \
       tarcommand = "tar -cf " LName " bin  digitizer doc $(L).c ";\
       tarcommand = tarcommand " Makefile man test texinputs";\
       system(tarcommand);\
       zipcommand = "gzip -f " LName;\
       system(zipcommand);\
       }' < $(L).c

extract:
       ls -1A $(L)*.tar.gz | \
       awk 'BEGIN{Vers1=-1; Vers2=0; Lname="$(L)"; lL=length(Lname);}\
        {if (length == 0) next;\
        Vers = substr($$0,lL+1,length-7); lVers = length(Vers);\
        if (lVers==0) next;\
        if (substr(Vers,1,1) != "-") next;\
        point = match(Vers,"[.]");\
        Vers1n = substr(Vers,2,point-1)+0;\
        Vers2n = substr(Vers,point+1,lVers)+0;\
        if ( (Vers1n > Vers1) || ((Vers1n == Vers1)&&(Vers2n>Vers2)) ) {\
         Vers1=Vers1n; Vers2 = Vers2n; Lname = substr($$0,1,length-7);}\
        }END{\
        unzipcommand = "gunzip " Lname ".tar.gz";\
        extractcommand = "tar -xf " Lname ".tar";\
        zipcommand = "gzip " Lname ".tar";\
        system(unzipcommand);\
        system(extractcommand);\
        system(zipcommand);\
        }'

# compile and install latexdraw for SUN Solaris from compressed tar-file!!!
installsun suninstall:
       make extract
       make sunbin
       cp $(L) bin/* $(SUNBINDIR)
       cp -r doc/* $(SUNDOCDIR)
       cp  man/man1/* $(SUNMANDIR)
       cp texinputs/* $(SUNSTYLEDIR)


# compile and install latexdraw for HPUX from compressed tar-file!!!
installhp hpinstall:
       make extract
       make hpbin
       cp $(L) bin/* $(HPBINDIR)
       cp -r doc/* $(HPDOCDIR)
       cp  man/man1/* $(HPMANDIR)
       cp texinputs/* $(HPSTYLEDIR)

# compile and install latexdraw for freeBSD from compressed tar-file!!!
installfreebsd installfreeBSD freebsdinstall freeBSDinstall:
       make extract
       make freebin
       cp $(L) bin/* $(FREEBINDIR)
       cp -r doc/* $(FREEDOCDIR)
       cp  man/man1/* $(FREEMANDIR)
       cp texinputs/* $(FREESTYLEDIR)

# compile and install latexdraw for Linux from compressed tar-file!!!
installlinux linuxinstall:
       make extract
       make linuxbin
       cp $(L) bin/* $(LINUXBINDIR)
       cp -r doc/* $(LINUXDOCDIR)
       cp  man/man1/* $(LINUXMANDIR)
       cp texinputs/* $(LINUXSTYLEDIR)


##############################################################
# following parts only for internal use by siegert
##############################################################

atbin:
       make freebin
       cp texinputs/* $$HOME/latex

# support to include colors
farben:
       awk 'BEGIN{print "Farben nach rgb.txt fuer Ergaenzung latexdraw";}\
           {printf("  eintragefarbname(&nr, \"%s\");\n",$$4);}'\
           rgb.txt >rgb.tmp1
       awk 'BEGIN{print "Farben nach rgb.txt fuer Ergaenzung latexdraw.sty";}\
           {printf(" %.2f %.2f %.2f \\sc@ \\or%% %d %d %d %s\n",\
           $$1/255,$$2/255,$$3/255,$$1,$$2,$$3,$$4);}' rgb.txt >rgb.tmp2
       awk 'BEGIN{print "Farben nach rgb.txt fuer allecolors.tex";}\
           {printf("\\sample{%.2f}{%.2f}{%.2f}{%s}\n",$$1/255,$$2/255,$$3/255,$$4);}'\
           rgb.txt >rgb.tmp3

# show testcase with number immediately following test, e.g. make test17
test%:
       cp -p abbtest/[email protected] ./
       latex $@
       rm [email protected]
       dvips [email protected] >[email protected];\
       ghostview -a4 -magstep -2 [email protected]
       rm $@.*

#####Ende Makefile#######