# Makefile configuration for Hatari.
#
# Use of '?=' for assignment allows overriding the given value with
# an environment variable, like this:
# 	HOSTCC=my-hostcc make
# or:
#	export HOSTCC=my-hostcc
#	make
#
# Following variables can be overridden like that:
#   CPPFLAGS, LDFLAGS, LIBS, HOSTCC, DATADIR, CONFDIR, BINDIR, MANDIR, DOCDIR
#
# GNU make itself supports overriding CC like this:
#	make CC=my-cc

# Set the C compiler (e.g. gcc)
CC = gcc

OPTFLAGS = -O2

# Architecture specific settings
#
# Omap2/ARMv6:
# OPTFLAGS += -mfpu=vfp -mfloat-abi=softfp -march=armv6 -finline-limit=64
#
# Wii/Gekko:
# OPTFLAGS = -MMD -MP -MF -O3 -mrvl -mcpu=750 -meabi -mhard-float
# CPPFLAGS = -DGEKKO -I$(DEVKITPRO)/libogc/include -I$(DEVKITPRO)/libogc/include/sdl
# LDFLAGS = -L$(DEVKITPRO)/libogc/lib/wii -Wl,-Map,hatari.map
# LIBS = -lz -lfat -lwiiuse -lbte -lasnd -logc -lm

# What warnings to use
WARNFLAGS = -Wmissing-prototypes -Wstrict-prototypes -Wsign-compare \
  -Wbad-function-cast -Wcast-qual  -Wpointer-arith \
  -Wall -Wwrite-strings # -Wshadow -Wcast-align -Werror


ifneq ($(MUDFLAP),)
# Run-time checks with GCC "mudflap" etc:
# - stack protection
# - checking of pointer accesses (AFAIK works only on x86)
#
# Before build, install "libmudflap<version>-<gcc-version>-dev"
# package (libmudflap0-4.3-dev in Debian Lenny).
#
# To build, use:
#	make clean; make MUDFLAP=1
#
# To run, use something like (disable sound as it can break things):
#   MUDFLAP_OPTIONS="-viol-gdb" ./hatari --sound off
#
# For more info, see (for now, works properly only for x86 gcc):
#   http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging
#
RUNCHECKS = -fstack-protector-all -fmudflapth #-fmudflapir
LDRUNCHECKS = -fmudflapth -lmudflap
endif


# Set flags passed to the compiler (e.g. optimization flags)
CFLAGS := -g $(WARNFLAGS) $(OPTFLAGS) $(RUNCHECKS)

# Set flags passed to the preprocessor (e.g. -I<include dir>)
CPPFLAGS ?=

# Additional libraries and linker flags:
LIBS ?= -lz -lm # -lreadline
LDFLAGS ?= $(LDRUNCHECKS)

# Ranlib - for generating an index of an archive
RANLIB = ranlib


# The native C compiler.
# This is normally the same as $(CC) unless you are using a cross compiler.
HOSTCC ?= $(CC)

# Native C compiler flags:
HOSTCFLAGS = -g -O -Wall

# Native linker flags:
HOSTLDFLAGS =


# SDL-Library configuration (compiler flags and linker options) - you normally
# don't have to change this if you have correctly installed the SDL library!
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LIBS := $(shell sdl-config --libs)

# libpng configuration (for PNG format screenshots)
PNG_LIBS := $(shell pkg-config --silence-errors --libs libpng)
ifneq ($(PNG_LIBS),)
PNG_CFLAGS := -DHAVE_LIBPNG=1 $(shell pkg-config --cflags libpng)
endif

# X11 configuration (for SDL window embedding)
X11_LIBS := $(shell pkg-config --silence-errors --libs x11)
ifneq ($(X11_LIBS),)
X11_CFLAGS := -DHAVE_X11=1 $(shell pkg-config --cflags x11)
endif

# PORTAUDIO configuration (to support Falcon microphone)
PORTAUDIO_LIBS := $(shell pkg-config --silence-errors --libs portaudio-2.0)
ifneq ($(PORTAUDIO_LIBS),)
PORTAUDIO_CFLAGS := -DHAVE_PORTAUDIO=1 $(shell pkg-config --cflags portaudio-2.0)
endif

# Here you can define the default data directory for Hatari.
# The emulator looks there for the default TOS image etc.
# For example you can use the local directory with "." or if you want
# a system-wide installation, use something like "/usr/share/hatari".
DATADIR ?= .

# In this folder, Hatari searches the global configuration file.
# /etc or /usr/local/etc is a good place for this.
CONFDIR ?= /etc

# The executable will be installed in BINDIR
#BINDIR ?= /usr/local/bin

# The man-page will be install in MANDIR
#MANDIR ?= /usr/local/share/man/man1

# All other documentation will be installed in DOCDIR
#DOCDIR ?= /usr/local/share/doc/hatari

# Program used for "make install"
#INSTALL = install -c
#INSTALL_PROGRAM = $(INSTALL) -s -m 755
#INSTALL_SCRIPT = $(INSTALL) -m 755
#INSTALL_DATA = $(INSTALL) -m 644

