########################################################################
# This file should be included by all other Makefiles in the project.
# Global configuration belongs here.
default: all
all:

########################################################################
# You can touch these:
########################################################################
ShakeNMake.QUIET ?= 0# set to 1 to enable "quiet mode"

########################################################################
# Set ENABLE_DEBUG to 1 to enable whefs debugging information.
DEBUG ?= 1
ENABLE_DEBUG ?= $(DEBUG)

########################################################################
# Set USE_PTHREADS to 1 to enable the pthreads-based mutex in the
# paging allocator. (Not currently used.)
USE_PTHREADS := 1

SQLITE3_CFLAGS := -Wno-long-long
GCC_CFLAGS := -pedantic -Wall -Werror -fPIC $(SQLITE3_CFLAGS)
LDFLAGS += -fPIC

CFLAGS += $(GCC_CFLAGS)
CXXFLAGS += $(GCC_CFLAGS)

ifneq (tcc,$(CC))
# Strict C89 mode is broken (==not portable) on 32-bit platforms
# for the time being due to non-portability of, e.g. PRIu64
# on 32-bit pltforms
CFLAGS += -std=c89
#CFLAGS += -std=c99
# Without the -std flag, gcc supports a subset of C99, but sqlite3.h
# uses (long long), which breaks -Wall -Werror.
# CFLAGS +=
endif

########################################################################
# Don't touch anything below this line unless you need to tweak it to
# build on your box:

########################################################################
# Calculate the top of the source tree, in case this is included
# from a subdir.
CONFIG.MAKEFILE := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
$(CONFIG.MAKEFILE):
TOP_SRCDIR_REL := $(dir $(CONFIG.MAKEFILE))
TOP_SRCDIR_REL := $(patsubst %/,%,$(TOP_SRCDIR_REL))# horrible kludge
#TOP_SRCDIR := $(shell cd -P $(TOP_SRCDIR_REL) && pwd)
TOP_SRCDIR := $(realpath $(TOP_SRCDIR_REL))
#$(error TOP_SRCDIR_REL=$(TOP_SRCDIR_REL)   TOP_SRCDIR=$(TOP_SRCDIR))
TOP_INCDIR := $(TOP_SRCDIR_REL)/include
INCLUDES += -I. -I$(TOP_INCDIR) -I$(HOME)/include
CPPFLAGS += $(INCLUDES)

SRC_DIR ?= .#$(PWD)
ShakeNMake.CISH_SOURCES := \
	$(wildcard *.c)

########################################################################
# common.make contains config-independent make code.
include $(TOP_SRCDIR_REL)/common.make
ALL_MAKEFILES := $(PACKAGE.MAKEFILE) $(ShakeNMake.MAKEFILE) $(CONFIG.MAKEFILE)
$(ALL_MAKEFILES):

SEARCH_PATH.H := $(HOME)/include /usr/local/include /usr/include 
SEARCH_PATH.DLL := $(HOME)/lib /usr/local/lib /usr/lib

########################################################################
ifeq (1,$(ENABLE_DEBUG))
  CPPFLAGS += -UNDEBUG -DDEBUG=1
  CFLAGS += -g
  CXXFLAGS += -g
else
  CFLAGS += -O2
  CPPFLAGS += -UDEBUG -DNDEBUG=1
endif

CLEAN_FILES += $(wildcard *.o *~)
