# Makefile.  Generated from Makefile.in by configure.

ARCH = unix
POLL = poll

GCVERSION = 7.6.0
GC = gc-$(GCVERSION)
LIBATOMIC = libatomic_ops-7.4.4
GCOPTIONS = --disable-shared --enable-large-config
GCLIB = $(GC)/.libs/libgc.a
GCPPLIB = 
GCLIBS = $(GCPPLIB) $(GCLIB)
LFLAGS = 
LIBS = $(LFLAGS)  -lglut -lGLU -lGL -lreadline -lrt -lz -lm -lncurses  $(GCLIBS)
DOSLIBS = $(subst -lncurses, -ltermcap, $(LIBS)) -s -static

PERL = perl

# Libraries needed to make asymptote.so.
# We have to remove OpenGL, threading, GC, etc from this.
SHAREDLIBS = $(filter-out -lGL -lGLU -lglut -pthread $(GCLIBS), $(LIBS))

vpath %.cc prc

CAMP = camperror path drawpath drawlabel picture psfile texfile util settings \
       guide flatguide knot drawfill path3 drawpath3 drawsurface \
       beziercurve bezierpatch pen pipestream

RUNTIME_FILES = runtime runbacktrace runpicture runlabel runhistory runarray \
	runfile runsystem runpair runtriple runpath runpath3d runstring \
	runmath

# Files to be scanned for pre-translated symbols defined by SYM(name).
SYMBOL_FILES = types builtin gsl $(RUNTIME_FILES)

PRC =  PRCbitStream oPRCFile PRCdouble writePRC

COREFILES = $(CAMP) $(SYMBOL_FILES) env genv stm dec errormsg \
        callable name symbol entry exp newexp stack camp.tab lex.yy \
	access virtualfieldaccess absyn record interact fileio \
	fftw++asy simpson coder coenv impdatum \
	 locate parser program application varinit fundec refaccess \
	envcompleter process constructor array Delaunay predicates \
	$(PRC) glrender tr arcball algebra3 quaternion

FILES = $(COREFILES) main

DIST = camp.tab.h camp.tab.cc lex.yy.cc runtime.cc keywords.cc \
	asy-keywords.el $(RUNTIME_FILES:=.cc) $(RUNTIME_FILES:=.h) asy.list \
        allsymbols.h opsymbols.h $(SYMBOL_FILES:=.symbols.h) 
NAME = asy
XNAME = x$(NAME)
CLEAN = camp.output base/version.asy doc/version.texi \
        GUI/xasyVersion.py $(XNAME) doc/asy-latex.pdf
EXTRA = asy-mode.el asy-init.el asy.vim asy_filetype.vim asy-kate.sh \
        asymptote.py reload.js nopapersize.ps
EXEXTRA = piicon.eps *.views *.dat *.bib
DOCEXTRA = *.asy *.csv *.dat latexusage.tex externalprc.tex pixel.pdf
KEYWORDS = base $(ASYMPTOTE_SITEDIR)
LATEXFILES = asymptote.sty asycolors.sty ocg.sty latexmkrc 
CONTEXTFILES = colo-asy.tex
ASY = ./asy -dir base -config "" -render=0

DEFS = -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -DUSEGC  -pthread -DFFTWPP_SINGLE_THREAD
CFLAGS = -g -fno-var-tracking
OPTS = $(DEFS)  -ansi $(CFLAGS)
INCL = -I. -I$(GC)/include

# Options for compiling the object files for the shared library.
# gc has to be configured with the option --disable-threads in order to make a
# shared library that doesn't seg fault.  For now, just disable gc in the
# shared library.
SHAREDOPTS = $(filter-out -DUSEGC, $(OPTS)) -fPIC -DFOR_SHARED

CXX = g++ -Wall
CC = gcc -Wall
MAKEDEPEND = $(OPTS) -O0 -M -DDEPEND
BISON = bison
LEX = flex

prefix = /tmp/ainst
exec_prefix = ${prefix}
datarootdir = ${prefix}/share
bindir = $(DESTDIR)${exec_prefix}/bin
mandir = $(DESTDIR)${datarootdir}/man
infodir = $(DESTDIR)${datarootdir}/info
datadir = $(DESTDIR)${datarootdir}
asydir = $(datadir)/asymptote
GUIdir = $(asydir)/GUI
docdir = $(DESTDIR)/tmp/ainst/share/doc/asymptote
exampledir = $(docdir)/examples
animationsdir = $(exampledir)/animations
latexdir = $(DESTDIR)/tmp/ainst/latex/asymptote
contextdir = $(DESTDIR)/tmp/ainst/context/asymptote
INSTALL = /usr/bin/install -c
REVISION = "const char *REVISION="
last = $(shell cat revision.cc | sed -e 's/.*\"\(.*\)\";/\1/')
usinggit = $(shell if test -d ".git"; then echo yes; fi)
ifeq ($(usinggit),yes)
	revision = $(shell LC_ALL="C" git describe --long | sed -e 's/git//' \
                    | sed -e 's/-g.*//')
