###############################################################################
#                                                                             #
# IPFire.org - A linux based firewall                                         #
# Copyright (C) 2007-2011  IPFire Team  <info@ipfire.org>                     #
#                                                                             #
# This program 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 3 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       #
#                                                                             #
###############################################################################

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

include Config

VER        = 2012h
TZDATA_VER = 2012h
TZCODE_VER = 2012h

THISAPP    = tzdata-$(VER)
DL_FROM    = $(URL_IPFIRE)
DIR_APP    = $(DIR_SRC)/$(THISAPP)
TARGET     = $(DIR_INFO)/$(THISAPP)

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

objects = tzdata$(TZDATA_VER).tar.gz tzcode$(TZCODE_VER).tar.gz

tzdata$(TZDATA_VER).tar.gz = $(DL_FROM)/tzdata$(TZDATA_VER).tar.gz
tzcode$(TZCODE_VER).tar.gz = $(DL_FROM)/tzcode$(TZCODE_VER).tar.gz

tzdata$(TZDATA_VER).tar.gz_MD5 = b937335e087fb85b7f8e3ce33e69184b
tzcode$(TZCODE_VER).tar.gz_MD5 = 44b3b6c3e50240ac44f16437040a7ba2

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) : $(patsubst %,$(DIR_DL)/%,$(objects))
	@$(PREBUILD)
	@rm -rf $(DIR_APP) && mkdir -pv $(DIR_APP)
	mkdir -pv $(DIR_APP)/tzdata$(TZDATA_VER) $(DIR_APP)/tzcode$(TZCODE_VER)
	tar axf $(DIR_DL)/tzdata$(TZDATA_VER).tar.gz -C $(DIR_APP)
	tar axf $(DIR_DL)/tzcode$(TZCODE_VER).tar.gz -C $(DIR_APP)

	cd $(DIR_APP) && make TOPDIR=/usr ETCDIR=/tmp LIBDIR=/tmp MANDIR=/tmp \
		TZDIR=/usr/share/zoneinfo all
	cd $(DIR_APP) && make TOPDIR=/usr ETCDIR=/tmp LIBDIR=/tmp MANDIR=/tmp \
		TZDIR=/usr/share/zoneinfo install

	-mkdir -pv /usr/share/zoneinfo
	mv -v /usr/share/zoneinfo-posix /usr/share/zoneinfo/posix
	mv -v /usr/share/zoneinfo-leaps /usr/share/zoneinfo/right
	rm -vf /usr/share/zoneinfo/localtime

	cp -vf /usr/share/zoneinfo/GMT /etc/localtime
	@rm -rf $(DIR_APP)
	@$(POSTBUILD)
