#
# This makefile makes the examples in this directory.  There's a good chance
# that you'll need to tweak this a bit to get it working on your system.
#
# To use:
#	Do "make matlab", "make octave", or "make tela" to make the
#	appropriate language binary for the pgplot library.
#	
PERL	  = perl
TOP	  = ../../../..
MV	  = mv

MATWRAP = $(PERL) -w $(TOP)/bin/matwrap

#
# Location of various libraries.  You may need to change these, or add
# a -L switch to specify the directory containing the .a or .so files:
# -lg2c seems to be needed on linux when pgplot is built with g77.
#
PGPLOT_LIBS = -L/usr/X11R6/lib -lcpgplot -lpgplot -lg2c -lX11 -lm


all::
	@echo 'Type "make matlab" to make the matlab example, "make octave"'
	@echo 'to make the octave example, and "make tela" to make the'
	@echo 'tela example.'
	@echo 'You may have to modify the makefile to specify the location'
	@echo 'of the PGPLOT libraries.'
	@false

########################################################################
#
# Instructions for making the matlab modules:
# Note that all of the matlab stub functions go into the directory 'wrap_m'.
#
matlab::
	test -d $(MATLAB_STUBDIR) || mkdir $(MATLAB_STUBDIR)
	$(MAKE) pgplot_matlab.mexaxp


#
# Force mex to use the gnu C++ compiler.
#
MEXVARS = ../mex_cpp.sh

#
# Command to run MEX:
#
MEX = mex -f $(MEXVARS)

#
# Where to put the matlab stub functions.
# This directory must be in your matlab path.
#
MATLAB_STUBDIR = wrap_m

pgplot_matlab.mexaxp: cpgplot.h
	$(MATWRAP) -language matlab $< \
		-o pgplot_matlab.c -outdir $(MATLAB_STUBDIR)
	$(MEX) pgplot_matlab.c $(PGPLOT_LIBS)

########################################################################
#
# Instructions for making the octave modules:
#
MKOCTFILE = mkoctfile
					# $(TOP)/share/matwrap/mkoctfile_fixed

octave:: pgplot_octave.oct

pgplot_octave.oct: cpgplot.h
	$(MATWRAP) -language octave $< \
		-o pgplot_octave.cc -stub pgplot_stub.m
	$(MKOCTFILE) pgplot_octave.cc $(PGPLOT_LIBS)

#
# Instructions for making the corrected mkoctfile script:
#
$(TOP)/share/matwrap/mkoctfile_fixed:
	$(TOP)/share/matwrap/fix_mkoctfile.sh $(TOP)/share/matwrap

########################################################################
#
# Instruction for making the tela modules:
#
TELAKKA	  = telakka

tela:: tela_pgplot

tela_pgplot: cpgplot.h
	$(MATWRAP) -language tela $< -o tela_pgplot.ct
	@echo Ignore warning messages about symbol index out of range,
	@echo if they appear.
	$(TELAKKA) tela_pgplot.ct $(PGPLOT_LIBS)
	$(MV) tela tela_pgplot

########################################################################
#
#
clean::
	$(RM) -rf $(MATLAB_STUBDIR) *.o *_matlab.c *_octave.cc *.mexaxp *.oct \
	octave-core so_locations *.ct tela_pgplot
