#
# Copyright (c) 1998, Guylhem AZNAR <guylhem@oeil.qc.ca>
#

@MAKEFILEDEFINES@

# We want to build both static and dynamic libs, as some service apps may need
# static library as they gets run at compile time (ASDocGen for example)
# but we only install whats selected
all:            $(LIB_STATIC) @LIBPROG@ $(INSTALLONBUILD) $(LIB_APPS)

install.bin:	$(LIB_APPS)
		@for p in $(LIB_APPS); do \
		  echo $(INSTALL_PROGRAM) $$p $(AFTER_BIN_DIR); \
		  $(INSTALL_PROGRAM) $$p $(AFTER_BIN_DIR); \
		done

install.lib:	@LIBPROG@ @LIBINSTALL@ install.inc

install.static:
		@( \
		if test -d $(LIBDIR) && test -w $(LIBDIR); then \
		    echo "$(INSTALL_LIB) $(LIB_STATIC) $(LIBDIR)"; \
		    $(INSTALL_LIB) $(LIB_STATIC) $(LIBDIR); \
		    if test `uname` = "Linux"; then \
			if test $(LIBDIR) = "/lib" || test $(LIBDIR) = "/usr/lib"; then \
		    	    echo "" > /dev/null; \
			elif grep -q $(LIBDIR) /etc/ld.so.conf > /dev/null 2>&1; then \
		    	    echo "" > /dev/null; \
			else \
		    	    echo "Unable to find $(LIBDIR) in ld.so.conf. In order to use "; \
		    	    echo "$(LIB_STATIC), you may need to add it or set LD_LIBRARY_PATH."; \
			fi; \
			if test -w /etc; then \
			    echo "$(LDCONFIG)"; \
			    $(LDCONFIG); \
			fi; \
		    fi ;\
		fi \
		)

install.man:

install.script:

install.dyn:
		@(  echo "$(INSTALL_LIB) $(LIB_SHARED).$(LIBVER) $(LIBDIR)"; \
		$(INSTALL_LIB) $(LIB_SHARED).$(LIBVER) $(LIBDIR); \
		$(RM) -f $(LIBDIR)/$(LIB_SHARED).$(LIBVERMAJOR) $(LIBDIR)/$(LIB_SHARED); \
		$(LN_S) -f $(LIB_SHARED).$(LIBVER) $(LIBDIR)/$(LIB_SHARED).$(LIBVERMAJOR); \
		$(LN_S) -f $(LIB_SHARED).$(LIBVERMAJOR) $(LIBDIR)/$(LIB_SHARED); \
		 if test `uname` = "Linux"; then \
		   if test $(LIBDIR) = "/lib" || test $(LIBDIR) = "/usr/lib"; then \
		     echo "" > /dev/null; \
		   elif grep -q $(LIBDIR) /etc/ld.so.conf > /dev/null 2>&1; then \
		     echo "" > /dev/null; \
		   else \
		     echo "Unable to find $(LIBDIR) in ld.so.conf. In order to use "; \
		     echo "$(LIB_SHARED), you may need to add it or set LD_LIBRARY_PATH."; \
		   fi; \
		   echo "$(LDCONFIG)"; \
		   $(LDCONFIG); \
		 fi \
		)

install.cyg:
		@( echo "$(INSTALL_LIB) $(LIB_SHARED_CYG) $(AFTER_BIN_DIR)"; \
		$(INSTALL_LIB) $(LIB_SHARED_CYG) $(AFTER_BIN_DIR); \
		echo "$(INSTALL_LIB) $(LIB_SHARED_CYG) $(LIBDIR)"; \
		$(INSTALL_LIB) $(LIB_SHARED_CYG) $(LIBDIR); \
		echo "$(INSTALL_LIB) $(LIB_SHARED_CYG_AR) $(LIBDIR)"; \
		$(INSTALL_LIB) $(LIB_SHARED_CYG_AR) $(LIBDIR); \
		)

