# Makefile for gtool4/src

# in Config.mk, DEST_LIB, DEST_INC is defined
include ../Config.mk

TARGET=libgtool4.a

all: $(TARGET)

install: $(TARGET)
	test -d $(DEST_LIB) || install -d $(DEST_LIB)
	test -d $(DEST_INC) || install -d $(DEST_INC)
	install -m 644 $(TARGET) $(DEST_LIB)
	install -m 644 $(MODS) $(MODINCS) $(DEST_INC)
	if [ X$(F90MODTYPE) = X"intel.d" ]; then \
		install -m 644 work.pc $(DEST_INC)/work.pc ;\
	fi

.SUFFIXES: .html

.f90.html:
	sed 's/^[	 ]*!//' $< > $<.rd
	rd2 -r rd/rd2html-lib --with-css=style.css  $<.rd > $@.tmp
	mv $@.tmp $@
	rm -f $<.rd

HTML = \
      gtool_history.html \
      sysdep.html

doc: $(HTML)

OBJS_A = \
      sysdepabort-$(SYSDEPABORT).o \
      sysdeparg-$(SYSDEPARG).o \
      dcstring_base.o dcstring_list.o regex.o \
      dcstringbase_warnlim.o \
      dcstringsprintf.o \
      dcstringprintf.o dcstringfprintf.o dcstringcprintf.o \
      dc_trace.o \
      dc_string.o dc_types.o netcdf_f77.o sysdep.o \
      dc_error.o dc_url.o dc_units.o dcunits_com.o \
      an_types.o an_generic.o an_file.o an_vartable.o \
      anvarputattrchar.o anvarputattrint.o anvarputattrreal.o \
      anvarattr.o anvarattrtrue.o anvarclose.o anvarcreate.o \
      anvaropen.o \
      anattrgetreal.o \
      anattrgetdouble.o \
      anattrgetint.o \
      anattrgetchar.o \
      anvardelattr.o anvarsearch.o anvarsync.o anvarcreated.o \
      anattrinquire.o anvarattrcopy.o \
      anvarinquire.o \
      anvarinquire-ia.o \
      anvaropenbydimord.o anvartostring.o \
      anattrinquire.o \
      anxtypename.o \
      anvargetreal.o \
      anvargetdouble.o \
      anvarputreal.o \
      ansearchdim.o \
      anvarputdouble.o

OBJS_D = $(OBJS_A) \
      gt_mem.o \
      gt_vartable.o \
      gt_args.o \
      gt_argtable.o \
      gtargget.o \
      gtargcount.o \
      gtdata_types.o \
      gtdata_generic.o \
      gtdata_internal.o \
      gt_vartable.o \
      gt_map.o \
      gtvardeldim.o \
      gtvaradddim.o \
      gtvarexchdim.o \
      gtdim_name2ord.o \
      gtdatatmpnam.o \
      gtvargetattrsc.o \
      gtvarsync.o \
      gtvargetslice.o \
      gtvarcopyattr.o \
      gtvarcopyattrall.o \
      gtvarcreatecopy.o \
      gtvargetattr.o \
      gtvarattrtrue.o \
      gtvardelattr.o \
      gtvarputattrchar.o \
      gtvaraddmember.o \
      gtvaropen.o \
      gtvarclose.o \
      gtvaropenbydimord.o \
      gtvarcreate.o \
      gtvarslice.o \
      gtvarslicenext.o \
      gtvarcreate.o \
      gtvarsliceauto.o \
      gtvargetsliceall.o \
      gtvarputline.o \
      gtvarsearch.o \
      gtvarattrsearch.o \
      gtvargetreal.o \
      gtvargetdouble.o \
      gtvarputreal.o \
      gtvarputdouble.o \
      gtvarinquire.o \
      gtvarinquire2.o \
      gtvarlimit.o \
      gtvarlimitbinary.o \
      gtvarcreated.o \
      gtvargetreal1.o \
      gtvargetreal2.o \
      gtvarequivalent.o \
      gtool.o \
      gtool_history.o \
      hscrea.o hsavar.o hsclse.o \
      hsaatc.o hsaatr.o hsaatd.o hsaati.o \
      hsp1r.o hsp2d.o hsp3d.o hsp1d.o hsp2r.o hsp3r.o 

