##############################################################################
# Makefile definitions and common commands
#
# Setup of C definitions based on makeconfig options
#
# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).
# Note: the configurable options are in makeconfig.
#
# Copyright (C) 2009-2010 Francesco Abbate. See Copyright Notice in gsl-shell.c
##############################################################################

AR= ar rcu
RANLIB= ranlib
CP_REL = cp --parents

CC = gcc
CXX = g++

LINK_EXE = $(CC) $(LDFLAGS)

ifeq ($(HOST_SYS),Windows)
  INCLUDES += -I/usr/include
  LDFLAGS += -Wl,--enable-auto-import
  LIBS += -L/usr/lib
else
  ifeq ($(HOST_SYS),Darwin)
    LINK_EXE = $(CXX) $(LDFLAGS)
    # Use rsync because the --parents option to cp doesn't exist in
    # Mac OS X
    CP_REL = rsync -R
    LDFLAGS += -L/usr/X11/lib -undefined dynamic_lookup -pagezero_size 10000 -image_base 100000000
  else
    LDFLAGS += -Wl,-E
  endif
endif

ifeq ($(strip $(LUA_BUILD)), yes)
  PACKAGE_NAME = lua
  PACKAGE_VERSION = 5.1
else
  PACKAGE_NAME = gsl-shell
  PACKAGE_VERSION = 2.3
endif

ifeq ($(strip $(DEBUG)), yes)
  CFLAGS = -g -Wall
  CXXFLAGS = -g -Wall
else
  # on windows do not use -fomit-frame-pointer
  CFLAGS = -O3 -fno-stack-protector -fomit-frame-pointer -ffast-math -Wall
  CXXFLAGS = -Os -fno-exceptions -fno-stack-protector -ffast-math -fno-rtti -Wall
endif

DEFS += -D_REENTRANT
LIBS += -lsupc++

ifeq ($(HOST_SYS),Windows)
  DEFS += -DWIN32
  EXE_EXT = .exe
  DLL_EXT = .dll
  LDFLAGS += -Wl,--export-all-symbols
else
  EXE_EXT =
  DLL_EXT = .so
  DEFS += -pthread
  LIBS += -pthread
  LDFLAGS += -Wl,-E
endif

ifeq ($(strip $(DEBUG)), yes)
  DEFS += -DGSL_SHELL_DEBUG
endif

ifeq ($(strip $(DISABLE_GAMMA_CORR)), yes)
  DEFS += -DDISABLE_GAMMA_CORR
endif

ifeq ($(strip $(DISABLE_SUBPIXEL_LCD)), yes)
  DEFS += -DDISABLE_SUBPIXEL_AA
endif

ifeq ($(strip $(USE_READLINE)),yes)
  ifneq ($(HOST_SYS),Windows)
    DEFS += -DUSE_READLINE
  else
    USE_READLINE = no
  endif
endif
