# Makefile for pstoedit. 

BINDIR=/home/sun11b/local/sun4/bin
MANDIR=/home/sun11b/local/man

AWK=gawk


# uncommment one of the following CCC lines for Un*x like systems
# For users of GNU g++
CCC=g++ -Wall 
# For Sun's SparcCompiler (You may need to change SCC4 to CC)
#CCC=SCC4.1 +w
# For CenterLine (You may need to change clCC to CC)
#CCC=clCC +w -ptv 

# rest of flags for Un*x systems
CCFLAGS=-DDEFAULTGS=gs
LDFLAGS=-lm
INSTALL=cp
OBJEXT=o
EXEEXT=
OUTPUT=-o pstoedit
SPECIFICDRIVERS= drvtgif.$(OBJEXT)  drvfig.$(OBJEXT)  drvgnplt.$(OBJEXT) 
MAIN=cmdmain
target=pstoedit
#############################################################

# For AIX xlC users
#CCC=xlC
#CCFLAGS=-g -+ -I/usr/lpp/xlC/src/nihC/aixinclude 


# uncomment for Win32 / Borland C++
#CCC=bcc32
## add -v to CCFLAGS for debugging
#CCFLAGS= -DINTERNALBOOL -P  -DDEFAULTGS=gswin32 -I.;../cd1.2x 
#LDFLAGS= 
#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
#LDFLAGS=
#OBJEXT=obj
#EXEEXT=.exe
#OUTPUT=-epstoedit
#SPECIFICDRIVERS=
#MAIN=cmdmain
#target=pstoedit.exe
#############################################################

# uncomment for Win32 / Visual C++
#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. -Dbool=BOOL -Dfalse=FALSE -Dtrue=TRUE -DDEFAULTGS=gswin32 
#FORCECPPFLAGS=/Tp
#LDFLAGS=
#OBJEXT=obj
#EXEEXT=.exe
#OUTPUT=/Fepstoedit
#SPECIFICDRIVERS=
#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
#LDFLAGS=
#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
#LDFLAGS=-lstdcpp
#DEFFILE=pstoedit.def
#SPECIFICDRIVERS=drvmet.o
#MAIN=cmdmain
#target=pstoedit
#############################################################


# uncomment if you want to use the CGM driver and have installed the 
# cd-library in $CDDIR
CDDIR=../cd1.2x
LOCALDEFINES=-I$(CDDIR) -DWITHCGM
LOCALDRIVERS=drvcgm.$(OBJEXT) cdlib.$(OBJEXT)
#############################################################

# 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 
.cpp.o:
	$(CCC) -c $(LOCALDEFINES) $(CCFLAGS) $(FORCECPPFLAGS) $<

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

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

HEADERS=\
	drvlwo.h \
	drvrib.h \
	drvrpl.h \
	drvtgif.h \
	drvmif.h \
	drvfig.h \
	drvgnplt.h \
	drvdxf.h \
	drvmet.h \
	drvpdf.h \
	drvcgm.h \
	drvjava.h \
	drvsampl.h \
	drvbase.h drvfuncs.h pstoedit.h pstoedit.ph version.h config.h

# Standard Drivers (for all systems)
STANDARDDRIVERS=\
	drvlwo.$(OBJEXT) \
	drvrib.$(OBJEXT) \
	drvrpl.$(OBJEXT) \
	drvmif.$(OBJEXT) \
	drvdxf.$(OBJEXT) \
	drvjava.$(OBJEXT) \
	drvpdf.$(OBJEXT) 

SAMPLEDRIVER=drvsampl.$(OBJEXT) 

DRIVERS=$(STANDARDDRIVERS) $(LOCALDRIVERS) $(SAMPLEDRIVER) $(SPECIFICDRIVERS)
OBJECTS=$(MAIN).$(OBJEXT) pstoedit.$(OBJEXT) lexyy.$(OBJEXT) drvbase.$(OBJEXT) $(DRIVERS)

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

pstoedit : $(OBJECTS) 
	$(CCC) $(OUTPUT)  $(CCFLAGS) $(OBJECTS) $(LDFLAGS) $(DEFFILE) 

