INSTALL_DIR=please_set_the_INSTALL_DIR_variable_in_the_top_level_makefile_and_run_make_config
DEFAULT_SERVER=localhost

BIN=$(INSTALL_DIR)/bin
LIB=$(INSTALL_DIR)/lib

CFLAGS= -O

SCRIPTS=tmu tmget tmrelease

COMMANDS=
	
install:	dirs $(SCRIPTS) $(COMMANDS)
	cd tmports; make install
	cd portmux; make install
	cd tmgetvar; make install
	cd tmsetvar; make install
	cd tmstatus; make install
	cd tmumon; make install

config:
	sed -e "/^INSTALL_DIR=/s;.*;INSTALL_DIR=$(INSTALL_DIR);" -e "/^DEFAULT_SERVER=/s;.*;DEFAULT_SERVER=$(DEFAULT_SERVER);" tmports/makefile > temp; mv temp tmports/makefile
	sed -e "/^INSTALL_DIR=/s;.*;INSTALL_DIR=$(INSTALL_DIR);" -e "/^DEFAULT_SERVER=/s;.*;DEFAULT_SERVER=$(DEFAULT_SERVER);" tmstatus/makefile > temp; mv temp tmstatus/makefile
	sed -e "/^INSTALL_DIR=/s;.*;INSTALL_DIR=$(INSTALL_DIR);" -e "/^DEFAULT_SERVER=/s;.*;DEFAULT_SERVER=$(DEFAULT_SERVER);" tmumon/makefile > temp; mv temp tmumon/makefile
	sed "/^INSTALL_DIR=/s;.*;INSTALL_DIR=$(INSTALL_DIR);" portmux/makefile > temp; mv temp portmux/makefile
	sed "/^INSTALL_DIR=/s;.*;INSTALL_DIR=$(INSTALL_DIR);" tmgetvar/makefile > temp; mv temp tmgetvar/makefile
	sed "/^INSTALL_DIR=/s;.*;INSTALL_DIR=$(INSTALL_DIR);" tmsetvar/makefile > temp; mv temp tmsetvar/makefile

dirs:	$(BIN) $(LIB)

$(BIN):
	mkdir $(BIN)

$(LIB):
	mkdir $(LIB)

clean:
	rm -f $(COMMANDS) *.o
	cd tmports; make clean
	cd portmux; make clean
	cd tmgetvar; make clean
	cd tmsetvar; make clean
	cd tmstatus; make clean
	cd tmumon; make clean

reallyclean:	clean

tmget:
	cp tmget.sh $(BIN)/tmget
	chmod a+x $(BIN)/tmget 

tmrelease:
	cp tmrelease.sh $(BIN)/tmrelease
	chmod a+x $(BIN)/tmrelease 

tmu:
	sed "s;%%INSTALL_DIR%%;$(INSTALL_DIR);" tmu.sh > $(BIN)/tmu
	chmod a+x $(BIN)/tmu
