# @(#)makefile	16.1.1.1 (ESO-IPG) 06/19/01 15:41:55
# .COPYRIGHT:   Copyright (c) 1988 European Southern Observatory,
#                                               all rights reserved
# .TYPE         make file
# .NAME         $MIDASHOME/$MIDVERS/system/ftoc/makefile
# .LANGUAGE     makefile syntax
# .ENVIRONMENT  Unix Systems.
# .REMARKS
# .AUTHOR       ESO-IPG, Garching
# .VERSION 1.0  901223:
# .VERSION 3.0  930308:		Using default.mk file

include ../../local/default.mk

DEV_NULL= >/dev/null 2>&1

M = ../exec

LIB = $(LIBDIR)/libos.a

OBJ0 = forif.o ftoc.o
OBJ1 = ftoc_names.o ftoc_namesc.o
OBJ2 = ftoc_log.o ftoc_logc.o
OBJ3 = ftoc_commf.o ftoc_commff.o ftoc_commap.o ftoc_commc.o
OBJ4 = for_test.o ftoc_sun.o ftoc.o
OBJ5 = for_test.o ftoc_hp.o  ftoc.o
OBJ6 = for_test.o ftoc_fx.o  ftoc.o
OBJ7 = for_test.o ftoc_hpr.o ftoc.o
OBJ8 = for_test.o ftoc_titan.o ftoc.o
OBJ9 = for_test.o ftoc_hpn.o ftoc.o
OBJ10 = for_test.o ftoc_pc.o ftoc.o
OBJ11 = for_test.o ftoc_osf.o ftoc.o
OBJ12 = ftoc_vmrf.o ftoc_vmrc.o 
OBJ13 = for_test.o ftoc_osf2.o ftoc.o
OBJ14 = for_test.o ftoc_axp.o ftoc.o

# Do not remove this order
OUT = 	$(M)/forif.exe $(M)/ftoc_names.exe \
	$(M)/ftoc_vmr.exe $(M)/ftoc_osf2.exe \
	$(M)/ftoc_sun.exe $(M)/ftoc_hp.exe \
	$(M)/ftoc_fx.exe $(M)/ftoc_hpr.exe \
	$(M)/ftoc_hpn.exe $(M)/ftoc_pc.exe \
	$(M)/ftoc_osf.exe $(M)/ftoc_titan.exe \
	$(M)/ftoc_axp.exe \
	$(INC)/ftoc.h $(INC)/ftoc_comm.h $(INC)/ftoc_log.h


# DEPENDENCIES:
all: $(OUT) 

$(M)/forif.exe: $(OBJ0)
	$(LDCC) $(OBJ0) $(LIB) $(SLIB) -o $@
	$(STRIP) $@

$(M)/ftoc_names.exe: $(OBJ1)
	$(LD77_CMD) $(OBJ1) $(SLIB) -o $@
	$(STRIP) $@

$(M)/ftoc_log.exe: $(OBJ2)
	$(LD77_CMD) $(OBJ2) $(SLIB) -o $@
	$(STRIP) $@

$(M)/ftoc_comm.exe: $(INC)/ftoc_comma.h $(INC)/ftoc_commb.h ftoc_commf.o ftoc_commff.o ftoc_commc.c
	($(CC) $(CFLAGS) -DFTOC_COMMA -c ftoc_commc.c $(DEV_NULL); \
	$(CC) $(CFLAGS) -DFTOC_COMMA -c ftoc_commap.c $(DEV_NULL); \
	$(LD77_CMD) $(OBJ3) $(SLIB) -o $@ $(DEV_NULL) ) || \
	($(CC) $(CFLAGS) -DFTOC_COMMB -c ftoc_commc.c $(DEV_NULL); \
	$(CC) $(CFLAGS) -DFTOC_COMMB -c ftoc_commap.c $(DEV_NULL); \
	$(LD77_CMD) $(OBJ3) $(SLIB) -o $@ $(DEV_NULL) )

