# Tools/MakeDefs
# define variables that can be overridden

ifndef PLATFORM
  PLATFORM := $(shell $(UTILS_DIR)/bin/config.guess)
  $(warning PLATFORM not defined, please set to '$(PLATFORM)')
endif

ifndef UTILS_DIR
  $(error Define UTILS_DIR in the shell environment)
endif
ifndef INSTALL_DIR
  $(error Define UTILS_DIR in the shell environment)
endif
ifneq ($(INSTALL_DIR), $(UTILS_DIR))
  $(error Sigh. UTILS_DIR and INSTALL_DIR must have the same value)
endif

include $(UTILS_DIR)/include/$(PLATFORM)/UtilsFlags.mk


JUNK = *.o *~ *.mk *.d *.a core* *.csv

# header files are installed into INC_DIR
INC_DIR = $(INSTALL_DIR)/include/$(INCLUDE_SUBTREE)$(strip $(SRC_MODULE))

# the library file is installed into LIB_DIR
LIB_DIR = $(INSTALL_DIR)/lib

# where to install the TARGET binary
BIN_DIR = $(INSTALL_DIR)/bin

LIBPRUNE = $(UTILS_DIR)/include/maketools/libsort_c

# Implicit make rules use these flags (per 'info make')
#   N.cc->N.o     $(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
#   N.o -> N      $(CC) $(LDFLAGS) N.o $(LOADLIBES) $(LDLIBS)
# and these rules on our version of gnu make (per 'make -p -f /dev/null')
#   N.cc->N.o     $(COMPILE.cc) $(OUTPUT_OPTION) $<
#   N.cc->N       $(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@
# where
#   LINK.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
#   COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
#   OUTPUT_OPTION = -o $@
# We define
#   N.cc -> N.d   $(CXX) $(CPPFLAGS) $(DEPFLAGS)

# primitive compilation variables
OPT_FLAGS = $(OPT) $(EXTRA_OPTS)
DEF_FLAGS = $(EXTRA_DEFS)
INCLUDE_FLAGS = -I. -I.. -I$(INSTALL_DIR)/include $(EXTRA_INC_DIRS)
#   (-I.. is for inclusions of the form #include Foo/asdasd.h)

#derived compilation variable; as used by make
CPPFLAGS =  $(DEF_FLAGS) $(INCLUDE_FLAGS)
CXXFLAGS = $(OPT_FLAGS)
DEPFLAGS = $(OPT_FLAGS) $(DEF_FLAGS)
CFLAGS = $(CXXFLAGS)

#otherwise unknown .o files should be linked with g++
LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)

# tool for simple link of a test program
CXXLINK =  $(CXX) $(CXXFLAGS) $(CPPFLAGS) $^ -o $@ $(LDFLAGS) $(LOADLIBES) $(LDLIBS)

# Default 'make' target; build in local directory
.PHONY: local
local: reallocal

ifneq "$(strip $(SUPPORT_MAKEFILES))" ""
include $(foreach f, $(SUPPORT_MAKEFILES), $(UTILS_DIR)/include/$f)
endif

