###############################################################################
# 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: adjust-toolchain 1300 2008-04-18 15:18:38Z chepati $
#                                                                             #
###############################################################################

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

include Config

PKG_NAME   = adjust-toolchain
HOST_ARCH  = all
OTHER_SRC  = no

THISAPP    = adjust-toolchain
TARGET     = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP)
CFLAGS     =
CXXFLAGS   =

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

install : $(TARGET)

check :

download :

md5 :

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

$(TARGET) :
	@$(PREBUILD)

ifeq "$(STAGE)" "toolchain"
	mv -v /$(TOOLS_DIR)/bin/ld /$(TOOLS_DIR)/bin/ld-old
	mv -v /$(TOOLS_DIR)/$$(gcc -dumpmachine)/bin/ld /$(TOOLS_DIR)/$$(gcc -dumpmachine)/bin/ld-old
	mv -v /$(TOOLS_DIR)/bin/ld-new /$(TOOLS_DIR)/bin/ld
	ln -sv /$(TOOLS_DIR)/bin/ld /$(TOOLS_DIR)/$$(gcc -dumpmachine)/bin/ld

	gcc -dumpspecs | sed 's@$(LINKER)@/$(TOOLS_DIR)&@g' \
		> `dirname $$(gcc -print-libgcc-file-name)`/specs

	# The following needs testing
	#GCC_INCLUDEDIR=`dirname $$(gcc -print-libgcc-file-name)`/include
	#find $$GCC_INCLUDEDIR/* -maxdepth 0 -xtype d -exec ls -la '{}' ';'
	#ls -la `grep -l "DO NOT EDIT THIS FILE" $$GCC_INCLUDEDIR/*`
	#unset GCC_INCLUDEDIR
endif

ifeq "$(STAGE)" "base"
	mv -v /$(TOOLS_DIR)/bin/ld /$(TOOLS_DIR)/bin/ld-old
	mv -v /$(TOOLS_DIR)/$$(gcc -dumpmachine)/bin/ld /$(TOOLS_DIR)/$$(gcc -dumpmachine)/bin/ld-old
	mv -v /$(TOOLS_DIR)/bin/ld-new /$(TOOLS_DIR)/bin/ld
	ln -sv /$(TOOLS_DIR)/bin/ld /$(TOOLS_DIR)/$$(gcc -dumpmachine)/bin/ld

	gcc -dumpspecs | sed \
		-e 's@/$(TOOLS_DIR)$(LINKER)@$(LINKER)@g' \
		-e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
		-e '/\*cpp:/{n;s@$$@ -isystem /usr/include@}' > \
		`dirname $$(gcc --print-libgcc-file-name)`/specs
endif

	@$(POSTBUILD)
