#
# Template makefile for building wxWindows companion libraries.
#
# Author:   Ron Lee <ron@debian.org>
# Created:  19/3/2000
# $Id: makelib.env.in,v 1.5 2000/07/15 19:50:24 cvsuser Exp $
#
# To use, set the following vars before including it:
#
# top_srcdir
# top_builddir
# libsrc_dir
#
# TARGET_LIBNAME
# LIBVERSION_CURRENT
# LIBVERSION_REVISION
# LIBVERSION_AGE
# HEADER_PATH
# HEADER_SUBDIR
#
# HEADERS
# OBJECTS
#
# either a shared or static lib will be built according to the
# option given to configure.
#

prefix = /usr/local
exec_prefix = ${prefix}
includedir = ${prefix}/include
libdir = ${exec_prefix}/lib

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

TARGETLIB_STATIC = $(TARGET_LIBNAME).a
TARGETLIB_SHARED = $(TARGET_LIBNAME).so.$(LIBVERSION_CURRENT).$(LIBVERSION_REVISION).$(LIBVERSION_AGE)
TARGETLIB_LINK1 = $(TARGET_LIBNAME).so.$(LIBVERSION_CURRENT)
TARGETLIB_LINK2 = $(TARGET_LIBNAME).so

TARGETLIB_SONAME = 

# Clears all default suffixes
.SUFFIXES:	.o .cpp .c .cxx

.c.o :
	$(CCC) -c $(CFLAGS) $(PICFLAGS) -o $@ $<

.cpp.o :
	$(CC) -c $(CPPFLAGS) $(PICFLAGS) -o $@ $<

.cxx.o :
	$(CC) -c $(CPPFLAGS) $(PICFLAGS) -o $@ $<

# the comment at the end of the next line is needed because otherwise autoconf
# would remove this line completely - it contains a built-in hack to remove
# any VPATH assignment not containing ':'
VPATH = :$(top_srcdir)/$(libsrc_dir) # ':' for autoconf

include $(top_builddir)/src/make.env


all: libtype_a

libtype_so: CREATE_LINKS

libtype_a: $(TARGETLIB_STATIC)


$(TARGETLIB_SHARED): $(OBJECTS)
	@$(INSTALL) -d $(top_builddir)/lib
	$(SHARED_LD) $(top_builddir)/lib/$@ $(TARGETLIB_SONAME) $(OBJECTS)

CREATE_LINKS: $(TARGETLIB_SHARED)
	cd $(top_builddir)/lib \
		&& $(RM) $(TARGETLIB_LINK1) $(TARGETLIB_LINK2) \
		&& $(LN_S) $(TARGETLIB_SHARED) $(TARGETLIB_LINK1) \
		&& $(LN_S) $(TARGETLIB_SHARED) $(TARGETLIB_LINK2)

$(TARGETLIB_STATIC): $(OBJECTS)
	@$(INSTALL) -d $(top_builddir)/lib
	ar $(AROPTIONS) $(top_builddir)/lib/$@ $(OBJECTS)
	$(RANLIB) $(top_builddir)/lib/$@

install: install_a install_headers

install_so:
	$(INSTALL_PROGRAM) $(top_builddir)/lib/$(TARGETLIB_SHARED) $(libdir)/$(TARGETLIB_SHARED)
	@$(RM) $(libdir)/$(TARGETLIB_LINK1) $(libdir)/$(TARGETLIB_LINK2)
	cd $(libdir) \
		&& $(LN_S) $(TARGETLIB_SHARED) $(TARGETLIB_LINK1) \
		&& $(LN_S) $(TARGETLIB_SHARED) $(TARGETLIB_LINK2)

install_a:
	$(INSTALL_PROGRAM) $(top_builddir)/lib/$(TARGETLIB_STATIC) $(libdir)/$(TARGETLIB_STATIC)

install_headers:
	$(INSTALL) -d $(includedir)/wx/$(HEADER_SUBDIR)
	@for h in $(HEADERS); do \
	  $(INSTALL_DATA) $(HEADER_PATH)/$(HEADER_SUBDIR)/$$h $(includedir)/wx/$(HEADER_SUBDIR)/$$h; \
	  echo "installing $(includedir)/wx/$(HEADER_SUBDIR)/$$h"; \
	done

uninstall:
	$(RM) $(libdir)/$(TARGETLIB_STATIC)
	$(RM) $(libdir)/$(TARGETLIB_SHARED)
	$(RM) $(libdir)/$(TARGETLIB_LINK1)
	$(RM) $(libdir)/$(TARGETLIB_LINK2)
	@echo "removing headers"
	@for h in $(HEADERS); do \
	  $(RM) $(includedir)/wx/$(HEADER_SUBDIR)/$$h; \
	done
	@if test -d $(includedir)/wx/$(HEADER_SUBDIR); then \
	  rmdir $(includedir)/wx/$(HEADER_SUBDIR); \
	fi
	@-rmdir $(includedir)/wx

clean:
	$(RM) $(OBJECTS) $(top_builddir)/lib/$(TARGETLIB_SHARED) \
	      $(top_builddir)/lib/$(TARGETLIB_LINK1) \
	      $(top_builddir)/lib/$(TARGETLIB_LINK2) \
	      $(top_builddir)/lib/$(TARGETLIB_STATIC) core

.PHONY: all shared static clean install install_static install_shared uninstall

