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

if [[ ${MakeClean,,} = "yes" ]]; then
	make distclean
fi
if [[ ${CleanOnly,,} = "yes" ]]; then
	return
fi

NCURSES_CFLAGS=$(pkg-config --cflags ncurses)
NCURSES_LIBS=$(pkg-config --libs ncurses)

CFLAGS="${CFLAGS} ${NCURSES_INCLUDES}"
LDFLAGS="${LDFLAGS} ${NCURSES_LIBS}"

./autogen.sh

# configuring with `-C` and setting realloc/malloc checking makes configure
# wtih cache, which can avoid configuring to use rpl_malloc and rpl_realloc.
env ac_cv_func_realloc_0_nonnull=yes \
	ac_cv_func_malloc_0_nonnull=yes \
	CC="${CC}" CXX="${CXX}" LD="${LD}" AR=${AR} \
	STRIP=${STRIP} RANLIB=${RANLIB} NM=${NM} \
	CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" LDFLAGS="${LDFLAGS}" \
	./configure ${ConfigOpt}

make ${MAKE_FLAGS}
# vim:set noet:
