# Makefile for pstoedit. 

prefix=/usr/local
# will install pstoedit in $prefix/bin and
# fontmap files in $prefix/lib
#
MANEXT=1
MANDIR=$(prefix)/man/man$(MANEXT)

AWK=gawk
#AWK=awk


# uncommment one of the following CCC lines for Un*x like systems
# For users of GNU g++
GNUGPPFLAGS=-DBUGGYGPP -ansi -pedantic -Wall -Wwrite-strings -Wcast-qual -Wpointer-arith -Wstrict-prototypes 
#CCC=g++ -O2 $(GNUGPPFLAGS)
# For debugging
#CCC=g++ -g $(GNUGPPFLAGS)

# For users of DJGPP
#CCC=gxx -DBUGGYGPP  

# For Sun's SparcCompiler or any C++ Compiler called via CC
#CCC=CC +w 
# SparcCompiler with source browsing option and debug support
# CCC=CC-4.2 -xsb +w -g

# For CenterLine (You may need to change clCC to CC)
#CCC=clCC +w -ptv 

# if you want to test pstoedit using insure (www.parasoft.com)
#CCC=insure CC +w 
#CCC=insure g++ -g $(GNUGPPFLAGS)

# rest of flags for Un*x systems
LINK=$(CCC) $(LDFLAGS)
CCFLAGS=-DDEFAULTGS=gs $(CXXFLAGS) 

# with shared libs LDFLAGS=-lm -ldl (Solaris, Linux, ???)
#LDLIBS= $(LOCALLIBS) -lm  -ldl
# without shared libs use LDFLAGS=-lm 
#LDLIBS=-lm

INSTALL_DATA=cp
INSTALL_DIR=install -d -m755     # or: mkdir -p
OBJEXT=o
EXEEXT=
OUTPUT=-o pstoedit
SPECIFICDRIVERS= drvtgif.$(OBJEXT)  drvfig.$(OBJEXT)  drvidraw.$(OBJEXT)  drvgnplt.$(OBJEXT) 
MAIN=cmdmain
target=pstoedit

# uncomment the next lines if you have the libplotter (GNU plotutils) 
#LOCALDRIVERS =  
#LOCALDEFINES = -DHAVE_LIBPLOTTER -DOLD_LIBPLOTTER -I/path/to/plotter.h
# use -DOLD_LIBPLOTTER for libplot older than 2.3
#LOCALLIBS = -lplotter 
#############################################################

# uncomment for Cygwin / Win32
# WARNING: -ansi compiler option does not work (for CygWin B20)!
GNUGPPFLAGS=-DBUGGYGPP -pedantic -Wall -Wwrite-strings -Wcast-qual -Wpointer-arith -Wstrict-prototypes
# For the release
#CCC=g++ -O2 $(GNUGPPFLAGS)
# For debugging
CCC=g++ -g $(GNUGPPFLAGS)
CCFLAGS=-DDEFAULTGS=gswin32
OBJEXT=o
EXEEXT=.exe
OUTPUT=-o pstoedit.exe
SPECIFICDRIVERS=drvwmf.$(OBJEXT)
MAIN=cmdmain
target=pstoedit.exe
LOCALDEFINES=-DHAVESTL -I. -I../othersrc/gsdllinc
LDLIBS=-luser32 -lgdi32
LINK=g++
#############################################################

## IRIX 5.3
#CCC=CC -O2 -mips2 -Olimit 2400   
#LDLIBS=-lm
## IRIX 6.2
#CCC=CC -mips3 -n32 -O2 -OPT:fold_arith_limit=2500 -DINTERNALBOOL
#LDLIBS=-lm
#############################################################

## For RiscOS users using g++
#CCC=g++
#CCFLAGS=-Wall -Dunix -Ilibgpp: -Ilibstdc: -Ilibio:
#LDLIBS=-rescan libgpp:o.libg++ libstdc:o.libstdc++ libio:o.libiostrea gcc:o.libgcc Unix:o.UnixLib
#LINK=link
#############################################################

