
CGNSDIR = ..
include $(CGNSDIR)/make.defs

CGNSLIB = $(CGNSDIR)/$(LIBCGNS)

COPTS  = $(CFLAGS) -I$(CGNSDIR)
LDLIBS = $(CGNSLIB) $(BUILDLIBS)

#----------

ALL = \
	cgnslist$(EXE) \
	cgnscheck$(EXE) \
	cgnsconvert$(EXE) \
	cgnscompress$(EXE) \
	cgnsdiff$(EXE) \
	cgnsnames$(EXE)

all : $(ALL)

#----------

cgnslist$(EXE) : cgnslist.$(O) getargs.$(O) $(CGNSLIB)
	$(CC) $(COPTS) $(CEOUT)$@ cgnslist.$(O) getargs.$(O) $(LDLIBS) $(CLIBS)
cgnslist.$(O) : cgnslist.c getargs.h
	$(CC) $(COPTS) -c cgnslist.c

#----------

cgnscheck$(EXE) : cgnscheck.$(O) getargs.$(O) hash.$(O) cgnames.$(O) $(CGNSLIB)
	$(CC) $(COPTS) $(CEOUT)$@ cgnscheck.$(O) getargs.$(O) hash.$(O) cgnames.$(O) $(LDLIBS) $(CLIBS)
cgnscheck.$(O) : cgnscheck.c getargs.h hash.h cgnames.h
	$(CC) $(COPTS) -c cgnscheck.c

#----------

cgnsconvert$(EXE) : cgnsconvert.$(O) getargs.$(O) $(CGNSLIB)
	$(CC) $(CFLAGS) $(CEOUT)$@ cgnsconvert.$(O) getargs.$(O) $(LDLIBS) $(CLIBS)
cgnsconvert.$(O) : cgnsconvert.c getargs.h
	$(CC) $(COPTS) -c cgnsconvert.c

#----------

cgnscompress$(EXE) : cgnscompress.$(O) $(CGNSLIB)
	$(CC) $(CFLAGS) $(CEOUT)$@ cgnscompress.$(O) $(LDLIBS) $(CLIBS)
cgnscompress.$(O) : cgnscompress.c
	$(CC) $(COPTS) -c cgnscompress.c

#----------

cgnsdiff$(EXE) : cgnsdiff.$(O) getargs.$(O) $(CGNSLIB)
	$(CC) $(CFLAGS) $(CEOUT)$@ cgnsdiff.$(O) getargs.$(O) $(LDLIBS) $(CLIBS)
cgnsdiff.$(O) : cgnsdiff.c getargs.h
	$(CC) $(COPTS) -c cgnsdiff.c

#----------

cgnsnames$(EXE) : cgnsnames.$(O) cgnames.$(O)
	$(CC) $(COPTS) $(CEOUT)$@ cgnsnames.$(O) cgnames.$(O) $(LDLIBS) $(CLIBS)
cgnsnames.$(O) : cgnsnames.c cgnames.h
	$(CC) $(COPTS) -c cgnsnames.c

#----------

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

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

cgnames.$(O) : cgnames.c cgnames.h
	$(CC) $(COPTS) -c cgnames.c

#----------

install : all $(BINDIR)
	cp $(ALL) $(BINDIR)
	cp cgnsupdate $(BINDIR)
	chmod +x $(BINDIR)/cgnsupdate
	cp adf2hdf $(BINDIR)
	chmod +x $(BINDIR)/adf2hdf
	cp hdf2adf $(BINDIR)
	chmod +x $(BINDIR)/hdf2adf

$(BINDIR) :
	@if [ ! -d $(BINDIR) ] ; then \
	    echo "Making directory $(BINDIR)"; \
	    mkdir -p $(BINDIR); \
	    chmod 755 $(BINDIR); \
	 fi;

uninstall :
	@for i in $(ALL) ; do \
	  if [ -f $(BINDIR)/$$i ] ; then \
	    /bin/rm -f $(BINDIR)/$$i; \
	  fi; \
	done;
	/bin/rm -f $(BINDIR)/cgnsupdate
	/bin/rm -f $(BINDIR)/adf2hdf
	/bin/rm -f $(BINDIR)/hdf2adf

clean :
	-$(RM) *.$(O)

allclean : clean
	-$(RM) $(ALL) sizes$(EXE)
	-$(RM) *~ *.bak
	-$(RM) *.cgns

