# -*- Mode: Makefile -*-

VGRIND = valgrind
OPTFLAGS = -O3
CFLAGS = $(OPTFLAGS) -Wall -W -Wcast-align -Wbad-function-cast -Wextra -Wmissing-noreturn -Wmissing-format-attribute -g3 -ggdb3   -Werror -fPIC -Wshadow -fvisibility=hidden
CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=500
LDFLAGS = -lz

DIRS = newbrt src
 # src cxx utils db-benchmark-test db-benchmark-test-cxx
include $(patsubst %,$(ROOT)%/Makefile.include,$(DIRS))

ifeq ($(VERBOSE),2)
VERBVERBOSE=-v
MAYBEATSIGN= 
else
 ifeq ($(VERBOSE),1)
  VERBVERBOSE=-q
  MAYBEATSIGN=
 else
  VERBVERBOSE=-q
  MAYBEATSIGN=@
 endif
endif

ifneq ($(OSX),)
LIBEXT=dylib
SHARED=-dynamiclib
RPATHNAME=-install_name @rpath/$(LIBRARY)
CFLAGS+=-fno-common
else
LIBEXT=so
SHARED=-shared $(EXPORTMAP)
RPATHNAME=
endif
LIBRARY=$(LIBNAME).$(LIBEXT)
TLIBRARY=$(TLIBNAME).$(LIBEXT)

ifeq ($(CYGWIN),cygwin)
else
FPICFLAGS = -fPIC
# valgrind is not present on cygwin
VGRIND = valgrind --quiet --error-exitcode=1 --leak-check=yes
endif

.PHONY: %.check
%.check: %
	$(VGRIND) ./$< $(VERBVERBOSE) 
