###############################################################################
# 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: syslinux 7552 2014-05-18 10:48:22Z owes $
#                                                                             #
###############################################################################

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

include Config

PKG_NAME   = syslinux
VER        = 6.02
HOST_ARCH  = i486
OTHER_SRC  = yes

THISAPP    = $(PKG_NAME)-$(VER)
DL_FILE    = $(THISAPP).tar.xz
DL_FROM    = $(URL_KERNEL)/linux/utils/boot/syslinux
DIR_APP    = $(DIR_SRC)/$(THISAPP)
TARGET     = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP)

CFLAGS    += -fno-PIE -nopie -norelro -nonow -nocombreloc
LDFLAGS   := -nopie

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

objects = $(DL_FILE)

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

$(DL_FILE)_MD5 = 6f275813a1b08cf852e55c0a3f8fbc78

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)) $(DIR_SRC)/config/arch/i486/extlinux.conf
	@$(PREBUILD)
	@rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar xf $(DIR_DL)/$(DL_FILE)

	# Patching is only required if full recompilation is needed
	# If full recompilation is required, uncomment both
	#cd $(DIR_APP) && patch -p1 -i $(DIR_PATCHES)/$(PKG_NAME)-4.05_nopie.patch
	#cd $(DIR_APP) && make -s --no-print-directory spotless && make V=1

	# The recommended way is to use precompiled ldlinux.asm and only compile installer
	cd $(DIR_APP) && make bios installer
	cd $(DIR_APP) && make bios install

	# copy fresh created MBR and graphical menu helper to /boot
	cp -f /usr/share/syslinux/mbr.bin       /boot
	cp -f /usr/share/syslinux/{ldlinux.c32,libcom32.c32,libutil.c32}  /boot
	cp -f /usr/share/syslinux/vesamenu.c32  /boot

	# copy extlinux config to /boot
	cp -f $(DIR_SRC)/config/arch/i486/extlinux.conf 	/boot
	cp -f $(DIR_SRC)/config/arch/i486/splash.png		/boot

	@rm -rf $(DIR_APP)
	@$(POSTBUILD)
