1# @configure_input@
2
3ARCH = unix
4POLL = poll
5
6GCVERSION = @GCVERSION@
7GC = gc-$(GCVERSION)
8LIBATOMIC = libatomic_ops-$(GCVERSION)
9GCOPTIONS = @GCOPTIONS@
10GCLIB = @GCLIB@
11GCPPLIB = @GCPPLIB@
12GCLIBS = $(GCPPLIB) $(GCLIB)
13LFLAGS = @LDFLAGS@
14LIBS = $(LFLAGS) @PTHREAD_LIBS@ @LIBS@ $(GCLIBS)
15
16# Libraries needed to make asymptote.so.
17# We have to remove OpenGL, threading, GC, etc from this.
18SHAREDLIBS = $(filter-out -lGL -lGLU -lglut -pthread $(GCLIBS), $(LIBS))
19
20vpath %.cc prc
21
22CAMP = camperror path drawpath drawlabel picture psfile texfile util settings \
23       guide flatguide knot drawfill path3 drawpath3 drawsurface pen pipestream
24
25RUNTIME_FILES = runtime runbacktrace runpicture runlabel runhistory runarray \
26	runfile runsystem runpair runtriple runpath runpath3d runstring \
27	runmath
28
29# Files to be scanned for pre-translated symbols defined by SYM(name).
30SYMBOL_FILES = types builtin gsl $(RUNTIME_FILES)
31
32PRC =  PRCbitStream oPRCFile PRCdouble writePRC
33
34COREFILES = $(CAMP) $(SYMBOL_FILES) env genv stm dec errormsg \
35        callable name symbol entry exp newexp stack camp.tab lex.yy \
36	access virtualfieldaccess absyn record interact fileio \
37	fftw++asy simpson coder coenv impdatum \
38	@getopt@ locate parser program application varinit fundec refaccess \
39	envcompleter process constructor array Delaunay predicates \
40	$(PRC) glrender tr arcball algebra3 quaternion
41
42FILES = $(COREFILES) main
43
44DIST = camp.tab.h camp.tab.cc lex.yy.cc runtime.cc keywords.cc \
45	asy-keywords.el $(RUNTIME_FILES:=.cc) $(RUNTIME_FILES:=.h) asy.list \
46        allsymbols.h opsymbols.h $(SYMBOL_FILES:=.symbols.h)
47NAME = asy
48XNAME = x$(NAME)
49CLEAN = camp.output svnrevision.cc base/version.asy doc/version.texi \
50        GUI/xasyVersion.py $(XNAME) doc/asy-latex.pdf
51EXTRA = asy-mode.el asy-init.el asy.vim asy_filetype.vim asy-kate.sh \
52        asymptote.py reload.js nopapersize.ps
53EXEXTRA = piicon.eps *.views *.dat *.bib
54DOCEXTRA = *.asy *.csv *.dat latexusage.tex externalprc.tex pixel.pdf
55KEYWORDS = base $(ASYMPTOTE_SITEDIR)
56LATEXFILES = asymptote.sty asycolors.sty ocg.sty latexmkrc
57CONTEXTFILES = colo-asy.tex
58ASY = ./asy -dir base -config "" -render=0
59
60DEFS = @DEFS@ @OPTIONS@ @PTHREAD_CFLAGS@ -DFFTWPP_SINGLE_THREAD
61CFLAGS = @CXXFLAGS@ @CFLAGS@
62OPTS = $(DEFS) @CPPFLAGS@ $(CFLAGS)
63INCL = -I. @INCL@
64
65# Options for compiling the object files for the shared library.
66# gc has to be configured with the option --disable-threads in order to make a
67# shared library that doesn't seg fault.  For now, just disable gc in the
68# shared library.
69SHAREDOPTS = $(filter-out -DUSEGC, $(DEFS)) $(CFLAGS) -fPIC -DFOR_SHARED
70
71CXX = @CXX@ -Wall
72CC = @CC@ -Wall
73MAKEDEPEND = $(OPTS) -O0 -M -DDEPEND
74BISON = bison
75LEX = @LEX@
76
77prefix = @prefix@
78exec_prefix = @exec_prefix@
79datarootdir = @datarootdir@
80bindir = $(DESTDIR)@bindir@
81mandir = $(DESTDIR)@mandir@
82infodir = $(DESTDIR)@infodir@
83datadir = $(DESTDIR)@datadir@
84asydir = $(datadir)/asymptote
85GUIdir = $(asydir)/GUI
86docdir = $(DESTDIR)@docdir@
87exampledir = $(docdir)/examples
88animationsdir = $(exampledir)/animations
89latexdir = $(DESTDIR)@latexdir@
90contextdir = $(DESTDIR)@contextdir@
91INSTALL = @INSTALL@
92REVISION = "const char *SVN_REVISION="
93last = `cat svnrevision.cc | sed -e 's/.*\"\(.*\)\";/\\1/'`
94
95export prefix docdir exampledir mandir infodir INSTALL MAKE DESTDIR TEXI2DVI
96
97asy:	version
98	if test -n "$(MSDOS)"; then \
99	  $(CXX) $(OPTS) -o $(NAME) $(FILES:=.o) svnrevision.o asy.o $(LIBS) -s -static; \
100	else \
101	  ln -sf GUI/xasy.py $(XNAME); \
102	  $(CXX) $(OPTS) -o $(NAME) $(FILES:=.o) svnrevision.o $(LIBS); \
103	fi
104
105version: $(GCLIB) $(FILES:=.o)
106	$(eval revision := "")
107	if test "$(findstring svn,@PACKAGE_VERSION@)" = "svn"; then \
108	  $(eval revision := `LC_ALL="C" svn info 2>/dev/null | grep 'Revision' | sed -e 's/Revision: \(.*\)/-r\1/'`) \
109	  if test "$(revision)" != "$(last)"; then \
110	    echo $(REVISION)\"$(revision)\"\; > svnrevision.cc; \
111	    $(CXX) $(OPTS) $(INCL) -o svnrevision.o -c svnrevision.cc; \
112          fi \
113	else \
114          echo $(REVISION)\"\"\; > svnrevision.cc; \
115	  $(CXX) $(OPTS) $(INCL) -o svnrevision.o -c svnrevision.cc; \
116	fi
117
118	echo string VERSION=\"@VERSION@$(revision)\"\; > base/version.asy
119	echo @set VERSION @VERSION@$(revision) > doc/version.texi
120	echo @set Datadir @datadir@ >> doc/version.texi
121
122	echo "#!/usr/bin/env python" > GUI/xasyVersion.py
123	echo xasyVersion = \"@VERSION@$(revision)\" >> GUI/xasyVersion.py
124
125	if test -n "$(MSDOS)"; then \
126	  cat asy.rc | sed -e "s/ASYMPTOTE_VERSION/@VERSION@$(revision)/" | \
127	  windres -o asy.o; \
128	fi
129
130asymptote.so: $(COREFILES:=.pic.o)
131	$(CXX) $(OPTS) -shared -o asymptote.so svnrevision.o $(COREFILES:=.pic.o) $(SHAREDLIBS)
132
133all:  	asy sty man faq asy-keywords.el
134
135$(GCLIB): $(GC).tar.gz
136	gunzip -c $(GC).tar.gz > $(GC).tar
137	tar -xf $(GC).tar
138	rm -f $(GC).tar
139	if test -r $(LIBATOMIC).tar.gz; then \
140	  gunzip -c $(LIBATOMIC).tar.gz > $(LIBATOMIC).tar; \
141	  tar -xf $(LIBATOMIC).tar; \
142	  rm -f $(LIBATOMIC).tar; \
143          mv $(LIBATOMIC) $(GC)/libatomic_ops; \
144	fi
145	if test "$(GC)" = "gc-7.0"; then \
146	  cd $(GC)/include/private && \
147            patch < ../../../patches/gc-7.0nomem.patch; \
148	fi
149	if test "$(GC)" = "gc-7.2b"; then \
150	  mv gc-7.2 gc-7.2b; \
151	fi
152	if test "$(GC)" = "gc-7.2c"; then \
153	  mv gc-7.2 gc-7.2c; \
154	fi
155	if test "$(GC)" = "gc-7.2d"; then \
156	  mv gc-7.2 gc-7.2d; \
157	fi
158	cd $(GC) && \
159	./configure $(GCOPTIONS); \
160	$(MAKE) check
161
162$(GCPPLIB): $(GCLIB)
163
164sty:
165	cd doc && $(MAKE) asy-latex.pdf
166
167dvi:	asy sty
168	cd doc && $(MAKE) dvi
169
170html:	asy sty
171	cd doc && $(MAKE) doc
172
173man:	asy sty
174	cd doc && $(MAKE) man
175
176faq:	asy sty
177	cd doc && $(MAKE) faq
178
179$(RUNTIME_FILES:=.cc): %.cc: runtime.pl opsymbols.h runtimebase.in %.in
180	perl ./runtime.pl $(@:.cc=)
181
182$(SYMBOL_FILES:=.symbols.h): %.symbols.h: findsym.pl %.cc
183	$(CXX) -E -DNOSYM $(OPTS) $(INCL) $(@:.symbols.h=.cc) | \
184          perl ./findsym.pl $@ -
185
186$(SYMBOL_FILES:=.o): %.o: %.symbols.h
187
188allsymbols.h: findsym.pl $(SYMBOL_FILES:=.cc)
189	$(CXX) -E -DNOSYM $(OPTS) $(INCL) $(SYMBOL_FILES:=.cc) | \
190          perl ./findsym.pl $@ -
191
192symbol.o: opsymbols.h allsymbols.h
193
194camp.tab.cc: camp.y
195	$(BISON) -dvt -b camp camp.y && mv camp.tab.c camp.tab.cc
196
197camp.tab.h: camp.tab.cc
198
199lex.yy.cc: camp.l
200	$(LEX) -d -olex.yy.cc camp.l
201
202lex.yy.d: $(GCLIB) lex.yy.cc camp.tab.h
203
204keywords.cc: keywords.pl camp.l process.cc
205	perl ./keywords.pl
206
207opsymbols.h: opsymbols.pl camp.l
208	perl ./opsymbols.pl
209
210envcompleter.d: keywords.cc
211
212asy-keywords.el: asy
213	@echo Creating $@;
214	$(ASY) -l > asy.list
215	ls $(addsuffix /*.asy,$(KEYWORDS)) | grep -v plain\* | \
216          grep -v three_\* | grep -v featpost3D | xargs $(ASY) -l >> asy.list
217	perl ./asy-list.pl asy.list @VERSION@
218
219install: asy-keywords.el install-texhash install-man
220
221install-all: install install-html
222
223install-texhash: install-asy
224	-if test -z "$(DESTDIR)"; then \
225	  texhash; \
226	fi
227
228install-asy: asy sty
229	${INSTALL} -d $(bindir) $(asydir) $(GUIdir) $(exampledir) \
230          $(animationsdir)
231	-${INSTALL} -d $(latexdir)
232	-${INSTALL} -d $(contextdir)
233	${INSTALL} -p -m 755 $(NAME) $(bindir)
234	${INSTALL} -p -m 644 base/*.asy $(addprefix base/,$(EXTRA)) \
235		asy-keywords.el $(asydir)
236	${INSTALL} -p -m 755 GUI/*.py $(GUIdir)
237	ln -sf @datadir@/asymptote/GUI/xasy.py $(bindir)/$(XNAME)
238	${INSTALL} -p -m 644 examples/*.asy $(addprefix examples/,$(EXEXTRA)) \
239	  doc/extra/*.asy $(addprefix doc/,$(DOCEXTRA)) $(exampledir)
240	${INSTALL} -p -m 644 examples/animations/*.asy \
241          examples/animations/inlinemovie.tex \
242	  examples/animations/inlinemovie3.tex $(animationsdir)
243	-${INSTALL} -p -m 644 $(addprefix doc/,$(LATEXFILES)) $(latexdir)
244	-${INSTALL} -p -m 644 $(addprefix doc/,$(CONTEXTFILES)) $(contextdir)
245
246install-html: html
247	cd doc && $(MAKE) install-all
248
249install-man: man
250	cd doc && $(MAKE) install
251
252install-prebuilt: install-asy
253	cd doc && $(MAKE) install-prebuilt
254
255uninstall: uninstall-all
256
257uninstall-all: uninstall-man uninstall-asy uninstall-docdir
258
259uninstall-asy:
260	-cd $(animationsdir) && rm -f *.asy *.tex
261	-rmdir $(animationsdir)
262	-cd $(exampledir) && rm -f $(EXEXTRA) $(DOCEXTRA)
263	-rmdir $(exampledir)
264	-cd $(GUIdir) && rm -f *.py
265	-rmdir $(GUIdir)
266	-cd $(asydir) && rm -f asy-keywords.el *.asy $(EXTRA)
267	-rmdir $(asydir)
268	-cd $(latexdir) && rm -f $(LATEXFILES)
269	-rmdir $(latexdir)
270	-cd $(contextdir) && rm -f $(CONTEXTFILES)
271	-rmdir $(contextdir)
272	-cd $(bindir) && rm -f $(NAME) $(XNAME)
273
274uninstall-man:
275	cd doc && $(MAKE) uninstall
276
277uninstall-docdir:
278	-rmdir $(docdir)
279
280clean:  FORCE
281	-rm -f asy asymptote.so *.pic.o *.o *.d *mon.out $(CLEAN)
282
283gc-clean: FORCE clean
284	-if test -d $(GC); then \
285		$(MAKE) -C $(GC) clean; \
286	fi
287
288cleaner: FORCE clean
289	-if test -d $(GC); then \
290		rm -rf $(GC); \
291	fi
292	-rm -f Makefile config.h config.log config.status errors.temp
293	cd doc && $(MAKE) clean
294	cd tests && $(MAKE) distclean
295
296distclean: FORCE cleaner
297	cd doc && $(MAKE) distclean
298
299cleanest: FORCE maintainer-clean
300maintainer-clean: FORCE distclean
301	-rm -f configure config.h.in $(DIST)
302	-rm -rf autom4te.cache
303
304check: asy FORCE
305	./wce
306	$(MAKE) -C tests
307
308check-all: asy FORCE
309	./wce
310	$(MAKE) -C tests all
311
312.SUFFIXES: .c .cc .o .d
313.cc.o:
314	$(CXX) $(OPTS) $(INCL) -o $@ -c $<
315.cc.d:
316	@echo Creating $@; \
317	rm -f $@; \
318	${CXX} $(MAKEDEPEND) $(INCL) $(MDOPTS) $< > $@.$$$$ 2>/dev/null && \
319	sed 's,\($*\)\.o[ :]*,\1.o \1.pic.o $@ : ,g' < $@.$$$$ > $@; \
320	rm -f $@.$$$$
321.c.d:
322	@echo Creating $@; \
323	rm -f $@; \
324	${CC} $(MAKEDEPEND) $(INCL) $(MDOPTS) $< > $@.$$$$ 2>/dev/null && \
325	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
326	rm -f $@.$$$$
327
328# Compile for the shared library.  OpenGL must be disabled as it causes
329# crashes inside a shared library.
330%.pic.o: %.cc
331	$(CXX) $(SHAREDOPTS) $(INCL) -o $@ -c $<
332
333ifeq (,$(findstring clean,${MAKECMDGOALS}))
334-include $(FILES:=.d)
335endif
336
337FORCE:
338
339configure: configure.ac
340	autoheader && autoconf
341
342Makefile: Makefile.in config.status
343	./config.status
344
345config.status: configure
346	./config.status --recheck
347
348