# CG. The Alpha OSF/1 creates a fake ftoc_vmr.exe and executable.
# However it gives errors when executed. Now and after the link
# It is executed and removed if error.
#
$(M)/ftoc_vmr.exe: $(OBJ12) $(M)/ftoc_names.exe
	$(LD77_CMD) ftoc_vmrf.o ftoc_vmrc.o $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@  && $@ $(DEV_NULL) || rm -f $@ ; touch $@

$(M)/ftoc_sun.exe:: $(OBJ4) 
	$(LD77_CMD) $(OBJ4) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_hp.exe:: $(OBJ5) 
	$(LD77_CMD) $(OBJ5) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_fx.exe:: $(OBJ6) 
	$(LD77_CMD) $(OBJ6) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_hpr.exe:: $(OBJ7) 
	$(LD77_CMD) $(OBJ7) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_titan.exe:: $(OBJ8) 
	$(LD77_CMD) $(OBJ8) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_hpn.exe:: $(OBJ9)
	$(LD77_CMD) $(OBJ9) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_pc.exe:: $(OBJ10)
	$(LD77_CMD) $(OBJ10) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_osf.exe:: $(OBJ11)
	$(LD77_CMD) $(OBJ11) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_osf2.exe:: $(OBJ13)
	$(LD77_CMD) $(OBJ13) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

$(M)/ftoc_axp.exe:: $(OBJ14)
	$(LD77_CMD) $(OBJ14) $(LIB) $(SLIB) -o $@ $(DEV_NULL) && \
	$(STRIP) $@ || rm -f $@; touch $@

ftoc_sun.o: ftoc_test.c $(INC)/ftoc_sun.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_sun.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_hp.o: ftoc_test.c $(INC)/ftoc_hp.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_hp.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_fx.o: ftoc_test.c $(INC)/ftoc_fx.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_fx.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_hpr.o: ftoc_test.c $(INC)/ftoc_hpr.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_hpr.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_hpn.o: ftoc_test.c $(INC)/ftoc_hpn.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_hpn.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_titan.o: ftoc_test.c $(INC)/ftoc_titan.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_titan.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_pc.o: ftoc_test.c $(INC)/ftoc_pc.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_pc.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_osf.o: ftoc_test.c $(INC)/ftoc_osf.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_osf.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_osf2.o: ftoc_test.c $(INC)/ftoc_osf.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_osf2.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_axp.o: ftoc_test.c $(INC)/ftoc_axp.h
	rm -f $(INC)/ftoc_test.h
	cp $(INC)/ftoc_axp.h $(INC)/ftoc_test.h
	$(CC) $(CFLAGS) -c ftoc_test.c $(DEV_NULL) && \
	mv ftoc_test.o $@ || touch $@

ftoc_vmrc.o: ftoc_vmrc.c
	$(CC) $(CFLAGS) `$(M)/ftoc_nam` -c ftoc_vmrc.c $(DEV_NULL) || \
	touch $@

$(INC)/ftoc.h: $(M)/ftoc_params.sh
	rm -f $(INC)/ftoc.h
	cp $(INC)/`$(M)/ftoc_params` $(INC)/ftoc.h
	rm -f core

$(INC)/ftoc_comm.h: $(M)/ftoc_comm.exe
	rm -f $@
	cp $(INC)/`$(M)/ftoc_comm.exe` $@

$(INC)/ftoc_log.h: $(M)/ftoc_log.exe
	rm -f $(INC)/ftoc_log.h
	$(M)/ftoc_log.exe >$@

ftoc_logc.o: $(INC)/ftoc.h

clean_exec:
	rm -f $(OUT)
clean:
	rm -f *.o *.f
	rm -f ftoc_commc.c ftoc_logc.c ftoc_test.c ftoc_vmrc.c
	rm -f $(INC)/ftoc.h $(INC)/ftoc_comm.h $(INC)/ftoc_log.h
