# set path to CGNS library

include ../make.defs

CALCDIR = ../calclib
CALCLIB = $(CALCDIR)/libcgnscalc.$(A)

COPTS  = $(CFLAGS) -I../common -I$(CGNSDIR)
LDLIST = $(CGNSLIB) $(BUILDLIBS) $(CLIBS)

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

ALL = \
	plot3d_to_cgns$(EXE) \
	cgns_to_plot3d$(EXE) \
	patran_to_cgns$(EXE) \
	tecplot_to_cgns$(EXE) \
	cgns_to_tecplot$(EXE) \
	cgns_to_vtk$(EXE) \
	tetgen_to_cgns$(EXE) \
	vgrid_to_cgns$(EXE) \
	aflr3_to_cgns$(EXE) \
	cgns_to_aflr3$(EXE) \
	fast_to_cgns$(EXE) \
	cgns_to_fast$(EXE) \
	convert_location$(EXE) \
	convert_variables$(EXE) \
	convert_dataclass$(EXE) \
	extract_subset$(EXE) \
	interpolate_cgns$(EXE)

OTHERS = \
	cgns_info$(EXE) \
	vertex_to_cell$(EXE) \
	cell_to_vertex$(EXE)

SCRIPTS = \
	utilities.mnu \
	plot3d.tcl \
	patran.tcl \
	tecplot.tcl \
	tetgen.tcl \
	vgrid.tcl \
	aflr3.tcl \
	fast.tcl \
	vtk.tcl \
	convert.tcl \
	util.tcl

CNVFILES = \
	primitive.cnv \
	conserved.cnv \
	dimensional.cnv

all : $(ALL)
others : $(OTHERS)
everything : $(ALL) $(OTHERS)

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

cgns_info$(EXE) : cgns_info.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ cgns_info.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

cgns_info.$(O) : cgns_info.c cgnsutil.h

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

plot3d_to_cgns$(EXE) : plot3d_to_cgns.$(O) cgnsutil.$(O) binaryio.$(O) \
		       getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ plot3d_to_cgns.$(O) cgnsutil.$(O) \
	binaryio.$(O) getargs.$(O) $(LDLIST)
	$(STRIP) $@

plot3d_to_cgns.$(O) : plot3d_to_cgns.c cgnsutil.h binaryio.h

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

cgns_to_plot3d$(EXE) : cgns_to_plot3d.$(O) cgnsutil.$(O) getargs.$(O) \
		       p3dfout.$(O)
	$(CC) $(LDFLAGS) -o $@ cgns_to_plot3d.$(O) cgnsutil.$(O) \
	getargs.$(O) p3dfout.$(O) $(LDLIST)
	$(STRIP) $@

cgns_to_plot3d.$(O) : cgns_to_plot3d.c cgnsutil.h
p3dfout.$(O)	    : p3dfout.c binaryio.h

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

patran_to_cgns$(EXE) : patran_to_cgns.$(O) cgnsImport.$(O) getargs.$(O) \
		       hash.$(O)
	$(CC) $(LDFLAGS) -o $@ patran_to_cgns.$(O) cgnsImport.$(O) \
	getargs.$(O) hash.$(O) $(LDLIST)
	$(STRIP) $@

patran_to_cgns.$(O) : patran_to_cgns.c cgnsImport.h

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

tecplot_to_cgns$(EXE) : tecplot_to_cgns.$(O) cgnsImport.$(O) getargs.$(O) \
			hash.$(O)
	$(CC) $(LDFLAGS) -o $@ tecplot_to_cgns.$(O) cgnsImport.$(O) \
	getargs.$(O) hash.$(O) $(LDLIST)
	$(STRIP) $@

tecplot_to_cgns.$(O) : tecplot_to_cgns.c cgnsImport.h

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

cgns_to_tecplot$(EXE) : cgns_to_tecplot.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ cgns_to_tecplot.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

cgns_to_tecplot.$(O) : cgns_to_tecplot.c cgnsutil.h

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

cgns_to_vtk$(EXE) : cgns_to_vtk.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ cgns_to_vtk.$(O) getargs.$(O) $(LDLIST)
	$(STRIP) $@

cgns_to_vtk.$(O) : cgns_to_vtk.c

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

tetgen_to_cgns$(EXE) : tetgen_to_cgns.$(O)
	$(CC) $(LDFLAGS) -o $@ tetgen_to_cgns.$(O) $(LDLIST)
	$(STRIP) $@

tetgen_to_cgns.$(O) : tetgen_to_cgns.c

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

vgrid_to_cgns$(EXE) : vgrid_to_cgns.$(O) binaryio.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ vgrid_to_cgns.$(O) binaryio.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

vgrid_to_cgns.$(O) : vgrid_to_cgns.c

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

aflr3_to_cgns$(EXE) : aflr3_to_cgns.$(O) binaryio.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ aflr3_to_cgns.$(O) binaryio.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

aflr3_to_cgns.$(O) : aflr3_to_cgns.c

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

cgns_to_aflr3$(EXE) : cgns_to_aflr3.$(O) getargs.$(O) hash.$(O)
	$(CC) $(LDFLAGS) -o $@ cgns_to_aflr3.$(O) \
	getargs.$(O) hash.$(O) $(LDLIST)
	$(STRIP) $@

cgns_to_aflr3.$(O) : cgns_to_aflr3.c

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

fast_to_cgns$(EXE) : fast_to_cgns.$(O) binaryio.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ fast_to_cgns.$(O) binaryio.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

fast_to_cgns.$(O) : fast_to_cgns.c

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

cgns_to_fast$(EXE) : cgns_to_fast.$(O) getargs.$(O) hash.$(O)
	$(CC) $(LDFLAGS) -o $@ cgns_to_fast.$(O) \
	getargs.$(O) hash.$(O) $(LDLIST)
	$(STRIP) $@

cgns_to_fast.$(O) : cgns_to_fast.c

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

fieldview_to_cgns$(EXE) : fieldview_to_cgns.$(O) cgnsImport.$(O) getargs.$(O) \
			  hash.$(O)
	$(CC) $(LDFLAGS) -o $@ fieldview_to_cgns.$(O) cgnsImport.$(O) \
	getargs.$(O) hash.$(O) $(LDLIST)
	$(STRIP) $@

fieldview_to_cgns.$(O) : fieldview_to_cgns.c cgnsImport.h

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

cgns_to_fieldview$(EXE) : cgns_to_fieldview.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ cgns_to_fieldview.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

cgns_to_fieldview.$(O) : cgns_to_fieldview.c cgnsutil.h

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

convert_location$(EXE) : convert_location.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ convert_location.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

convert_location.$(O) : convert_location.c cgnsutil.h

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

vertex_to_cell$(EXE) : vertex_to_cell.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ vertex_to_cell.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

vertex_to_cell.$(O) : convert_location.c cgnsutil.h
	$(CC) $(COPTS) -DVERTEX_TO_CELL -o vertex_to_cell.$(O) \
	-c convert_location.c

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

cell_to_vertex$(EXE) : cell_to_vertex.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ cell_to_vertex.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

cell_to_vertex.$(O) : convert_location.c cgnsutil.h
	$(CC) $(COPTS) -DCELL_TO_VERTEX -o cell_to_vertex.$(O) \
	-c convert_location.c

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

convert_variables$(EXE) : convert_variables.$(O) cgnsutil.$(O) getargs.$(O) \
			  $(CALCLIB)
	$(CC) $(LDFLAGS) -o $@ convert_variables.$(O) cgnsutil.$(O) \
	getargs.$(O) $(CALCLIB) $(LDLIST)
	$(STRIP) $@

convert_variables.$(O) : convert_variables.c cgnsutil.h
	$(CC) $(COPTS) -I$(CALCDIR) -c convert_variables.c

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

convert_dataclass$(EXE) : convert_dataclass.$(O) cgnsutil.$(O) getargs.$(O) \
			  $(CALCLIB)
	$(CC) $(LDFLAGS) -o $@ convert_dataclass.$(O) cgnsutil.$(O) \
	getargs.$(O) $(CALCLIB) $(LDLIST)
	$(STRIP) $@

convert_dataclass.$(O) : convert_dataclass.c
	$(CC) $(COPTS) -I$(CALCDIR) -c convert_dataclass.c

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

extract_subset$(EXE) : extract_subset.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ extract_subset.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

extract_subset.$(O) : extract_subset.c cgnsutil.h

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

interpolate_cgns$(EXE) : interpolate_cgns.$(O) cgnsutil.$(O) getargs.$(O)
	$(CC) $(LDFLAGS) -o $@ interpolate_cgns.$(O) cgnsutil.$(O) \
	getargs.$(O) $(LDLIST)
	$(STRIP) $@

interpolate_cgns.$(O) : interpolate_cgns.c cgnsutil.h

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

cgnsImport.$(O) : cgnsImport.c cgnsImport.h
cgnsutil.$(O)	: cgnsutil.c cgnsutil.h
binaryio.$(O)	: binaryio.c binaryio.h

getargs.$(O)	: ../common/getargs.c ../common/getargs.h
	$(CC) $(COPTS) -o getargs.$(O) -c ../common/getargs.c

hash.$(O)	: ../common/hash.c ../common/hash.h
	$(CC) $(COPTS) -o hash.$(O) -c ../common/hash.c

$(CALCLIB) :
	cd $(CALCDIR) && $(MAKE)

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

install : install-dirs install-prog install-script

install-dirs :
	@for d in \
	  $(EXE_INSTALL_DIR) \
	  $(LIB_INSTALL_DIR) ; do \
	  if [ ! -d $$d ] ; then \
	    echo "Making directory $$d"; \
	    mkdir -p $$d; \
	    chmod 755 $$d; \
	  fi; \
	done;

install-prog : $(ALL)
	@echo "installing utility executables to $(EXE_INSTALL_DIR)"
	@for i in $(ALL) ; do \
	  if [ -f $$i ]; then \
	    $(INSTALL_PROG) $$i $(EXE_INSTALL_DIR); \
	  fi; \
	done;

install-script :
	@echo "installing utility tcl scripts to $(LIB_INSTALL_DIR)"
	@for i in $(CNVFILES) $(SCRIPTS) ; do \
	  $(INSTALL_DATA) $$i $(LIB_INSTALL_DIR); \
	done;

uninstall :
	@echo "uninstalling utility executables"
	@for i in $(ALL) ; do \
	  if [ -f $(EXE_INSTALL_DIR)/$$i ] ; then \
	    /bin/rm -f $(EXE_INSTALL_DIR)/$$i; \
	  fi; \
	done;
	@echo "uninstalling utility tcl scripts"
	@for i in $(CNVFILES) $(SCRIPTS) ; do \
	  if [ -f $(LIB_INSTALL_DIR)/$$i ] ; then \
	    /bin/rm -f $(LIB_INSTALL_DIR)/$$i; \
	  fi; \
	done;

.c.$(O) :
	$(CC) $(COPTS) -c $<

clean:
	$(RM) *.$(O) *~ *.bak $(ALL)

