#
#       Makefile for the clawpack code:
#
#       To make an executable, type:             make xclaw
#       (from the application sub-directory)
#
#       To make an executable that generates
#       output in HDF (version 4) format:         make xclawhdf
#       For this work work you may need to
#       set the HDFLIBS properly below.
#
#       To compile a single file.f:               make file.o
#
#       To compile the lib library files:         make 
#
#       To combine all source files:              make program
#       (sometimes easier to debug all in one)
#
#       To clean up files created by make:        make clean
#       Deletes *.o, x*, htmls
#       This does not delete fort.* files or
#       graphics files.
#       running the plotclaw.py script
#

FFLAGS = -O
LFLAGS = $(FFLAGS)
LINK   = $(FC)

# using make htmls requires having clawcode2html from Clawpack:
CC2HTML = python clawcode2html.py --force --nojsmath

# how to make .o files from .f files:
%.o : %.f ; $(FC) $(FFLAGS) -c $< -o $@

SOURCES = \
  driver.f \
  qinit.f \
  rpn2ad1.f \
  rpt2ad1.f \
  setaux.f \
  mapc2p.f \
  stream.f \
  setprob.f \

LIBSOURCES = \
  lib/src2.f \
  lib/b4step2.f \
  lib/bc2.f \
  lib/claw2ez.f \
  lib/claw2.f \
  lib/step2.f \
  lib/step2ds.f \
  lib/dimsp2.f \
  lib/flux2.f \
  lib/limiter.f \
  lib/philim.f \
  lib/copyq2.f \
  lib/out2.f \
  lib/restart2.f


# make list of .o files required from the sources above:
OBJECTS = $(subst .f,.o, $(SOURCES))
LIBOBJECTS = $(subst .f,.o, $(LIBSOURCES))

# make list of html files to be created by 'make htmls':
HTML = \
  README.html \
  clawcode2html.html \
  $(subst .f,.f.html,$(wildcard *.f)) \
  $(subst .data,.data.html,$(wildcard *.data)) \
  $(subst .py,.py.html,$(wildcard *.py))


#----------------------------------------------------------------------------


xclaw: $(OBJECTS) $(LIBOBJECTS) 
	$(LINK) $(LFLAGS) $(OBJECTS) $(LIBOBJECTS)  -o xclaw

program : $(SOURCES) $(LIBSOURCES) $(OUTSOURCES)
	cat $(SOURCES) $(LIBSOURCES) $(OUTSOURCES) > clawprogram.f

# To make individual html files:  (e.g. 'make qinit.f.html'):
%.py.html : %.py ; $(CC2HTML) $<
%.f.html : %.f ; $(CC2HTML) $<
%.data.html : %.data ; $(CC2HTML) $<
README.html : README ; $(CC2HTML) --noheader README
clawcode2html.html : clawcode2html ; $(CC2HTML) --noheader clawcode2html

htmls: $(HTML) ;

clean:
	-rm -f $(OBJECTS) xclaw*  $(HTML)

### DO NOT remove this line - make depends on it ###
