# -*- mode: makefile -*-
# vim:syntax=make

# Set hardened CFLAGS
HARDENED_CFLAGS = $(shell dpkg-buildflags --get CFLAGS 2>/dev/null | sed -e 's/-g\|-O2//g')
HARDENED_CFLAGS += $(shell dpkg-buildflags --get CPPFLAGS)
ifeq (,$(HARDENED_CFLAGS))
  # Handle case for versions of Debian/Ubuntu that have dpkg-dev (<< 1.15.7).
  HARDENED_CFLAGS = -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2
endif

# Set CFLAGS from DEB_CFLAGS if defined, otherwise let xvidcore's build system
# set CFLAGS to use.
DEFAULT_CFLAGS = -Wall -O3 -fstrength-reduce -finline-functions -ffast-math \
                 -fomit-frame-pointer $(HARDENED_CFLAGS)
export CFLAGS = $(or $(DEB_CFLAGS),$(DEFAULT_CFLAGS))

export DEB_HOST_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
export DEB_HOST_ARCH_OS  ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

# Explicitely disable Altivec support on powerpc until we introduce flavours
ifeq ($(DEB_HOST_ARCH_CPU),powerpc)
	confflags += --disable-assembly
endif

# Explicitely disable yasm support on kfreebsd, it's broken on 64bit;
# see: http://www.freebsd.org/cgi/cvsweb.cgi/ports/multimedia/xvid/Makefile?rev=1.36
ifeq ($(DEB_HOST_ARCH_OS),kfreebsd)
	confflags += --disable-assembly
endif
