#!/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])
		return
		;;
esac

REQUIRES="libsynosdk libsynorecycle libsynofileop libsynocurconn libsynoacl synologd libplist synocontentsearchutils"
INCS="$(pkg-config --cflags ${REQUIRES})"
LIBS="$(pkg-config --libs ${REQUIRES}) -lpthread -lcrypt"

cp config/netatalk.PAM config/netatalk.PAM.cache
if [ "$BUILD_ARCH" = "64" ]; then
	sed -i -e 's/@LIBDIR@/\/lib64/' config/netatalk.PAM.cache
	LIB_PATH="/lib64"
else
	sed -i -e 's/@LIBDIR@/\/lib/' config/netatalk.PAM.cache
	LIB_PATH="/lib"
fi

# If netatalk need show some debug log, please add below options,
# "--enable-debug --enable-debug1", to configure.

# netatalk_cv_SIZEOF_OFF_T=yes/cross both turn on afp large file support
# therefore, we don't need to set yes
# set ac_cv_func_openat=no to ensure the HAVE_ATFUNCS is disabled
# (MARVELL toolchain has those function)


env CC="${CC}" AR="${AR}" RANLIB="${RANLIB}" STRIP="${STRIP}" \
	CFLAGS="${CFLAGS} -Wall" \
	CPPFLAGS="${CFLAGS} ${INCS}" \
	LDFLAGS="${LDFLAGS} -Wl,--as-needed" \
	LIBS="${LIBS}" \
	ac_cv_func_memcmp_working=yes \
	ac_cv_func_mmap_fixed_mapped=yes \
	./configure ${ConfigOpt} \
	--prefix=/usr \
	--program-prefix="" \
	--sbindir=/usr/bin \
	--bindir=/usr/bin \
	--localstatedir=/etc \
	--with-pkgconfdir=/etc \
	--with-bdb=${SysRootPrefix} \
	--with-uams-path=${LIB_PATH} \
	--with-ssl-dir=${SysRootPrefix} \
	--with-pam=${SysRootPrefix} \
	--with-gssapi=${SysRootPrefix} \
	--with-libgcrypt-dir=${SysRootPrefix} \
	--with-lockfile=/var/run/netatalk.pid \
	--enable-largefile \
	--enable-admin-group \
	--disable-tcp-wrappers \
	--without-libiconv \
	--without-ldap \
	--without-afpstats \
	--with-libevent=no \
	--enable-zeroconf=no

make ${MAKE_FLAGS}