else
	revision = 2.41
endif

export prefix docdir exampledir mandir infodir INSTALL MAKE DESTDIR TEXI2DVI

asy:	version
	if test -n "$(MSDOS)"; then \
          $(CXX) $(OPTS) -o $(NAME) $(FILES:=.o) revision.o asy.o $(DOSLIBS); \
	else \
	  ln -sf GUI/xasy.py $(XNAME); \
	  $(CXX) $(OPTS) -o $(NAME) $(FILES:=.o) revision.o $(LIBS); \
	fi

version: $(GCLIB) $(FILES:=.o)
	if test ! -s revision.cc -o "$(revision)" != "$(last)"; then     \
	  echo $(REVISION)\"$(revision)\"\; > revision.cc; \
	fi
	$(CXX) $(OPTS) $(INCL) -o revision.o -c revision.cc;

	echo string VERSION=\"$(revision)\"\; > base/version.asy
	echo @set VERSION $(revision) > doc/version.texi
	echo @set Datadir ${datarootdir} >> doc/version.texi

	echo "#!/usr/bin/env python" > GUI/xasyVersion.py
	echo xasyVersion = \"$(revision)\" >> GUI/xasyVersion.py

	if test -n "$(MSDOS)"; then \
	  cat asy.rc | sed -e "s/ASYMPTOTE_VERSION/$(revision)/" | \
	  windres -o asy.o; \
	fi

asymptote.so: $(COREFILES:=.pic.o)
	$(CXX) $(OPTS) -shared -o asymptote.so revision.o $(COREFILES:=.pic.o) $(SHAREDLIBS)

all:  	asy sty man faq asy-keywords.el

$(GCLIB): $(GC).tar.gz
	gunzip -c $(GC).tar.gz > $(GC).tar
	tar -xf $(GC).tar
	rm -f $(GC).tar
	if test -r $(LIBATOMIC).tar.gz; then \
	  gunzip -c $(LIBATOMIC).tar.gz > $(LIBATOMIC).tar; \
	  tar -xf $(LIBATOMIC).tar; \
	  rm -f $(LIBATOMIC).tar; \
          mv $(LIBATOMIC) $(GC)/libatomic_ops; \
	fi
	if test "$(GC)" = "gc-7.0"; then \
	  cd $(GC)/include/private && \
            patch < ../../../patches/gc-7.0nomem.patch; \
	fi
	if test "$(GC)" = "gc-7.2b"; then \
	  mv gc-7.2 gc-7.2b; \
	fi
	if test "$(GC)" = "gc-7.2c"; then \
	  mv gc-7.2 gc-7.2c; \
	fi
	if test "$(GC)" = "gc-7.2d"; then \
	  mv gc-7.2 gc-7.2d; \
	fi
	cd $(GC) && \
	./configure CC="$(CC)" CXX="$(CXX)" $(GCOPTIONS); \
	$(MAKE) check

$(GCPPLIB): $(GCLIB)

sty:
	cd doc && $(MAKE) asy-latex.pdf

dvi:	asy sty
	cd doc && $(MAKE) dvi

html:	asy sty
	cd doc && $(MAKE) doc

man:	asy sty
	cd doc && $(MAKE) man

faq:	asy sty
	cd doc && $(MAKE) faq

$(RUNTIME_FILES:=.cc): %.cc: runtime.pl opsymbols.h runtimebase.in %.in
	$(PERL) ./runtime.pl $(@:.cc=)

$(SYMBOL_FILES:=.symbols.h): %.symbols.h: findsym.pl %.cc
	$(CXX) -E -DNOSYM $(OPTS) $(INCL) $(@:.symbols.h=.cc) | \
          $(PERL) ./findsym.pl $@ -

$(SYMBOL_FILES:=.o): %.o: %.symbols.h

allsymbols.h: findsym.pl $(SYMBOL_FILES:=.cc)
	$(CXX) -E -DNOSYM $(OPTS) $(INCL) $(SYMBOL_FILES:=.cc) | \
          $(PERL) ./findsym.pl $@ -

symbol.o: opsymbols.h allsymbols.h

camp.tab.cc: camp.y
	$(BISON) -dvt -b camp camp.y && mv camp.tab.c camp.tab.cc

camp.tab.h: camp.tab.cc

lex.yy.cc: camp.l
	$(LEX) -d -olex.yy.cc camp.l

lex.yy.d: $(GCLIB) lex.yy.cc camp.tab.h

keywords.cc: keywords.pl camp.l process.cc
	$(PERL) ./keywords.pl

opsymbols.h: opsymbols.pl camp.l
	$(PERL) ./opsymbols.pl

envcompleter.d: keywords.cc