# For AIX xlC users
#CCC=xlC
#CCFLAGS=-D__unix__ -g -+ -I/usr/lpp/xlC/src/nihC/aixinclude          
#LINK=$(CCC)
#############################################################

## For DEC OSF/1 with its native cxx
#
#> Ferner muss drvbase.cc mit der cxx compiler-option -define_templates
#> compiliert werden; fuer alle anderen cc-Files kann der Compiler im
#> makefile mit (wilms@astro.uni-tuebingen.de)
#>
#CCC=cxx -w
#CCFLAGS=-DDEFAULTGS=gs -define_templates
#LINK=$(CCC)
#############################################################


# uncomment for Win32 / Borland C++
#CCC=f:\sw2\bc5\bin\bcc32 /If:\sw2\bc5\include /I../othersrc/gsdllinc /I. 
#CCC=bcc32 /I../othersrc/gsdllinc /I.  
## add -v to CCFLAGS for debugging
#CCFLAGS= -DINTERNALBOOL -P  -DDEFAULTGS=gswin32 -I.;../cd1.3 
#LDLIBS= owlwf.lib bidsf.lib import32.lib cw32.lib
#OBJEXT=obj
#EXEEXT=.exe
#OUTPUT=-epstoedit
#SPECIFICDRIVERS=drvwmf.$(OBJEXT)
#MAIN=cmdmain
#target=pstoedit.exe
#############################################################

# uncomment for DOS / Turbo C++
#CCC=tcc
#CCFLAGS=-P -I. -ml -DDEFAULTGS=gs386
#OBJEXT=obj
#EXEEXT=.exe
#OUTPUT=-epstoedit
#SPECIFICDRIVERS=
#MAIN=cmdmain
#target=pstoedit.exe
#############################################################

# uncomment for Win32 / Visual C++
#
# This builds a pstoedit.exe with all drivers linked in.
# So far the Makefile does not support building the 
# pstoedit.dll and the separate pstoedit which just calls
# the pstoedit.dll
# 
#CCC=cl
## /Ze is used in version 4.2 to enable language extensions like bool
## unfortunately this does not work as expected
## so we have to #define bool,false and true
#CCFLAGS= /Zi /MLd /W3 /I../othersrc/gsdllinc /I. -Dbool=BOOL -Dfalse=FALSE -Dtrue=TRUE -DDEFAULTGS=gswin32 
# for version 5.0 and 6.0 (which support bool)
#CCFLAGS= /I../othersrc/gsdllinc /Zi /MLd /W3 /I. -DINTERNALBOOL -DDEFAULTGS=gswin32 
#FORCECPPFLAGS=/Tp
#LDLIBS=  user32.lib gdi32.lib advapi32.lib 
#OBJEXT=obj
#EXEEXT=.exe
#OUTPUT=/Fepstoedit
#SPECIFICDRIVERS=drvwmf.$(OBJEXT)
#MAIN=cmdmain
#target=pstoedit.exe
#############################################################

# uncomment for OS2 using VisualAge C++
#CCC=icc
# # Tdp forces C++
# # Gm+ enables threads
# # Ti activates debug mode
#CCFLAGS= -I. /Tdp /Gm+ -DDEFAULTGS=gsos2
#OBJEXT=obj
#EXEEXT=.exe
#OUTPUT=-Fepstoedit
#DEFFILE=pstoedit.def
#SPECIFICDRIVERS=drvmet.obj
#MAIN=cmdmain
#target=pstoedit.exe
#############################################################

# uncomment for OS2 using gcc
#CCC=gcc
#CCFLAGS=-Zexe -Zmt -D__OS2__='' -DDEFAULTGS=gsos2
#OBJEXT=o
#EXEEXT=
#OUTPUT=-o pstoedit
#LDLIBS=-Zexe -Zmt -lstdcpp 
#DEFFILE=pstoedit.def
#SPECIFICDRIVERS=drvmet.o
#MAIN=cmdmain
#target=pstoedit
#############################################################