install.inc:
		@( \
                if [ -f $(CONFIG_SCRIPT) ] ; then \
			echo "$(INSTALL_SCRIPT) $(CONFIG_SCRIPT) $(AFTER_BIN_DIR)"; \
                        $(INSTALL_SCRIPT) $(CONFIG_SCRIPT) $(AFTER_BIN_DIR); \
                fi; \
                 if [ -d $(AFTER_INC_DIR) ]; then \
		    echo "$(RM) $(AFTER_INC_DIR)/*"; \
		    $(RM) $(AFTER_INC_DIR)/*; \
		 else \
		    if [ -d $(INCLUDEDIR) ]; then \
		       echo "$(MKDIR) $(AFTER_INC_DIR)"; \
		       if $(MKDIR) $(AFTER_INC_DIR); then \
		          echo " ">/dev/null; \
		       else \
		    	  echo "failed to create include directory: $(AFTER_INC_DIR)"; \
		       fi; \
		    else \
		       echo "$(MKDIR) $(INCLUDEDIR)"; \
		       if $(MKDIR) $(INCLUDEDIR); then \
		          echo "$(MKDIR) $(AFTER_INC_DIR)"; \
		          if $(MKDIR) $(AFTER_INC_DIR) >/dev/null; then \
		             echo " ">/dev/null; \
		          else \
		             echo "failed to create include directory: $(AFTER_INC_DIR)"; \
			  fi; \
		       else \
		          echo "failed to create include directory: $(INCLUDEDIR)"; \
		       fi; \
		    fi; \
		 fi; \
		 if [ -d $(AFTER_INC_DIR) ]; then \
		    echo "installing $(LIB_NAME) headers using command - "; \
		    echo "    \"$(INSTALL_HEADER) <header> $(AFTER_INC_DIR)\" :"; \
		    for file in $(LIB_INCS) ; do  \
			echo -n "$$file "; \
			$(INSTALL_HEADER) $$file $(AFTER_INC_DIR); \
		    done; \
		    echo ""; echo "Done."; \
		 fi \
		)

uninstall.bin:

uninstall.lib:

uninstall.man:

uninstall.script:

clean:
		$(RMF) $(LIB_SHARED) $(LIB_SHARED_CYG) $(LIB_SHARED_CYG_AR) $(LIB_STATIC) $(LIB_APPS) *.so.* *.so *.o *~ *% *.bak \#* core

distclean:
		$(RMF) $(LIB_SHARED) $(LIB_SHARED_CYG) $(LIB_SHARED_CYG_AR) $(LIB_STATIC) $(LIB_APPS) *.o *.so.* *~ *% *.bak \#* *.orig core Makefile

indent:
		@SRCS=`echo "$(LIB_OBJS) " | sed "s/.o /.c /g"`; \
		if test "x$$SRCS" == "x"; then exit; fi; \
		for i in $$SRCS; do \
		  if (indent -di14 -ts4 -i4 -l120 -lc80 -bad -nbbb -bli0 -c48 -cd48 -ce -cli1 -ncs -nbs -nbbo -hnl < $$i > /tmp/$$i); then \
		    echo "indent $$i"; \
		    mv /tmp/$$i $$i; \
		  fi; \
		done

deps:
		echo -n > .depend ; \
		buf="" ; \
		SRCS=`echo "$(LIB_OBJS) " | sed "s/.o /.c /g"`; \
		echo -n $(LIB_NAME)_OBJS = > .shared ; \
		for file in $$SRCS; do \
		  echo " \\" >> .shared ; \
		  echo -n '		$$('$(LIB_NAME)_PATH')'/$$file >> .shared ; \
		  if test "x$$buf" != "x"; then \
		      echo $$buf >>.depend ; \
		      echo >>.depend ; \
		  fi; \
		  buf="./"`echo "$$file " | sed "s/.c /.o /g"`: ; \
		  for d in `grep "#include \"" < $$file | awk -F \" '{print $$2}'`; do \
		      if test "x$$buf" != "x"; then \
		         echo $$buf \\ >>.depend ; \
		      fi; \
		      echo -n "		" >>.depend ; \
		      buf="$$d "; \
		  done; \
		done; \
		if test "x$$buf" != "x"; then \
		  echo $$buf >>.depend ; \
		fi; \
		echo "">> .shared ; \
		echo "">> .shared ; \
		echo -n $(LIB_NAME)_INCS = >> .shared ; \
		for f in $(LIB_INCS); do \
		  echo " \\" >> .shared ; \
		  echo -n '		$$('$(LIB_NAME)_PATH')'/$$f >> .shared ; \
		done; \
		echo "" >> .shared ;

$(LIB_STATIC):	$(LIB_OBJS) $(LIB_INCS)
		$(RMF) $(LIB_STATIC)
		$(AR) $(LIB_STATIC) $(LIB_OBJS)
		$(RANLIB) $(LIB_STATIC)

.c.o:
		$(CC) $(CCFLAGS) $(EXTRA_DEFINES) $(INCLUDES) $(EXTRA_INCLUDES) -c $*.c

.c.s:
		$(CC) $(CCFLAGS) $(EXTRA_DEFINES) $(INCLUDES) $(EXTRA_INCLUDES) -S $*.c

#
# include dependency files if they exist
#
# this is merely a precaution, but as it does not work with ansi make
# we took it out
#ifneq ($(wildcard .depend),)
include .depend
#endif

$(LIB_SHARED_CYG): $(LIB_OBJS) $(LIB_INCS)
	$(CC) -shared -o $(LIB_SHARED_CYG) \
    		-Wl,--out-implib=$(LIB_SHARED_CYG_AR) \
    		-Wl,--export-all-symbols -Wl,--enable-auto-import \
    		-Wl,--whole-archive ${LIB_OBJS} \
    		$(USER_LD_FLAGS) -Wl,--no-whole-archive $(LIBS_ALL)

$(LIB_SHARED): $(LIB_SHARED).$(LIBVERMAJOR)
	$(LN_S) -f $(LIB_SHARED).$(LIBVERMAJOR) $(LIB_SHARED)

$(LIB_SHARED).$(LIBVERMAJOR): $(LIB_SHARED).$(LIBVER)
	$(LN_S) -f $(LIB_SHARED).$(LIBVER) $(LIB_SHARED).$(LIBVERMAJOR)

$(LIB_SHARED).$(LIBVER): $(LIB_OBJS) $(LIB_INCS)
	$(CC) -shared -Wl,-soname,$(LIB_SHARED).$(LIBVERMAJOR) -o $(LIB_SHARED).$(LIBVER) \
	 $(LIB_OBJS)

install:	install.lib install.bin


uninstall:	uninstall.lib

