# $Id$

TARGET_ARCH	= @TARGET_ARCH@

SHELL		= @SHELL@
VPATH		= @srcdir@
srcdir		= @srcdir@
TOPDIR		= @TOPDIR@
top_builddir	?= $(TOPDIR)
MKRULESDIR	= @MKRULESDIR@

PREFIX		= @prefix@
DEST_EXEDIR	= $(PREFIX)/bin
DEST_LIBDIR	= $(PREFIX)/lib
DEST_HDRDIR_TOP	= $(PREFIX)/include

LIBTOOL_DEPS	= @LIBTOOL_DEPS@

MAKE		= LC_ALL=C @MAKE@
RM		= @RM@
MKDIR		= @MKDIR@
LIBTOOL		= LC_ALL=C @LIBTOOL@ --quiet

CC		= @CC@
CXX		= @CXX@

INSTALL		= @INSTALL@
INSTALL_DATA	= @INSTALL_DATA@
INSTALL_SCRIPT	= @INSTALL_SCRIPT@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@

BUILD_SRCDIR	= $(TOPDIR)/src
BUILD_INCDIR	= $(BUILD_SRCDIR)/include
BUILD_LIBDIR	= $(BUILD_SRCDIR)/lib

SITECONF_MK	?=	$(shell ls $(MKRULESDIR)/siteconf.mk 2>/dev/null)
ifdef SITECONF_MK
__SITECONF__=.pre.
include $(SITECONF_MK)
endif

NATALIB		= libnata.la

DEP_NATALIB	= $(BUILD_LIBDIR)/$(NATALIB)

CPPFLAGS	+= -I$(BUILD_INCDIR)

WARN_BASE_CFLAGS	+= -W -Wall -Wextra -pedantic \
	-Wshadow \
	-Wcast-align \
	-Wwrite-strings \
	-Wconversion \
	-Wmissing-format-attribute \
	-Wno-long-long \
	-Wno-variadic-macros

#	-Waddress
#	-Wlogical-op

WARN_CFLAGS	+= $(WARN_BASE_CFLAGS) \
	-Wstrict-prototypes \
	-Wold-style-definition \
	-Wmissing-declarations \
	-Wmissing-prototypes \
	-Wnested-externs \
	-Wdeclaration-after-statement


WARN_CXXFLAGS	+= $(WARN_BASE_CFLAGS) \
	-Wnon-virtual-dtor \
	-Wstrict-null-sentinel \
	-Woverloaded-virtual

DEBUG_CFLAGS	+= -g3
DEBUG_CXXFLAGS	+= -g3

OPT_CFLAGS	+= -O0 -fno-omit-frame-pointer
OPT_CXXFLAGS	+= -O0 -fno-omit-frame-pointer

CODEGEN_CFLAGS		+= -fkeep-inline-functions
CODEGEN_CXXFLAGS	+= -fkeep-inline-functions


COMMON_CFLAGS	= $(WARN_CFLAGS) $(DEBUG_CFLAGS) $(OPT_CFLAGS) \
	$(CODEGEN_CFLAGS) $(LOCAL_CFLAGS)

COMMON_CXXFLAGS	= $(WARN_CXXFLAGS) $(DEBUG_CXXFLAGS) $(OPT_CXXFLAGS) \
	$(CODEGEN_CXXFLAGS) $(LOCAL_CXXFLAGS)

CFLAGS		+= @OS_CFLAGS@ @CFLAGS@ $(COMMON_CFLAGS)
CXXFLAGS	+= @OS_CFLAGS@ @CXXFLAGS@ $(COMMON_CXXFLAGS)

LDFLAGS		+= @OS_LDFLAGS@ @OS_LIBS@ @LDFLAGS@

OBJS		?= $(SRCS:.cpp=.lo)

ifdef TARGET_LIB
SHLIB_VERSION	?= 0:0:0
LTLINK_VERSION	= -version-info $(SHLIB_VERSION)
endif
LTLINK_RPATH	= -rpath $(DEST_LIBDIR)

STATICBUILD	=	@STATICBUILD@
ifndef STATICBUILD
LT_SHARED	=	-shared
endif

LTCOMPILE_CC	= $(LIBTOOL) --mode=compile --tag=CC $(CC) $(CFLAGS) \
	$(CPPFLAGS) $(LT_SHARED)
LTCOMPILE_CXX	= $(LIBTOOL) --mode=compile --tag=CXX $(CXX) $(CXXFLAGS) \
	$(CPPFLAGS) $(LT_SHARED)
LTLINK_CC	= $(LIBTOOL) --mode=link \
	$(CC) $(CFLAGS) $(LTLINK_RPATH) $(LTLINK_VERSION) $(LT_SHARED)
LTLINK_CXX	= $(LIBTOOL) --mode=link \
	$(CXX) $(CXXFLAGS) $(LTLINK_RPATH) $(LTLINK_VERSION) $(LT_SHARED)
LTINSTALL_EXE	= $(LIBTOOL) --mode=install $(INSTALL_PROGRAM)
LTINSTALL_LIB	= $(LIBTOOL) --mode=install $(INSTALL_DATA)
LTINSTALL_HEADER= $(LIBTOOL) --mode=install $(INSTALL_DATA)
LTCLEAN		= $(LIBTOOL) --mode=clean $(RM)

ifdef SITECONF_MK
__SITECONF__=.post.
include $(SITECONF_MK)
endif
