# Makefile for the MATLAB C Math Library Examples.
# Requires GNU make.  Will not work with ordinary make.
#
# Peter Webb, Sept. 1995

SHELL=/bin/sh

# Edit the definition of MATLAB_ROOT to reflect the location of the
# MATLAB root directory on your system.
#MATLAB_ROOT = /usr/local/matlab
MATLAB_ROOT = /tmp_mnt/export/home/c0t0d0s6/misc/matlabph/matlab-4.2c

# Where to look for the include files
INCDIR = $(MATLAB_ROOT)/extern/include

# Where to look for the libraries
LIBDIR = $(MATLAB_ROOT)/extern/lib/$(ARCH)

# Default values for SYSLIBS (the math library is required on every
# platform) and MWOPT (build with default optimization).
SYSLIBS = -lm

ifndef $MWOPT
MWOPT = -O
endif

# Pass DEBUG=1 to gmake to build with optimization off, debug on.
# The default is to build with optimization turned on.

ifeq ($(DEBUG),1)
MWOPT = -g
endif

# Variable settings for each supported platform.  Make sure your ARCH
# environment variable is set to one of these:
#
#	sun4 	: Sun running SunOS 4.x
#	sol2 	: Sun running Solaris 2.x
#	hp700 	: HP700 running HPUX
#	alpha   : DEC's Alpha, running Digital UNIX
#	ibm_rs  : IBM RS6000, running AIX
#	sgi     : SGI R4000, running IRIX

# Platform specific defines.  Edit at your own discretion.

ifeq ($(ARCH),sun4)
  CC=/usr/lang/acc
  CPPFLAGS= -I$(INCDIR)

# Use these three lines instead if using the GNU compiler
# CC=gcc
# CFLAGS= -ansi
# CPPFLAGS= -I$(INCDIR) -Dsparc

endif

ifeq ($(ARCH),sol2)
  CFLAGS= -Xa -xlibmieee -xlibmil
  CPPFLAGS= -I$(INCDIR)
endif

ifeq ($(ARCH),hp700)
CC = cc
  CFLAGS= -Aa
  CPPFLAGS=-I$(INCDIR) -D_HPUX_SOURCE
endif

ifeq ($(ARCH),sgi)
  CPPFLAGS=-I$(INCDIR)
  SYSLIBS=-lblas -lm
endif

ifeq ($(ARCH),ibm_rs)
  CFLAGS= -qfloat=nomaf
  CPPFLAGS=-I$(INCDIR) -qlanglvl=ansi -D_ALL_SOURCE
endif 

ifeq ($(ARCH),alpha)
  CFLAGS= -ieee_with_no_inexact -assume noaccuracy_sensitive
  CPPFLAGS= -I$(INCDIR) -std1
  SYSLIBS=-lots -lm
endif

ARCH_DIR = bin/$(ARCH)

# If you're having trouble with this file, truncate it to zero-length.
include make.depend

LIBS = -L$(LIBDIR) -ltbx -lmcc -lmatlb $(SYSLIBS)


$(ARCH_DIR)/%.o :: %.c
	$(CC) $(MWOPT) $(CPPFLAGS) $(CFLAGS) -c $< -o $(ARCH_DIR)/$*.o

$(ARCH): 
	-@touch $(ARCH)
	-@if [ ! -d bin ] ; then mkdir bin ; fi
	-@if [ ! -d $(ARCH_DIR) ] ; then mkdir $(ARCH_DIR) ; fi

targets = ex1 ex2 ex3 ex4 ex5 
ALL_OFILES = $(targets:%=%.o)

all: $(targets)

$(targets) : %: %.$(ARCH)
	-@touch $@.$(ARCH)

platforms = $(targets:%=%.$(ARCH))

$(platforms):  %.$(ARCH): $(ARCH) $(ARCH_DIR)/%.o
	rm -f $@
	$(CC) -o $(ARCH_DIR)/$@ $(ARCH_DIR)/$(@:.$(ARCH)=.o) $(LIBPATH) $(LIBS) $(ARCH_LIBS)
	ln -s $(ARCH_DIR)/$@ $@

depend:
	$(CC) $(CFLAGS) $(CPPFLAGS) -MM $(platforms:.$(ARCH)=.c) > make.depend

clean:
	$(RM) -r $(ARCH_DIR) *.$(ARCH) $(ARCH)

exec: all 
	-ex1.$(ARCH)
	-ex2.$(ARCH)
	-ex3.$(ARCH)
	-ex4.$(ARCH)
	-ex5.$(ARCH)

