# Makefile for Unix/Linux

include ../make.defs

COPTS  = $(CFLAGS) -I../common -I$(CGNSDIR) $(TKINCS) $(OGLINCS)
LDLIST = $(CGNSLIB) $(BUILDLIBS) $(TKOGLLIB) $(TKLIBS) \
	 $(OGLLIBS) $(X11LIBS) $(TKOGLXLIB) $(CLIBS)

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

plotwish$(EXE) : plotwish.$(O) cgnstcl.$(O) hash.$(O) $(TKOGLLIB)
	$(CC) $(LDFLAGS) -o $@ plotwish.$(O) cgnstcl.$(O) hash.$(O) $(LDLIST)
	$(STRIP) $@

plotwish.$(O) : plotwish.c
cgnstcl.$(O)  : cgnstcl.c
	$(CC) $(COPTS) $(PLOTOPTS) -c cgnstcl.c

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

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

ICONS = cgnsplot.ico cgnsplot.png cgnsplot-icon.xbm cgnsplot-mask.xbm

install : install-dirs install-prog install-wish install-script

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

install-prog :
	@echo "installing cgnsplot shell scripts to $(BIN_INSTALL_DIR)"
	@$(INSTALL_PROG) cgnsplot.sh $(BIN_INSTALL_DIR)/cgnsplot
	@chmod +x $(BIN_INSTALL_DIR)/cgnsplot
	@if [ ! -f $(EXE_INSTALL_DIR)/cgconfig ] ; then \
	  echo "installing configuration file to $(EXE_INSTALL_DIR)"; \
	  $(INSTALL_DATA) ../cgconfig $(EXE_INSTALL_DIR)/cgconfig; \
	fi;

install-wish : plotwish$(EXE)
	@echo "installing plotwish executable to $(WSH_INSTALL_DIR)"
	@$(INSTALL_PROG) plotwish$(EXE) $(WSH_INSTALL_DIR)

install-script :
	@echo "installing cgnsplot tcl scripts to $(LIB_INSTALL_DIR)"
	@$(INSTALL_DATA) cgnsplot.tcl $(LIB_INSTALL_DIR)
	@echo "installing icons to $(LIB_INSTALL_DIR)"
	@for i in $(ICONS) ; do \
	  $(INSTALL_DATA) $$i $(LIB_INSTALL_DIR); \
	done;

uninstall :
	@echo "uninstalling cgnsplot executables"
	@if [ -f $(BIN_INSTALL_DIR)/cgnsplot ] ; then \
	  /bin/rm -f $(BIN_INSTALL_DIR)/cgnsplot; \
	fi;
	@if [ -f $(WSH_INSTALL_DIR)/plotwish$(EXE) ] ; then \
	  /bin/rm -f $(WSH_INSTALL_DIR)/plotwish$(EXE); \
	fi;
	@echo "uninstalling cgnsplot tcl scripts"
	@if [ -f $(LIB_INSTALL_DIR)/cgnsplot.tcl ] ; then \
	  /bin/rm -f $(LIB_INSTALL_DIR)/cgnsplot.tcl; \
	fi;
	@echo "uninstalling cgnsplot icons"
	@for i in $(ICONS) ; 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 plotwish$(EXE)

