#
# Makefile for libTw, the library that talks to Twin
#
TOPDIR=../..
THISDIR=$(TOPDIR)/libs/libTw

SUBDIRS=

include $(TOPDIR)/include/Tw/makeversion
-include $(TOPDIR)/makeautoconf

LD_FLAGS+=$(LD_LIBSOCKET)

all: build-all

SHLIBS=libTw.la
ARLIBS=libTw.a

OBJS_libTw.la=libTw.lo avl.lo md5.lo missing.lo
OBJS_libTw.a=libTw.o avl.o md5.o missing.o

OBJS_gcc_i386_asm=libTw2_i386.o
OBJS_gcc_i386_asm_L=libTw2_i386.lo


ALL_OBJS=$(OBJS_libTw.a) $(OBJS_libTw.a) $(OBJS_gcc_i386_asm) $(OBJS_gcc_i386_asm_L)


CC_FLAGS+=-D_REENTRANT

-include $(TOPDIR)/conf/conf.current
-include .modules
-include .depend
-include $(TOPDIR)/.hdepend

ifneq ($(CONF_SOCKET),n)
  # do not link against libpthread: let client programs specify it explicitly
  # if they want to use threads, so that if they don't,
  # fallback, do-nothing functions will be picked from libc (if they exist)
  # avoiding overhead.
  #
  ifeq ($(CONF_SOCKET_PTHREADS),y)
    LD_FLAGS_libTw.la+=$(LD_LIBPTHREAD_WEAK)
  endif
  build-all: lib
  install: install-real
  uninstall: uninstall-real
  ifeq ($(CONF_SOCKET_GZ),y)
    LD_FLAGS_libTw.la+=-lz
  endif
else
  build-all install uninstall warn:
	@rm -f $(ARLIBS) $(SHLIBS) ; \
	 echo ; \
	 echo "You disabled \"Support remote socket connections\"," ; \
	 echo "so the library libTw will NOT be compiled!" ; \
	 echo
endif

ifeq ($(GCC_I386_ASM),yes)
    OBJS_libTw.la+=$(OBJS_gcc_i386_asm_L)
    OBJS_libTw.a+=$(OBJS_gcc_i386_asm)
endif

#
# include the do-everything file.
# Must correctly set all CC_FLAGS* and LD_FLAGS* before including this!
#
include $(TOPDIR)/makerules


#
# handy targets
#
ifeq ($(CONF__SHLIBS),y)
  lib: $(ARLIBS) $(SHLIBS)
else
  lib: $(ARLIBS)
	@rm -f $(SHLIBS) ; \
	 echo ; \
	 echo "You disabled \"Enable shared libraries\"," ; \
	 echo "so only the static library libTw.a will be compiled!" ; \
	 echo
endif

md5.c:
	$(LN) $(TOPDIR)/server/md5.c $@

missing.c:
	$(LN) $(TOPDIR)/server/missing.c $@

do-autogen: libTw1_m4.h libTw2_m4.h libTw2_i386_m4.h libTw3_m4.h

install-headers:
	$(INSTALL-DIR) $(DESTDIR)$(includedir)/Tw && \
	$(INSTALL-TXT) $(TOPDIR)/include/Tw/*.h $(DESTDIR)$(includedir)/Tw
	
install-dir:
	$(INSTALL-DIR) $(DESTDIR)$(libdir)

install-real: install-headers install-dir $(foreach B,$(SHLIBS) $(ARLIBS),install-lib-$(B))



uninstall-headers:
	rm -f $(DESTDIR)$(includedir)/Tw/*.h
	rmdir $(DESTDIR)$(includedir)/Tw || true

uninstall-dir:
	rmdir $(DESTDIR)$(libdir) || true

uninstall-real: uninstall-headers $(foreach B,$(SHLIBS) $(ARLIBS),uninstall-lib-) uninstall-dir


clean:
	rm -f .*.flags .*.shlib .*.arlib *.a *.la *.o *.lo *.so *.so.* ; \
	rm -fr .libs