pstoedit.pure : $(OBJECTS) 
	purify $(CCC) -o pstoedit.pure  $(CCFLAGS) $(OBJECTS) $(LDFLAGS) $(DEFFILE) 

pstoedit.proof : $(OBJECTS) 
	proof $(CCC) -o pstoedit.proof  $(CCFLAGS) $(OBJECTS) $(LDFLAGS) $(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) pstoedit.$(OBJEXT) $(STANDARDDRIVERS)  > link.rsp
	echo lexyy.$(OBJEXT) $(LOCALDRIVERS)  >> link.rsp
	echo $(SAMPLEDRIVER)  $(SPECIFICDRIVERS)  >> link.rsp
	echo drvbase.$(OBJEXT) $(LDLIBS)  >> link.rsp
	$(CCC) $(OUTPUT)  $(LDFLAGS) $(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)

test: pstoedit$(EXEEXT)
	cd ../examples;\
	../src/pstoedit -f tgif illusion.ps illusion.ps.obj;\
	tgif illusion.ps.obj;\
	../src/pstoedit -s 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 ps from groff";\
	groff -man ../src/pstoedit.man > pstoedit.man.ps;\
	../src/pstoedit -f ps pstoedit.man.ps pstoedit.man.ps.ps;\
	gs pstoedit.man.ps.ps;\
	echo "now trying MIF for Frame ";\
	../src/pstoedit -f mif illusion.ps illusion.ps.mif ;\
	../src/pstoedit -f mif eschertr.ps eschertr.ps.mif ;\
	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";

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

dummy.ph $(PSHEADER) : pstoedit.pro
	$(AWK) 'BEGIN { \
		print "// DO NOT CHANGE THIS FILE. THIS FILE IS GENERATED FROM pstoedit.pro "; \
		print "// You can get pstoedit.pro from the author of pstoedit"; \
		print "// pstoedit.pro contains a lot more comments and explanations than pstoedit.ph"; \
		print "const char * PS_prologue[] = "; print "{"; } \
	      /^%\/\//      { gsub(/%/,""); print $$0; next;}	\
	      /^[ \t]*%/      { next; }	\
	      /^[ \t]*$$/      { next; }	\
	      { gsub(/^[ \t]*/,""); gsub(/\\/,"\\\\"); gsub(/"/,"\\\""); print " \" " $$0 " \","; } \
	      END   { print "0"; print "};" } ' < pstoedit.pro > pstoedit.ph

install: pstoedit pstoedit.man
	$(INSTALL) pstoedit $(BINDIR)
	$(INSTALL) pstoedit.man $(MANDIR)/manl/pstoedit.l

mtest:	
	echo $(OBJECTS)
#depend: 
#	makedepend *.cpp
# DO NOT DELETE


lexyy.$(OBJEXT): drvbase.h drvfuncs.h 
drvbase.$(OBJEXT): drvbase.h drvfuncs.h
pstoedit.$(OBJEXT): $(HEADERS) 
$(MAIN).$(OBJEXT): pstoedit.h

drvtgif.$(OBJEXT): drvtgif.h drvbase.h drvfuncs.h 
drvlwo.$(OBJEXT): drvlwo.h drvbase.h drvfuncs.h 
drvrib.$(OBJEXT): drvrib.h drvbase.h drvfuncs.h 
drvrpl.$(OBJEXT): drvrpl.h drvbase.h drvfuncs.h 
drvmif.$(OBJEXT): drvmif.h drvbase.h drvfuncs.h 
drvfig.$(OBJEXT): drvfig.h drvbase.h drvfuncs.h
drvgnplt.$(OBJEXT): drvgnplt.h drvbase.h drvfuncs.h 
drvdxf.$(OBJEXT): drvdxf.h drvbase.h drvfuncs.h
drvmet.$(OBJEXT): drvmet.h drvbase.h drvfuncs.h 
drvpdf.$(OBJEXT): drvpdf.h drvbase.h drvfuncs.h
drvcgm.$(OBJEXT): drvcgm.h drvbase.h drvfuncs.h
drvsampl.$(OBJEXT): drvbase.h drvsampl.h drvfuncs.h
drvjava.$(OBJEXT): drvbase.h drvjava.h drvfuncs.h
drvwmf.$(OBJEXT): drvbase.h drvwmf.h drvfuncs.h