# For developers only: 
# Uncomment the following lines (LEXSOURCE= and PSHEADER=) if you  have 
# pstoedit.pro and makeedit.l and need to make some changes in these files.
#LEXSOURCE=lexyy.cpp
# This is some sort ot hack. If LEXSOURCE is not defined, the make rule below
# only relates to dummy.cpp, which is not used by the main target.
#PSHEADER=pstoedit.ph
# same comment applies to PSHEADER variable
#############################################################


default : $(target)
# No changes should be necessary below this line

.SUFFIXES: .cpp .obj .o .chk
.cpp.o:
	$(CCC) -c $(LOCALDEFINES) $(CCFLAGS) $(FORCECPPFLAGS) $<

.cpp.obj:
	$(CCC) /c $(LOCALDEFINES) $(CCFLAGS) $(FORCECPPFLAGS) $<

#	$(CCC) /c $(LOCALDEFINES) $(CCFLAGS) $&.cpp


# Standard Drivers (for all systems)
STANDARDDRIVERS=\
	drvlwo.$(OBJEXT)  \
	drvrib.$(OBJEXT)  \
	drvrpl.$(OBJEXT)  \
	drvdxf.$(OBJEXT)  \
	drvjava.$(OBJEXT) \
	drvjava2.$(OBJEXT) \
	drvlplot.$(OBJEXT) \
	drvpdf.$(OBJEXT)  \
	drvkillu.$(OBJEXT) \
	drvsk.$(OBJEXT) \
	drvmpost.$(OBJEXT) \
	drvlatex2e.$(OBJEXT) \
	drvpic.$(OBJEXT) \
	drvhpgl.$(OBJEXT) \
	drvtk.$(OBJEXT)



# Comment out the next line if you don't want the sample driver to be included
SAMPLEDRIVER=drvsampl.$(OBJEXT) 

DRIVERS=$(STANDARDDRIVERS) $(LOCALDRIVERS) $(SAMPLEDRIVER) $(SPECIFICDRIVERS)
OBJECTS=dynload.$(OBJEXT) callgs.$(OBJEXT) $(MAIN).$(OBJEXT) pstoedit.$(OBJEXT) lexyy.$(OBJEXT) miscutil.$(OBJEXT) cbstream.$(OBJEXT) psimage.$(OBJEXT) drvbase.$(OBJEXT) subpath.$(OBJEXT) $(DRIVERS)

# this does not work with GNU make
#OBJECTS:sh =ls drv*.c | sed 's/\.c/\.$(OBJEXT)/'
#OBJECTS += lexyy.$(OBJEXT)

TESTDRIVER=drvpdf
libdemo : libusagedemo.$(OBJEXT) drvbase.$(OBJEXT) $(TESTDRIVER).$(OBJEXT)
	$(LINK) -o libusagedemo libusagedemo.$(OBJEXT) drvbase.$(OBJEXT) $(TESTDRIVER).$(OBJEXT)

pstoedit : $(OBJECTS) 
	$(LINK) $(OUTPUT)  $(OBJECTS) $(LDLIBS) $(DEFFILE) 

# purified version
pstoedit.pure : $(OBJECTS) 
	purify $(LINK) -o pstoedit.pure  $(CCFLAGS) $(OBJECTS) $(LDLIBS) $(DEFFILE) 

# proofed version (TestCenter from CenterLine)
pstoedit.proof : $(OBJECTS) 
	proof $(LINK) -o pstoedit.proof  $(CCFLAGS) $(OBJECTS) $(LDLIBS) $(DEFFILE) 

