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

case ${makeClean} in
	[Yy][Ee][Ss])
		make distclean
		;;
esac

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

# No need of this for GPL release
# net-snmp-5.x/agent/mibgroup/syno-mib will be removed
if [ "$IsGPLBuild" = "yes" ]; then
	INCS=""
	LIBS=""
	WITH_MIB_MODULES=''
else
	REQUIRES="libsynosdk libsynostoragecore libhwcontrol libsynocurconn libsynocgi libcrypto"
	if checkPlatformFunction SYNO_FEA_SAS_SUPPORT; then
		REQUIRES+=" libsynosas"
	fi
	if checkPlatformFunction SYNO_FEA_GPU_SUPPORT; then
		REQUIRES+=" libsynogpuinfo"
	fi
	INCS="$(pkg-config --cflags $REQUIRES libsynoserviceutil libsynoflashcache)"
	LIBS="$(pkg-config --libs-only-l $REQUIRES) -lm"
	WITH_MIB_MODULES="ucd-snmp/diskio syno-mib"
fi

case "$PLATFORM_FAMILY" in
	SYNOPLAT_F_PPC)
		Endian="big"
		;;
	*)
		Endian="little"
		;;
esac

export PKG_CONFIG_PATH="${SysRootLib}/openssl-3/pkgconfig:${PKG_CONFIG_PATH}"

# remove --with-mib-modules="syno-mib" for GPL release
env CC="${CC}" \
	CPP="${CPP}" \
	CPPFLAGS="-DSYNO ${INCS}" \
	CFLAGS="${CFLAGS} -Wno-format-truncation" \
	LDFLAGS="${LDFLAGS}"\
	LIBS="${LIBS}" \
	./configure ${ConfigOpt} \
		--prefix=/usr \
		--disable-manuals \
		--disable-scripts \
		--disable-set-support \
		--disable-debugging \
		--without-perl-modules \
		--disable-embedded-perl \
		--disable-perl-cc-checks \
		--with-endianness="${Endian}" \
		--with-default-snmp-version="2" \
		--with-sys-contact="admin@diskstation" \
		--with-sys-location="Unknown" \
		--with-logfile="/var/log/snmpd.log" \
		--with-persistent-directory="/var/lib/net-snmp" \
		--with-cc="${CC}" \
		--with-linkcc="${CC}" \
		--without-nl \
		--with-ar=${AR} --enable-ipv6 --with-transports="UDPIPv6 TCPIPv6" \
		--with-mib-modules="${WITH_MIB_MODULES}" \
		--with-systemd \

make NOAUTODEPS=y ${MAKE_FLAGS}
