# $FreeWRT: src/share/misc/licence.template,v 1.7 2006/04/09 22:08:49 tg Rel $ */
#-
# Copyright (c) 2006
#	Thorsten Glaser <tg@mirbsd.de>
#
# Licensee is hereby permitted to deal in this work without restric-
# tion, including unlimited rights to use, publicly perform, modify,
# merge, distribute, sell, give away or sublicence, provided all co-
# pyright notices above, these terms and the disclaimer are retained
# in all redistributions or reproduced in accompanying documentation
# or other materials provided with binary redistributions.
#
# All advertising materials mentioning features or use of this soft-
# ware must display the following acknowledgement:
#	This product includes material provided by Thorsten Glaser.
# This acknowledgement does not need to be reprinted if this work is
# linked into a bigger work whose licence does not allow such clause
# and the author of this work is given due credit in the bigger work
# or its documentation. Specifically, re-using this code in any work
# covered by the GNU General Public License version 1 or Library Ge-
# neral Public License (any version) is permitted.
#
# Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
# express, or implied, to the maximum extent permitted by applicable
# law, without malicious intent or gross negligence; in no event may
# licensor, an author or contributor be held liable for any indirect
# or other damage, or direct damage except proven a consequence of a
# direct error of said person and intended use of this work, loss or
# other issues arising in any way out of its use, even if advised of
# the possibility of such damage or existence of a nontrivial bug.

GMAKE?=		$(PWD)/lbin/gmake
GMAKE_INV=	PATH=$(PWD)/lbin:$(PATH) ${GMAKE} -f $(PWD)/build.mk ${VARS_TO_PASS}

VARS_TO_PASS=	HOSTCC='${CC}' MAKE='${GMAKE}' LC_ALL=C \
		HOSTCFLAGS="$$(set +x; x=$$(echo \
		    'f:\n\techo P:$${CFLAGS}\n.include <bsd.prog.mk>' | \
		    ${MAKE} -f - f EXPERIMENTAL=yes 2>/dev/null | grep '^P:' \
		    2>/dev/null | sed 's/^P://'); echo $${x:--O2 ${CFLAGS}})"

all: prereq
	${GMAKE_INV} all

v: prereq
	(set -x; ${GMAKE_INV} all V=99) 2>&1 | tee -a make.log

verbose: prereq
	${GMAKE_INV} all V=99

clean: prereq
	${GMAKE_INV} clean

config: prereq
	${GMAKE_INV} config

cleandir: prereq
	${GMAKE_INV} cleandir
	@-rm -rf lbin
	@-rm -f make.log prereq

distclean: prereq
	${GMAKE_INV} distclean
	@-rm -rf lbin
	@-rm -f make.log prereq

image_clean: prereq
	${GMAKE_INV} image_clean

menuconfig: prereq
	${GMAKE_INV} menuconfig

oldconfig: prereq
	${GMAKE_INV} oldconfig

package_index: prereq
	${GMAKE_INV} package_index

source: prereq
	${GMAKE_INV} source

target_clean: prereq
	${GMAKE_INV} target_clean

world: prereq
	${GMAKE_INV} world

prereq:
	@-rm -rf prereq lbin
	@mkdir lbin
	@if which gmake >/dev/null 2>&1; then \
		ln -s $$(which gmake) lbin/gmake; \
	else \
		ln -s $$(which make) lbin/gmake; \
	fi
	@if ! which md5sum >/dev/null 2>&1; then \
		cp scripts/md5sum.bsd lbin/md5sum; \
		chmod 555 lbin/md5sum; \
	fi
	@touch $@
