#---------------------------------------------------------------------------
# Makefile (sytem independent part) for the TECS Client library and TecsServer
# included in a machine-specific makefile
#
# Markus Zolliker, March 2003
#--------------------------------------------------------------------------

.SUFFIXES:
.SUFFIXES: .o .c .f

LIBR_OBJ  =coc_util.o myc_err.o myc_str.o myc_buf.o myc_time.o
SERV_OBJ  =tecs.o coc_server.o tecs_lsc.o tecs_serial.o coc_logfile.o \
           tecs_data.o tecs_logger.o $(LIBR_OBJ)
CLI_OBJ   =tecs_cli.o coc_client.o $(LIBR_OBJ)
TCLI_OBJ  =sys_getenv.o sys_env.o myc_tmp.o sys_cmdpar.o \
           sys_date.o sys_wait.o sys_lun.o sys_rdline.o \
           sys_get_key.o sys_unix.o sys_open$(SYS_OPEN).o \
           $(CLI_OBJ)
TECLI_OBJ =tecs_client.o tecs_plot.o str.o instr_hosts.o \
           $(TCLI_OBJ)

HARDSUPLIB = ../hardsup/libhlib.a

libtecsl.a: $(CLI_OBJ)
	rm -f $@
	$(AR) $(ARFLAGS) $@ $Q
	ranlib libtecsl.a

all: libtecsl.a TecsServer TecsClient keep_running six

CFGDIR=/afs/psi.ch/project/sinq/common/lib/tecs/cfg/

-include make_crv

make_crv: make_crv.tcsh inp/lsc.codes $(ALLINP)
	make_crv.tcsh inp/lsc.codes

dev.list:
	make_list.tcsh $(CFGDIR)*.cfg > $@
	cp $@ $(CFGDIR)

# use target all_crv to make all curves in inp directory

TecsServer: $(SERV_OBJ) $(HARDSUPLIB) $(FORTIFYOBJ)
	$(CC) $(CFLAGS) -o $@ $Q -lm

lsc331: lsc331.o coc_server.o tecs_lsc.o tecs_serial.o coc_logfile.o \
           $(LIBR_OBJ) $(HARDSUPLIB) $(FORTIFYOBJ)
	$(CC) $(CFLAGS) -o $@ $Q -lm

TecsClient: $(TECLI_OBJ) $(FORTIFYOBJ) pg_plus/libpgplus.a
	$(FC) -o $@ $Q $(PGLIB) $(RDLIB)

instr_hosts.o: instr_hosts.c
	$(CC) $(CFLAGS) -DMYC_FORTRAN -c $Q

$(HARDSUPLIB):
	cd ../hardsup; make $(MFLAGS) libhlib.a

# -- for tascom --
libtecs.so: tecs_c.c $(CLI_OBJ) $(FORTIFYOBJ)
	$(CC) $(CFLAGS) -shared -o $@ $Q

ccrv: conv.f sys_cmdpar.o str.o cvt.o
	$(FC) $(FFLAGS) -o ccrv $Q

# -- needs special include
tecs_serial.o: tecs_serial.c
	$(CC) $(CFLAGS) -I../hardsup -c $Q

keep_running: keep_running.c
	$(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ)

six: six.c term.o sys_select.o libtecsl.a instr_hosts.o
	$(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ)

rexstart: rstart.c myc_str.o myc_err.o instr_hosts.o
	$(CC) $(CFLAGS) -o $@ $Q $(FORTIFYOBJ)
	@ echo "$(PWD)/rstart"

pg_plus/libpgplus.a:
	cd pg_plus; make $(MFLAGS) 

clean:
	rm -f *.o *.a six keep_running TecsServer TecsClient
