# Copyright (C) 2011-2013 G.P. Halkes
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
.POSIX:

# C-compiler flags
CFLAGS=-O2

# Configuration flags and libraries. Include flags here to compile against the
# libt3config and libtinfo or (n)curses library
# If your system does not provide strdup, remove -DHAS_STRDUP
CONFIGFLAGS=-DHAS_STRDUP
CONFIGLIBS=

# The libtool executable
LIBTOOL=libtool

# Installation prefix and datadir (also defined in Makefile)
prefix=/usr/local
datadir=$(prefix)/share

# Gettext configuration
# GETTEXTFLAGS should contain -DUSE_GETTEXT to enable gettext translations
# GETTEXTLIBS should contain all link flags to allow linking with gettext, if
# it has been enabled. The GNU libc already contains the gettext library, so
# there is no need to add any flags. Otherwise, -lintl is usually required, and
# sometimes -liconv as well.
# LOCALEDIR: the directory where the locale dependant files should be installed.
# LINGUAS: translations to be installed. Look in po directory for available
#  translations.
GETTEXTFLAGS=
GETTEXTLIBS=
# LOCALEDIR is also defined in Makefile
LOCALEDIR=$(prefix)/share/locale
LINGUAS=

SILENCELT=--silent
SILENTCCLT=@echo '[CCLT]' $< ;
SILENTLDLT=@echo '[LDLT]' $@ ;

# Miscelaneous install paths
libdir=$(prefix)/lib

all: src/libt3key.la

.PHONY: all clean dist-clean
.SUFFIXES: .c .o .lo .la .mo .po
.SECONDARY: # Tell GNU make not to delete intermediate files

OBJECTS=src/key.lo src/key_shared.lo

clean:
	rm -rf src/*.lo src/.libs src/libt3key.la

dist-clean: clean

.c.lo:
	$(SILENTCCLT) $(LIBTOOL) $(SILENCELT) --mode=compile --tag=CC $(CC) -shared $(CFLAGS) -Isrc \
		$(CONFIGFLAGS) $(GETTEXTFLAGS) -DT3_KEY_BUILD_DSO -DLOCALEDIR=\"$(LOCALEDIR)\" \
		-DDB_DIRECTORY=\"$(datadir)/libt3key1\" -c -o $@ $<

src/libt3key.la: $(OBJECTS)
	$(SILENTLDLT) $(LIBTOOL) $(SILENCELT) --mode=link --tag=CC $(CC) -shared -version-info 1:0:0 \
		$(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS) $(GETTEXTLIBS) \
		$(CONFIGLIBS) -rpath $(libdir)

