###############################################################################
# This file is part of the IPCop Firewall.                                    #
#                                                                             #
# IPCop is free software; you can redistribute it and/or modify               #
# it under the terms of the GNU General Public License as published by        #
# the Free Software Foundation; either version 2 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# IPCop is distributed in the hope that it will be useful,                    #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with IPCop; if not, write to the Free Software                        #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA    #
#                                                                             #
# Makefiles are based on LFSMake, which is                                    #
# Copyright (C) 2002 Rod Roard <rod@sunsetsystems.com>                        #
#                                                                             #
# Modifications by:                                                           #
# ??-12-2003 Mark Wormgoor < mark@wormgoor.com>                               #
#          - Modified Makefile for IPCop build                                #
#                                                                             #
# $Id: freetype 7330 2014-03-15 19:44:41Z owes $
#                                                                             #
###############################################################################

###############################################################################
# Definitions
###############################################################################

include Config

PKG_NAME   = freetype
VER        = 2.5.3
HOST_ARCH  = all
OTHER_SRC  = yes

THISAPP    = $(PKG_NAME)-$(VER)
DL_FILE    = $(THISAPP).tar.bz2
DL_FROM    = $(URL_SFNET)/$(PKG_NAME)
DIR_APP    = $(DIR_SRC)/$(THISAPP)
TARGET     = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP)

###############################################################################
# Top-level Rules
###############################################################################

objects = $(DL_FILE)

$(DL_FILE) = $(DL_FROM)/$(DL_FILE)

$(DL_FILE)_MD5 = d6b60f06bfc046e43ab2a6cbfd171d65

install : $(TARGET)

check : $(patsubst %,$(DIR_CHK)/%,$(objects))

download :$(patsubst %,$(DIR_DL)/%,$(objects))

md5 : $(subst %,%_MD5,$(objects))

###############################################################################
# Downloading, checking, md5sum
###############################################################################

$(patsubst %,$(DIR_CHK)/%,$(objects)) :
	@$(CHECK)

$(patsubst %,$(DIR_DL)/%,$(objects)) :
	@$(LOAD)

$(subst %,%_MD5,$(objects)) :
	@$(MD5)

###############################################################################
# Installation Details
###############################################################################

$(TARGET) : $(firstword $(MAKEFILE_LIST)) $(patsubst %,$(DIR_DL)/%,$(objects))
	@$(PREBUILD)
	@rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar jxf $(DIR_DL)/$(DL_FILE)

	# configuration may have three stages
	# 1 select modules in modules.cfg (look to have priority to next ftoption.h)
	# 2 select some option in include/freetype/config/ftoption.h
	# (no more used as BYTECODE_INTERPRETER is now enabled by default since that patent expired)
	# subpixel rending patents still expire in 2019 according to wikipedia
	# 3 ./configure

	# Disabling modules reduce space, memory usage, reduce attack surface, ...
	# Mostly remove other fonts support than truetype, but rrdtool is not very modular with regard to cairo ps, svg, pdf options
	# compression (gzip only) is needed to avoid linker errors later
	# rddtool need ps support
	# -e 's:FONT_MODULES.*type1:# &:'
	# -e 's:HINTING_MODULES.*pshinter:# &:'
	# -e 's:AUX_MODULES.*psaux:# &:'
	# -e 's:AUX_MODULES.*psnames:# &:'
	# pango want more ps
	# -e 's:BASE_EXTENSIONS.*fttype1.c:# &:'

	cd $(DIR_APP) && sed -i 		\
				-e 's:FONT_MODULES.*cff:# &:'		\
				-e 's:FONT_MODULES.*cid:# &:'		\
				-e 's:FONT_MODULES.*pfr:# &:'		\
				-e 's:FONT_MODULES.*type42:# &:'	\
				-e 's:FONT_MODULES.*winfonts:# &:'	\
				-e 's:FONT_MODULES.*pcf:# &:'		\
				-e 's:FONT_MODULES.*bdf:# &:'		\
				-e 's:AUX_MODULES.*lzw:# &:'		\
				-e 's:AUX_MODULES.*bzip2:# &:'		\
				-e 's:BASE_EXTENSIONS.*ftbdf.c:# &:'	\
				-e 's:BASE_EXTENSIONS.*ftcid.c:# &:'	\
				-e 's:BASE_EXTENSIONS.*ftfstype.c:# &:'	\
				-e 's:BASE_EXTENSIONS.*ftwinfnt.c:# &:'	\
				-e 's:BASE_EXTENSIONS.*ftxf86.c:# &:' modules.cfg

	# Disable compression as only pcf font use that.
	# As a side effect, this correct 'gcc static flag -static works' test on 2.4.10 and before. This test is fixed after 2.4.10
	cd $(DIR_APP) && ./configure --prefix=/usr --disable-static --without-bzip2 --with-zlib
	cd $(DIR_APP) && make -j $(PARALLELISM)
	cd $(DIR_APP) && make install

	rm -f $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/{libgd-*,fontconfig-*,cairo-*}
	@rm -rf $(DIR_APP)
	@$(POSTBUILD)
