#
# Makefile
prefix=/usr/local
exec_prefix=${prefix}

CCX=gcc
INCLUDES=-I/usr/include -I../lib -I../ -I/usr/local/ActiveTcl/include/
CCXFLAGS=${INCLUDES} -fPIC
LIBS=-L/usr/local/lib -L/usr/lib -lm -ltcl8.4 -ltk8.4 -ldl -L/usr/X11R6/lib/X11

RANLIB=ranlib
AR=ar

INSTALL=/usr/bin/install -c
INSTALL_DATA=${INSTALL} -m 644

RM   = rm -f
LNK  = ln -sf

lib_dir=${prefix}/lib

lib_version=0.0.1

lib_name=tctcl

STATIC_LIB=lib${lib_name}.a
SHARED_LIB=lib${lib_name}.so.${lib_version}

SRC  = tctcl.c

OBJS = $(SRC:.c=.o)
OBJD = $(SRC:.c=.lo)

#
# Rules for compiling .c .s sources
#
.SUFFIX: .c .o .lo
.c.o:
	$(CCX) $(CCXFLAGS) -c $<

%.lo: %.c
	$(CCX) $(CCXFLAGS) -c $< -o $@


#all: static-libs shared-libs
all: shared-libs
devel: static-libs

static-libs: ${STATIC_LIB}

shared-libs: ${SHARED_LIB}

# Rules for building the static library
#
${STATIC_LIB}: ${OBJS}
	${AR} cr ${STATIC_LIB} ${OBJS}
	${RANLIB} ${STATIC_LIB}

# Rules for building the shared library
#
${SHARED_LIB}: ${OBJD}
	${CCX} -shared -Wl,-soname,lib${lib_name}.so.0 -o ${SHARED_LIB} $(OBJD) ${LIBS} 
	${LNK} $(SHARED_LIB) lib$(lib_name).so.0
	${LNK} $(SHARED_LIB) lib$(lib_name).so

clean:
	@${RM} ${OBJS} ${OBJD} ${STATIC_LIB} ${SHARED_LIB} lib$(lib_name).so* \
	*.a core *.bak *.o *.lo

install: install-shared

install-static: ${STATIC_LIB} 
	${INSTALL_DATA} ${STATIC_LIB} ${lib_dir}/${STATIC_LIB}

install-shared: ${SHARED_LIB} 
	${INSTALL_DATA} ${SHARED_LIB} ${lib_dir}/${SHARED_LIB}
	${LNK} ${lib_dir}/$(SHARED_LIB) ${lib_dir}/lib$(lib_name).so
	${LNK} ${lib_dir}/$(SHARED_LIB) ${lib_dir}/lib$(lib_name).so.0