pstoedit.exe : $(OBJECTS) 
#	echo pstoedit.$(OBJEXT) lexyy.$(OBJEXT) drvbase.$(OBJEXT) > link.rsp
# distribute the above objects among the following lines, in case
# one of the driver variable is empty
	echo $(MAIN).$(OBJEXT) poptions.$(OBJEXT) pstoedit.$(OBJEXT) callgs.$(OBJEXT) > link.rsp
	echo $(STANDARDDRIVERS)  >> link.rsp
	echo lexyy.$(OBJEXT) $(LOCALDRIVERS)  >> link.rsp
	echo $(SAMPLEDRIVER)  $(SPECIFICDRIVERS)  >> link.rsp
	echo miscutil.$(OBJEXT)  dynload.$(OBJEXT) base64writer.$(OBJEXT) cbstream.$(OBJEXT) drvbase.$(OBJEXT) $(LDLIBS)  >> link.rsp
	$(CCC) $(OUTPUT)  $(CCFLAGS) @link.rsp
	-del link.rsp

dummy.cpp $(LEXSOURCE) : makeedit.l
	flex  -L -8 makeedit.l 
	-mv lex.yy.c lexyy.cpp
	-mv lexyy.c lexyy.cpp

clean:
	rm -f core pstoedit.pure pstoedit.proof pstoedit$(EXEEXT) *.$(OBJEXT) *.chk

test: pstoedit$(EXEEXT)
	-cd ../examples;\
	../src/pstoedit -f tgif illusion.ps illusion.ps.obj;\
	tgif illusion.ps.obj;\
	../src/pstoedit -scale 2 -f tgif illusion.ps illusion.ps.obj;\
	tgif illusion.ps.obj;\
	../src/pstoedit -dt -f tgif illusion.ps illusion.ps.obj;\
	tgif illusion.ps.obj;\
	../src/pstoedit -f tgif eschertr.ps eschertr.ps.obj;\
	tgif eschertr.ps.obj;\
	../src/pstoedit -f fig illusion.ps illusion.ps.fig;\
	xfig illusion.ps.fig;\
	../src/pstoedit -f fig eschertr.ps eschertr.ps.fig;\
	xfig eschertr.ps.fig;\
	../src/pstoedit -f fig spiral.ps spiral.ps.fig;\
	xfig spiral.ps.fig;\
	echo "now trying RIB for RenderMan ";\
	../src/pstoedit -dt -f rib illusion.ps illusion.ps.rib ;\
	../src/pstoedit -dt -f rib eschertr.ps eschertr.ps.rib ;\
	echo "now trying LWO for LightWave 3D ";\
	../src/pstoedit -dt -f lwo illusion.ps illusion.ps.lwo ;\
	../src/pstoedit -dt -f lwo eschertr.ps eschertr.ps.lwo ;\
	echo "now trying RPL for Real3D ";\
	../src/pstoedit -dt -f rpl illusion.ps illusion.ps.rpl ;\
	../src/pstoedit -dt -f rpl eschertr.ps eschertr.ps.rpl ;\
	echo "tests done";

#	groff -man ../doc/pstoedit.1  > pstoedit.man.ps
# if you don't have groff, try the following instead
#	troff -man -Tpsc ../doc/pstoedit.1 | psdit > pstoedit.man.ps

drvmdraw.ph : drvmdraw.pro
	$(AWK) -f mkmdraw.awk < drvmdraw.pro > drvmdraw.ph

dummy.ph $(PSHEADER) : pstoedit.pro
	$(AWK) -f mkpspro.awk < pstoedit.pro > pstoedit.ph

install: pstoedit ../doc/pstoedit.1
	if [ ! -d $(prefix)/bin ] ; then \
		$(INSTALL_DIR) $(prefix)/bin; \
	fi                                    
	$(INSTALL_DATA) pstoedit $(prefix)/bin
	if [ ! -d $(prefix)/lib ] ; then \
		$(INSTALL_DIR) $(prefix)/lib; \
	fi
	$(INSTALL_DATA) ../misc/mpost.fmp  $(prefix)/lib
	$(INSTALL_DATA) ../misc/latex2e.fmp  $(prefix)/lib
	if [ ! -d $(MANDIR) ] ; then \
		$(INSTALL_DIR) $(MANDIR); \
	fi
	$(INSTALL_DATA) ../doc/pstoedit.1  $(MANDIR)/pstoedit.$(MANEXT);
	echo "please copy ../doc/pstoedit.htm to a suitable place"