OBJS = $(OBJS_D) \
      gtgraph_types.o gtgraph_generic.o gtgraph_com.o gtgraph_drawparam.o \
      gtgraphsavename.o gtfigsave.o gtcontsave.o gtaxissave.o \
      gtfigdisplay.o gtframe.o gtstringquotefordcl.o \
      gtfigputobject.o gtfigload.o gtframeload.o gtcontload.o gtlineload.o \
      gtdev.o gtfig.o gtcontlib.o gtlinelib.o gtaxis.o gtaxisload.o \
      gtaxisequivalent.o \
      gtobjectopen.o gtlinesave.o gtvectlib.o

$(OBJS):

$(OBJS): work.pcl

work.pcl: Makefile ../Config.mk
	sh ../chkpcl.sh $(SYSFFLAGS)

an: $(OBJS_A)
	$(AR) $(TARGET) $(OBJS_A)

gtdata: $(OBJS_D)
	$(AR) $(TARGET) $(OBJS_D)

$(TARGET): $(OBJS)
	$(AR) $@ $(OBJS)

# files generated with m4

anattrgetreal.f90: anattrgettype.m4
	m4 -Dtype=REAL $< > $@

anattrgetdouble.f90: anattrgettype.m4
	m4 -Dtype=DOUBLE $< > $@

anattrgetint.f90: anattrgettype.m4
	m4 -Dtype=INT $< > $@

anvargetreal.f90: anvargettype.m4
	m4 -Dtype=REAL $< > $@

anvargetdouble.f90: anvargettype.m4
	m4 -Dtype=DOUBLE $< > $@

gtvargetreal.f90: gtvargettype.m4
	m4 -Dtype=REAL $< > $@

gtvargetdouble.f90: gtvargettype.m4
	m4 -Dtype=DOUBLE $< > $@

anvarputreal.f90: anvarputtype.m4
	m4 -Dtype=REAL $< > $@

anvarputdouble.f90: anvarputtype.m4
	m4 -Dtype=DOUBLE $< > $@

gtvarputreal.f90: gtvarputtype.m4
	m4 -Dtype=REAL $< > $@

gtvarputdouble.f90: gtvarputtype.m4
	m4 -Dtype=DOUBLE $< > $@

sysdep-src: sysdeparg-dcl.f90 sysdeparg-common.f90 \
	sysdeparg-hitachi.f90 \
	sysdepabort-dcl.f90 sysdepabort-abort.f90 \
	sysdepabort-exit.f90 sysdepabort-stop.f90 \
	sysdepabort-setrcd.f90 sysdepabort-errtra-setrcd.f90

sysdeparg-dcl.f90: sysdeparg.m4
	m4 -Dargtype=DCL $< > $@

sysdeparg-common.f90: sysdeparg.m4
	m4 -Dargtype=COMMON $< > $@

sysdeparg-hitachi.f90: sysdeparg.m4
	m4 -Dargtype=HITACHI $< > $@

sysdepabort-dcl.f90: sysdepabort.m4
	m4 -Daborttype=DCL $< > $@

sysdepabort-abort.f90: sysdepabort.m4
	m4 -Daborttype=ABORT $< > $@

sysdepabort-exit.f90: sysdepabort.m4
	m4 -Daborttype=EXIT $< > $@

sysdepabort-stop.f90: sysdepabort.m4
	m4 -Daborttype=STOP $< > $@

sysdepabort-setrcd.f90: sysdepabort.m4
	m4 -Daborttype=SETRCD $< > $@

sysdepabort-errtra-setrcd.f90: sysdepabort.m4
	m4 -Daborttype=ERRTRA-SETRCD $< > $@

clean:
	-rm -f $(MODS) *.o $(TARGET) work.pc*

depend: f90depend.pl Makefile
	perl f90depend.pl -Xdcl.o *.f90 > depend

include depend

tags: $(OBJS:.o=.f90)
	perl f90tags $(OBJS:.o=.f90)
