#!/bin/sh
#
# Script to configure and make CUPS with the standard build options.  When no
# targets are specified, the "clean" and "check" targets are used.
#
# Usage:
#
#   makecups [configure option(s)] [make target(s)]
#

# Scan the command-line arguments...
confopts=""
makeopts=""
archflags="-arch i386 -arch x86_64"
ldarchflags="-arch i386 -arch x86_64"
CC=/usr/bin/clang; export CC
CXX=/usr/bin/clang++; export CXX

while test $# -gt 0; do
	opt="$1"
	shift

	case "$opt" in
		--gcc)
			CC=/usr/bin/gcc
			CXX=/usr/bin/g++
			;;
		-l)
			archflags=""
			ldarchflags=""
			;;
		-*)
			confopts="$confopts $opt"
			;;
		*)
			makeopts="$makeopts $opt"
			;;
	esac
done
if test "x$makeopts" = x; then
	makeopts="clean check"
fi
makeopts="-j`sysctl -n hw.activecpu` $makeopts"

# Update the configure script...
echo cd cups
cd cups
echo autoconf -f
autoconf -f || exit 1

# Run the configure script...
echo ./configure ... $confopts
./configure --enable-debug --enable-debug-guards --enable-debug-printfs \
	--enable-unit-tests --enable-pie --with-pam-module=opendirectory \
	--with-archflags="$archflags" \
	--with-ldarchflags="$ldarchflags" \
	--with-adminkey="system.print.admin" \
	--with-operkey="system.print.operator" \
	$confopts || exit 1

# Build the software...
echo make $makeopts
make $makeopts