# Just for running static check tools
LINTLIKECHECKER=cppchecker
LINTLIKECHECKER=flintchecker
ALLCHKS=\
drvbase.chk\
drvwmf.chk\
drvdxf.chk\
drvfig.chk\
drvgnplt.chk\
drvmet.chk\
drvpdf.chk\
drvjava.chk\
drvsampl.chk\
drvtgif.chk\
drvidraw.chk\
drvlwo.chk\
drvrib.chk\
drvrpl.chk\
drvavf.chk\
lexyy.chk\
cmdmain.chk\
pstoedit.chk\
cdlib.chk

.cpp.chk:
	$(LINTLIKECHECKER) $< $@ -c $(LOCALDEFINES) $(CCFLAGS) $(FORCECPPFLAGS) 

checknamed: $(ALLCHKS)
	echo checks done

checkall:
	for f in *.cpp; do \
		$(LINTLIKECHECKER) $$f `basename $$f .cpp`.log $(LOCALDEFINES) $(CCFLAGS) $(FORCECPPFLAGS) ;\
	done

#depend: 
#	makedepend *.cpp
# DO NOT DELETE


lexyy.$(OBJEXT): lexyy.cpp drvbase.h drvfuncs.h psimage.h
drvbase.$(OBJEXT): drvbase.cpp drvbase.h drvfuncs.h psimage.h
pstoedit.$(OBJEXT): pstoedit.cpp drvbase.h drvfuncs.h psfront.h pstoedit.h pstoedit.ph
$(MAIN).$(OBJEXT): $(MAIN).cpp pstoedit.h

drvtgif.$(OBJEXT): drvtgif.cpp drvtgif.h drvbase.h drvfuncs.h psimage.h
drvtk.$(OBJEXT): drvtk.cpp drvtk.h drvbase.h drvfuncs.h psimage.h
drvlwo.$(OBJEXT): drvlwo.cpp drvlwo.h drvbase.h drvfuncs.h psimage.h
drvrib.$(OBJEXT): drvrib.cpp drvrib.h drvbase.h drvfuncs.h psimage.h
drvrpl.$(OBJEXT): drvrpl.cpp drvrpl.h drvbase.h drvfuncs.h psimage.h
drvidraw.$(OBJEXT): drvidraw.cpp drvidraw.h drvbase.h drvfuncs.h psimage.h
drvfig.$(OBJEXT): drvfig.cpp drvfig.h drvbase.h drvfuncs.h psimage.h
drvgnplt.$(OBJEXT): drvgnplt.cpp drvgnplt.h drvbase.h drvfuncs.h psimage.h
drvdxf.$(OBJEXT): drvdxf.cpp drvdxf.h drvbase.h drvfuncs.h psimage.h
drvmet.$(OBJEXT): drvmet.cpp drvmet.h drvbase.h drvfuncs.h psimage.h
drvpdf.$(OBJEXT): drvpdf.cpp drvpdf.h drvbase.h drvfuncs.h psimage.h
drvtext.$(OBJEXT): drvtext.cpp drvtext.h drvbase.h drvfuncs.h psimage.h
cdlib.$(OBJEXT): cdlib.cpp 
drvmdraw.$(OBJEXT): drvmdraw.cpp drvbase.h drvmdraw.h drvfuncs.h psimage.h drvmdraw.ph
drvsampl.$(OBJEXT): drvsampl.cpp drvbase.h drvsampl.h drvfuncs.h psimage.h
drvjava.$(OBJEXT): drvjava.cpp drvbase.h drvjava.h drvfuncs.h psimage.h
drvjava2.$(OBJEXT): drvjava2.cpp drvbase.h drvjava2.h drvfuncs.h psimage.h
drvwmf.$(OBJEXT): drvwmf.cpp drvbase.h drvwmf.h drvfuncs.h psimage.h
pstoedit.ph: # dummy for RiscOS GNU make's screwed dependencies
 
 
 
 
 