asy-keywords.el: asy
	@echo Creating $@;
	$(ASY) -l > asy.list
	ls $(addsuffix /*.asy,$(KEYWORDS)) | grep -v plain\* | \
          grep -v three_\* | grep -v featpost3D | xargs $(ASY) -l >> asy.list
	$(PERL) ./asy-list.pl asy.list $(revision)

install: asy-keywords.el install-texhash install-man

install-all: install install-html

install-texhash: install-asy
	-if test -z "$(DESTDIR)"; then \
	  texhash; \
	fi

install-asy: asy sty
	${INSTALL} -d $(bindir) $(asydir) $(GUIdir) $(exampledir) \
          $(animationsdir)
	-${INSTALL} -d $(latexdir)
	-${INSTALL} -d $(contextdir)
	${INSTALL} -p -m 755 $(NAME) $(bindir)
	${INSTALL} -p -m 644 base/*.asy $(addprefix base/,$(EXTRA)) \
		asy-keywords.el $(asydir)
	${INSTALL} -p -m 755 GUI/*.py $(GUIdir)
	ln -sf ${datarootdir}/asymptote/GUI/xasy.py $(bindir)/$(XNAME)
	${INSTALL} -p -m 644 examples/*.asy $(addprefix examples/,$(EXEXTRA)) \
	  doc/extra/*.asy $(addprefix doc/,$(DOCEXTRA)) $(exampledir)
	${INSTALL} -p -m 644 examples/animations/*.asy \
          examples/animations/inlinemovie.tex \
	  examples/animations/inlinemovie3.tex $(animationsdir)
	-${INSTALL} -p -m 644 $(addprefix doc/,$(LATEXFILES)) $(latexdir)
	-${INSTALL} -p -m 644 $(addprefix doc/,$(CONTEXTFILES)) $(contextdir)

install-html: html
	cd doc && $(MAKE) install-all

install-man: man
	cd doc && $(MAKE) install

install-prebuilt: install-asy
	cd doc && $(MAKE) install-prebuilt

uninstall: uninstall-all

uninstall-all: uninstall-man uninstall-asy uninstall-docdir

uninstall-asy:
	-cd $(animationsdir) && rm -f *.asy *.tex
	-rmdir $(animationsdir)
	-cd $(exampledir) && rm -f $(EXEXTRA) $(DOCEXTRA)
	-rmdir $(exampledir)
	-cd $(GUIdir) && rm -f *.py
	-rmdir $(GUIdir)
	-cd $(asydir) && rm -f asy-keywords.el *.asy $(EXTRA)
	-rmdir $(asydir)
	-cd $(latexdir) && rm -f $(LATEXFILES)
	-rmdir $(latexdir)
	-cd $(contextdir) && rm -f $(CONTEXTFILES)
	-rmdir $(contextdir)
	-cd $(bindir) && rm -f $(NAME) $(XNAME)

uninstall-man: 
	cd doc && $(MAKE) uninstall

uninstall-docdir:
	-rmdir $(docdir)

clean:  FORCE
	-rm -f asy asymptote.so *.pic.o *.o *.d *mon.out $(CLEAN)

gc-clean: FORCE clean
	-if test -d $(GC); then \
		$(MAKE) -C $(GC) clean; \
	fi

cleaner: FORCE clean
	-if test -d $(GC); then \
		rm -rf $(GC); \
	fi
	-rm -f Makefile config.h config.log config.status errors.temp
	cd doc && $(MAKE) clean
	cd tests && $(MAKE) distclean

distclean: FORCE cleaner
	cd doc && $(MAKE) distclean

cleanest: FORCE maintainer-clean
maintainer-clean: FORCE distclean
	-rm -f configure config.h.in $(DIST)
	-rm -rf autom4te.cache

check: asy FORCE
	./wce
	$(MAKE) -C tests

check-all: asy FORCE
	./wce
	$(MAKE) -C tests all

.SUFFIXES: .c .cc .o .d
.cc.o:
	$(CXX) $(OPTS) $(INCL) -o $@ -c $<
.cc.d:
	@echo Creating $@; \
	rm -f $@; \
	${CXX} $(MAKEDEPEND) $(INCL) $(MDOPTS) $< > $@.$$$$ 2>/dev/null && \
	sed 's,\($*\)\.o[ :]*,\1.o \1.pic.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$
.c.d:
	@echo Creating $@; \
	rm -f $@; \
	${CC} $(MAKEDEPEND) $(INCL) $(MDOPTS) $< > $@.$$$$ 2>/dev/null && \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

# Compile for the shared library.  OpenGL must be disabled as it causes
# crashes inside a shared library.
%.pic.o: %.cc
	$(CXX) $(SHAREDOPTS) $(INCL) -o $@ -c $<

ifeq (,$(findstring clean,${MAKECMDGOALS}))
-include $(FILES:=.d)
endif

FORCE:

configure: configure.ac
	autoheader && autoconf

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck

