SHELL		= /bin/sh
VPATH		= @srcdir@
top_builddir	= $(top_srcdir)

# Programs
@SET_MAKE@
CC		= @CC@
CPP		= @CPP@
LN_S		= @LN_S@
INSTALL		= @INSTALL@
MKINSTALLDIRS	= $(top_srcdir)/autoconf/mkinstalldirs.sh

# Default version number. Each individual directory is free to set their
# own version (if they wish).
MAJOR_VERSION	= 2
MINOR_VERSION	= 5
PATCH_LEVEL	= 5

DATE		:= $(shell date +%D)
VERSION		= $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_LEVEL)$(EXTRA_VERSION)

# Compiler flags
CFLAGS		= @CFLAGS@
LDFLAGS		= @LDFLAGS@
EVMS_CFLAGS	= -Wall -fPIC -fno-strict-aliasing
EVMS_CPPFLAGS	= -I$(top_srcdir)/include -I$(top_srcdir)/intl
EVMS_DEFS	= $(EVMS_DEBUG)				\
		  $(NLS_DEFS)				\
		  -DMAJOR_VERSION=$(MAJOR_VERSION)	\
		  -DMINOR_VERSION=$(MINOR_VERSION)	\
		  -DPATCH_LEVEL=$(PATCH_LEVEL)		\
		  -DVERSION=\"$(VERSION)\"		\
		  -DDATE=\"$(DATE)\"

EVMS_LDFLAGS	= $(LDFLAGS)
EVMS_LIBS	= @LIBINTL@ $(EFENCE_LIBS)
NLS_DEFS	= $(ENABLE_NLS) -DPACKAGE=\"@PACKAGE@\" -DLOCALEDIR=\"$(localedir)\"

PTHREAD_LIBS	= @PTHREAD_LIBS@
UUID_LIBS	= @UUID_LIBS@
NCURSES_LIBS	= @NCURSES_LIBS@
NCURSES_CPPFLAGS= @NCURSES_CPPFLAGS@
PANEL_LIBS	= @PANEL_LIBS@
READLINE_LIBS	= @READLINE_LIBS@
READLINE_DEFS	= @READLINE_DEFS@
MATH_LIBS	= @MATH_LIBS@
GLIB_LIBS	= @GLIB_LIBS@
GLIB_CPPFLAGS	= @GLIB_CPPFLAGS@
GLIB2_LIBS	= @GLIB2_LIBS@
GLIB2_CPPFLAGS	= @GLIB2_CPPFLAGS@
GTK_LIBS	= @GTK_LIBS@
GTK_CPPFLAGS	= @GTK_CPPFLAGS@
HA_LIBS		= @HA_LIBS@
HA_CPPFLAGS	= @HA_CPPFLAGS@
HA_RESOURCEDIR	= @HA_RESOURCEDIR@
HA_MAJOR	= @HA_MAJOR@
HA_MINOR	= @HA_MINOR@
HA_PATCH	= @HA_PATCH@
HA_GLIB_CPPFLAGS= @HA_GLIB_CPPFLAGS@
HA_GLIB_LIBS	= @HA_GLIB_LIBS@
HA_GS_R_LIBS	= @HA_GS_R_LIBS@
DEVMAPPER_LIBS	= @DEVMAPPER_LIBS@
EFENCE_LIBS	= @EFENCE_LIBS@
EVMS_DEBUG	= @EVMS_DEBUG@
ENABLE_NLS	= @ENABLE_NLS@

# Install directories
# By default, we want prefix to be "/usr", and exec_prefix to be "/". This
# will install the libraries in /lib, the plugins in /lib/evms, the UIs in
# /sbin, the headers in /usr/include/evms, and the man pages in /usr/man.
# However, autoconf only seems to let us set the default for prefix. So to
# make it all work correctly with the configure script, we have to play some
# games here. In the configure script, we set the prefix default to blank. If
# it is still blank here, we can assume the user has not specified a prefix,
# and we can set them up as we wish.
prefix		= @prefix@

ifeq ($(strip $(prefix)),)
	prefix		= /usr
	exec_prefix	=
else
	exec_prefix	= @exec_prefix@
endif

sbindir		= @sbindir@
libdir		= @libdir@
mandir		= @mandir@
includedir	= @includedir@
localedir	= @datadir@/locale
evmsheadersdir	= @includedir@/evms
evmspluginsdir	:= @libdir@/evms/$(VERSION)

# Variables that most Makefiles will use.
SOURCES		:= $(wildcard *.c)
HEADERS		:= $(wildcard *.h)
MANPAGES	:= $(wildcard *.8)
OBJECTS		= $(SOURCES:.c=.o)
SBIN_TARGET	= $(NAME)
LIB_TARGET	= lib$(NAME)-$(MAJOR_VERSION).$(MINOR_VERSION).so.0.$(PATCH_LEVEL)
PLUGIN_TARGET	= $(NAME)-$(VERSION).so
SONAME		= lib$(NAME)-$(MAJOR_VERSION).$(MINOR_VERSION).so.0
ARNAME		= lib$(NAME).a
LIBNAME		= lib$(NAME).so

# Macros to use to run make recursively over a set of directories, which
# must be specified in the $(subdirs) or $(distsubdirs) variable.
PROCESS_DIRS	=			\
	+@for dir in $(subdirs); do	\
		$(MAKE) -C $$dir $@ ||	\
		case "$(MAKEFLAGS)" in	\
			*k*) fail=yes;;	\
			*) exit 1;;	\
		esac;			\
	done && test -z "$$fail"

PROCESS_DISTDIRS =			\
	+@for dir in $(distsubdirs); do	\
		$(MAKE) -C $$dir $@ ||	\
		case "$(MAKEFLAGS)" in	\
			*k*) fail=yes;;	\
			*) exit 1;;	\
		esac;			\
	done && test -z "$$fail"

# Macros to build libraries and binaries.
BUILD_SHARED_LIB = $(CC) -shared $(EVMS_LDFLAGS) -Wl,-soname,$(SONAME),--version-script,.export -o $(TARGET) $(OBJECTS) $(EVMS_LIBS)
BUILD_STATIC_LIB = $(AR) rcs $(ARNAME) $(OBJECTS)
BUILD_PLUGIN = $(CC) -shared $(EVMS_LDFLAGS) -Wl,--version-script,.export -o $(TARGET) $(OBJECTS) $(EVMS_LIBS)
BUILD_SBIN = $(CC) -L$(top_srcdir)/engine $(EVMS_LDFLAGS) -o $(TARGET) $(OBJECTS) -levms $(EVMS_LIBS) $(PTHREAD_LIBS)

.PHONY: install uninstall clean distclean
.SUFFIXES: .c .o

# Compiling .c's to .o's
%.o: %.c
	$(CC) $(EVMS_CPPFLAGS) $(CPPFLAGS) $(EVMS_DEFS) $(EVMS_CFLAGS) $(CFLAGS) -c $< -o $@

# Generating dependencies
.depend:
	$(CPP) -M $(EVMS_CPPFLAGS) $(CPPFLAGS) $(EVMS_DEFS) $(SOURCES) > .depend

# Generating linker version-scripts for the plugins.
.export:
	echo "EVMS { global: evms_plugin_records; local: *; };" > .export

