# **************************************************************************
# Fichero makefile.
# --------------------------------------------------------------------------
# Licencia GPL. Juan Gonzalez Gomez
# --------------------------------------------------------------------------
#
#***************************************************************************

# Edited for Debian GNU/Linux.
DESTDIR =

# ¿Dónde poner las librerias en el 'make install'?
LIB  = $(DESTDIR)/usr/lib

#-- Donde instalar las paginas man?
MAN  = $(DESTDIR)/usr/local/man

#-- Donde instalar los fichero .h?
INCLUDE = $(DESTDIR)/usr/local/include

DOC = $(DESTDIR)/usr/local/doc

#--- Libreria dinamica
LIBNAME_D = libcts.so.1.5

#--- Libreria estatica
LIBNAME_S = libcts.a

#---- Compilador
CC = gcc
CFLAGS = -Wall

all: cts-target cts-test

#-- Construccion de los ejemplos de prueba
cts-test: test-ascbin1 test-serie1-terminal test-s19-leers19 test-s19-dump \
          test-s19-s19toc 

#-- Construccion de la libreria estatica y dinamica
cts-target: $(LIBNAME_D) $(LIBNAME_S)

#----- Paquetes que componen la Libreria CTS
CTS = ascbin.o serie.o s19.o bootstrp.o ctclient.o ctnet.o


#---------------------------
#       OBJETIVOS
#---------------------------
# ---- Generacion de la libreria dinamica
$(LIBNAME_D):  $(CTS)
	           $(CC) -shared -W1,-soname,libcts.so -o $(LIBNAME_D) $(CTS)
clean::
	  rm -f $(LIBNAME_D) $(CTS)

#----- Generacion de la libreria estatica
$(LIBNAME_S):  $(CTS)
	           ar rs $(LIBNAME_S) $(CTS)
clean::
	  rm -f $(LIBNAME_S) $(CTS)              

#--------------------------
#  Programas de prueba
#--------------------------
NAME1= test-ascbin1
DEP1 = $(NAME1).o $(LIBNAME_S) 

$(NAME1): $(DEP1)
	    $(CC) -o $(NAME1) $(DEP1)

clean::
	  rm -f $(NAME1) $(DEP1)

#---------------------------------------
NAME2= test-serie1-terminal
DEP2 = $(NAME2).o io.o $(LIBNAME_S) 

$(NAME2): $(DEP2)
	    $(CC) -o $(NAME2) $(DEP2)

clean::
	  rm -f $(NAME2) $(DEP2)

#---------------------------------------
NAME3= test-s19-leers19
DEP3 = $(NAME3).o $(LIBNAME_S)

$(NAME3): $(DEP3)
	    $(CC) -o $(NAME3) $(DEP3)

clean::
	  rm -f $(NAME3) $(DEP3)
	  
#---------------------------------------
NAME4= test-s19-dump
DEP4 = $(NAME4).o $(LIBNAME_S)

$(NAME4): $(DEP4)
	    $(CC) -o $(NAME4) $(DEP4)

clean::
	  rm -f $(NAME4) $(DEP4)	  
	  
#---------------------------------------
NAME5= test-s19-s19toc
DEP5 = $(NAME5).o $(LIBNAME_S)

$(NAME5): $(DEP5)
	    $(CC) -o $(NAME5) $(DEP5)

clean::
	  rm -f $(NAME5) $(DEP5)	  

#-----------------------------
#--- Dependencias
#-----------------------------
serie.o    : serie.h
ascbin.o   : ascbin.h
bootstrp.o : serie.h s19.h bootstrp.h
s19.o      : s19.h
ctclient.o : serie.h ctclient.h
ctnet.o    : serie.h 

#---------------------------
#-- INSTALACION
#---------------------------
install: cts-target
	     install -d $(LIB) $(MAN) $(INCLUDE) 
	     install ./libcts.so.1.5 $(LIB)
	     install ./libcts.a      $(LIB)
	     install ../man/cts.3    $(MAN)/man3
	     cp -a *.h $(INCLUDE)
	     install -d $(DOC)/cts
	     cp -a ../doc/cts.pdf $(DOC)/cts
	     ln -s $(LIB)/libcts.so.1.5 $(LIB)/libcts.so
	     ldconfig
                       

#---------------------------
#-- DESINSTALACION
#---------------------------
uninstall:
	   rm -f $(LIB)/libcts.so.1.5 $(LIB)/libcts.a $(LIB)/libcts.so
	   rm -f $(MAN)/man3/cts.3
	   rm -f $(INCLUDE)/serie.h $(INCLUDE)/ascbin.h $(INCLUDE)/s19.h \
             $(INCLUDE)/bootstrap.h $(INCLUDE)/ctclient.h $(INCLUDE)/r6811pc.h
	   rm -f $(DOC)/cts/cts.pdf
	   rm -rf $(DOC)/cts
      
#--------------------------
#  REGLAS GENERICAS
#--------------------------
.c.o:		
		$(CC) $(CFLAGS) -c $<
