#!/bin/bash
# Copyright (c) 2000-2014 Synology Inc. All rights reserved.

if ! checkPlatformFunction SYNO_FEA_ROUTER_COMMON; then
	SkipThisProject
	return
fi

case ${MakeClean} in
	[Yy][Ee][Ss])
		make clean
		;;
esac

case ${CleanOnly} in
	[Yy][Ee][Ss])
		return
		;;
esac

put_autogen_file ()
{
	local scripts_dir="synoscripts"
	local autogen_dir="${scripts_dir}/autogen/"
	cp -rf ./${autogen_dir}/* ./

	# Fixup timestamps
	# In autotools, generated files are treated as stale (i.e., need regeneration)
	# if its timestamp is not newer than its originator.
	# This would trigger unnecessary regen if we commit all these files into VCS,
	# as the timestamps are not preserved on all files.
	# So we employ the fix suggested in [1] to update the timestamp, since we're
	# pretty sure that we don't need regeneration in this case...
	# [1]: http://www.gnu.org/software/automake/manual/html_node/CVS.html
	echo -n "Fixing timestamps ..."
	${scripts_dir}/fixtimestamp.sh
	echo " Done."
}

put_autogen_file

env CC="${CC}" CXX="${CXX}" LD="${LD}" AR=${AR} STRIP=${STRIP} RANLIB=${RANLIB} NM=${NM} \
	CFLAGS="${CFLAGS}" CXXFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS} -Wl,-rpath,/usr/syno/lib" \
	PKG_CONFIG_PATH="/usr/syno/lib/pkgconfig:${PKG_CONFIG_PATH}" \
	./configure ${ConfigOpt} --prefix=${SynoDir}

make ${MAKE_FLAGS}
