#
# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/scripts/config.in
# ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---
#
# Main config script
#
# Execution of sub-scripts:
#
# 	- architecture/*/preconfig.in
#
#	* Selecting Architecture
#	* architecture/$ROCKCFG_ARCH/config.in
#
#	- misc/*/preconfig.in
#	- target/*/preconfig.in
#	- package/*/*/preconfig.in
#
#	* Selecting Target
#	* target/$ROCKCFG_TARGET/config.in
#
#	* misc/*/noexpertconfig.in
#
#	* {package/*,misc}/*/config-*.in
#	* {package/*,misc}/*/config.in
#	* Various common build options
#
#	- package/*/*/postconfig.in
# 	- misc/*/postconfig.in
#	- architecture/$ROCKCFG_ARCH/postconfig.in
#	- target/$ROCKCFG_TARGET/postconfig.in
#
# Only procedures marked with '*' might interact with the user.
#
# Naming-scheme for extening config variables:
#
# Core:     ROCKCFG_*
# Archs:    ROCKCFG_ARCH_<Arch-Name>_*
# Targets:  ROCKCFG_TRG_<Target-Name>_*
# Packages: ROCKCFG_PKG_<Pkg-Name>_*
#
# Config-Internal Variables:
#
# Core:     CFGTEMP_*
# Archs:    CFGTEMP_ARCH_<Arch-Name>_*
# Targets:  CFGTEMP_TRG_<Target-Name>_*
# Packages: CFGTEMP_PKG_<Pkg-Name>_*
#
# Config Presets: ROCKCFGSET_*
#

CFGTEMP_ARCHLIST=""
CFGTEMP_TARGETLIST=""

%include architecture/*/preconfig.in

comment_id '- Architecture, CPU and Optimization' COMMENT_ARCHCPUOPT
block_begin 7
	choice ROCKCFG_ARCH $ROCKCFG_ARCH $CFGTEMP_ARCHLIST
	ROCKCFG_ID="$ROCKCFG_ID-$ROCKCFG_ARCH"

	if [ -f architecture/$ROCKCFG_ARCH/config.in ]
	then . architecture/$ROCKCFG_ARCH/config.in ; fi
	bool 'This is a cross-build between architectures' ROCKCFG_CROSSBUILD 0
	if [ "$ROCKCFG_CROSSBUILD" = 1 ] ; then
		pkgfilter sed -e 's,^\(. ..\)[^ ]*,\1--------,'
		ROCKCFG_ID="$ROCKCFG_ID-cross" ; ROCKCFGSET_USE_CROSSCC=1
	fi
block_end

%include misc/*/preconfig.in
%include target/*/preconfig.in
%include package/*/*/preconfig.in

comment ' '
comment_id '- Target Distribution' COMMENT_TARGET

block_begin 7
	choice ROCKCFG_TARGET generic $CFGTEMP_TARGETLIST
	ROCKCFG_ID="$ROCKCFG_ID-$ROCKCFG_TARGET"

	if [ -f target/$ROCKCFG_TARGET/config.in ]
	then . target/$ROCKCFG_TARGET/config.in ; fi
block_end

comment ' '
comment_id '- Build System Configuration' COMMENT_BUILD_SYS_CONF
block_begin 3
	bool 'Make a parallel (cluster) build' ROCKCFG_PARALLEL 0
	if [ "$ROCKCFG_PARALLEL" = 1 ] ; then
	    block_begin 10
		ROCKCFG_PARALLEL_MAX="`echo $ROCKCFG_PARALLEL_MAX |
							sed 's,[^0-9],,g'`"
		text 'Maximum size of job queue' ROCKCFG_PARALLEL_MAX 10
		text 'Command for adding jobs' ROCKCFG_PARALLEL_ADDJOB ''
	    block_end
	else
		bool 'Abort when a package-build fails' \
						ROCKCFG_ABORT_ON_ERROR 0
	fi

	bool 'Retry building broken packages' ROCKCFG_RETRY_BROKEN 0
	bool 'Disable packages which are marked as broken' \
						ROCKCFG_DISABLE_BROKEN 0
	bool 'Do not try building packages if deps failed' \
						ROCKCFG_NOBROKENDEPS 0
	bool 'Always clean up src dirs (even on pkg fail)' \
						ROCKCFG_ALWAYS_CLEAN 0
	bool 'Create debug information (xtrace) for builds' ROCKCFG_XTRACE 0

	bool 'Use TMPFS for building packages' ROCKCFG_SRC_TMPFS 0
	if [ "$ROCKCFG_SRC_TMPFS" = 1 ] ; then
	    block_begin
		comment '! WARNING: This feature can hang your system, if'
		comment '! you do not have enough virtual memory!'
		text 'TMPFS mount options' ROCKCFG_SRC_TMPFS_OPT \
		                           'size=800M,nr_inodes=100k'
		bool 'Write tmpfs log to var/adm/rock-debug/tmpfslog.txt' \
					ROCKCFG_SRC_TMPFS_LOG 0
	    block_end
	fi
block_end

%include misc/*/noexpertconfig.in

comment ' '
block_begin 3
	bool 'Show expert-only and experimental options' ROCKCFG_EXPERT 0
block_end

if [ $ROCKCFG_EXPERT = 1 ] ; then ROCKCFG_ID="$ROCKCFG_ID-expert"
else ROCKCFG_ID="$ROCKCFG_ID-noexpert" ; fi

expert_begin

    comment ' '
    comment '- Binary package format'
    block_begin 3
	bool 'Create *.tar.bz2 binary packages' ROCKCFG_CREATE_TARBZ2 0
	bool 'Create *.gem binary packages' ROCKCFG_CREATE_GEM 1
	bool 'Append version number to package files' ROCKCFG_PKGFILE_VER 1
    block_end

    comment ' '
    comment '- Additional Package Selection'
    block_begin 3
      choice ROCKCFG_PKGSEL_TPL none none 'No package preselection template' \
		$( cd misc/pkgsel; grep -H "^# TITLE: " *.in | tr ' ' '_' | sed 's,\.in:#_TITLE:_, ,' )
      if [ -f misc/pkgsel/${ROCKCFG_PKGSEL_TPL}.in ]; then
	. misc/pkgsel/${ROCKCFG_PKGSEL_TPL}.in
      fi
      bool 'Custom package selection' ROCKCFG_PKGSEL 0
      if [ "$ROCKCFG_PKGSEL" = 1 ] ; then
	menu_begin MENU_PKGSEL_RULES 'Edit package selection rules'
		# Active error checking: explicitly show an annoying popup
		filter=`printf "^[-xXoO][ \t]\+[a-zA-Z0-9_/*+.-]"`
		if grep -lvq "$filter" config/$config/pkgsel 2> /dev/null && \
			./src/rockdialog.bin --title "Build Config" --yesno \
			"Invalid line(s) in package rule set. Remove?" 5 50
		then
			grep "$filter" < config/$config/pkgsel \
				> config/$config/pkgsel.new
			mv config/$config/pkgsel.new config/$config/pkgsel
		fi
		unset filter

		editfile ROCKCFG_PKGSEL_FILE config/$config/pkgsel \
		         'Package selection rules'

		echo "# created from 'pkgsel'" > config/$config/pkgsel.awk
		while read action patternlist ; do
			case "$action" in
			    [xX])
				action='$1="X"' ;;
			    [oO])
				action='$1="O"' ;;
			    -)
				action='next'   ;;
			    *)
				echo '{ exit; }'
				continue ;;
			esac
			address="" ; first="(" ; others="&&"
			while read pattern ; do
				if [ -z "$address" ] && \
				   [ "$pattern" = "!" ] ; then
					address="! " ; others="||"
				else
					pattern="$( echo "$pattern" | sed \
						-e 's,[^a-zA-Z0-9_/\*+\.-],,g' \
						-e 's,[/\.\+],\\&,g' \
						-e 's,\*,[^ ]*,g' )"
					[ "$pattern" ] || continue
					address="$address$first"
					address="$address / $pattern /"
					first=" $others"
				fi
			done < <( echo "$patternlist" | tr '\t ' '\n\n' )
			echo "$address ) { $action; }"
		done < config/$config/pkgsel >> config/$config/pkgsel.awk
		echo '{ print; }' >> config/$config/pkgsel.awk

		pkgout
		gawk -f config/$config/pkgsel.awk < config/$config/packages \
				> config/$config/packages.new 2> /dev/null
		if [ -s config/$config/packages.new ] ; then
			mv config/$config/packages.new config/$config/packages
		else
			rm -f config/$config/packages.new
			comment '----    Syntax error(s) in rule set!'
		fi
		pkgin
	menu_end
      else
	rm -f config/$config/pkgsel
	rm -f config/$config/pkgsel.awk
      fi
      startprog ROCKCFG_SHOW_PKGLIST 'Show the current package list' \
              "./src/rockdialog.bin --title 'ROCK Linux Config - Package List' \
                        --backtitle 'ROCK Linux $rockver Configuration' \
                        --textbox config/$config/packages.txt \
                        $(( $lines - 4 )) $(( $columns - 5 ))"
    block_end

    comment ' '
%include $( ls {package/*,misc}/*/config{,-*}.in 2>/dev/null | sed 's,\(.*/\)\([^/]*\),\2 \1\2,' | sort | cut -f2 -d' ' )

    comment ' '
    comment '- Additional GNU Configure Options'
    block_begin 5
	editfile ROCKCFG_CONFOPT_FILE config/$config/confopt \
	                              'GNU Configure Options'
	if [ -f config/$config/confopt ] ; then
		const ROCKCFG_CONFIGURE_OPTS "`tr '\n' ' ' \
					< config/$config/confopt`"
	else
		const ROCKCFG_CONFIGURE_OPTS ""
	fi
	for option in $ROCKCFG_CONFIGURE_OPTS ; do
		if [ "${option#--with-}" = "$option" -a \
			"${option#--without-}" = "$option" ]
		then
			comment '----     Warning! The custom options may
break packages!'
			break
		fi
	done
    block_end

    comment ' '
    text 'Additional compiler flags' ROCKCFG_C_FLAGS ""

    comment ' '
    comment_id '- Flist detection technique' COMMENT_FLIST
    block_begin 5
	choice ROCKCFG_FLIST flwrapper \
		flwrapper 'Use the flist wrapper library for flist creation' \
		strace    'Use strace to get the file list'                  \
		find      'Use find on timestamp-file for flist creation'
    block_end

    comment ' '
    comment '- Various Options'
    block_begin 5
	bool 'Build and use a (pseudo-)cross compiler' ROCKCFG_USE_CROSSCC 1
	bool 'Make rebuild stage (stage 9)' ROCKCFG_DO_REBUILD_STAGE 1

	if [ $ROCKCFG_CROSSBUILD != 1 ]; then
		bool 'Run a check/test for packages with support' ROCKCFG_DO_CHECK 0
	fi

	if [ $ROCKCFG_USE_CROSSCC != 1 ]; then
		pkgfilter sed 's,^\([XO] \)0,\1-,'
	fi

	if [ $ROCKCFG_DO_REBUILD_STAGE != 1 ]; then
		pkgfilter sed 's,^\([XO] [0-8-]*\)9 ,\1- ,'
	fi

	choice ROCKCFG_OPT size \
		smart	'Smart optimisiation using a profile database'	\
		bizarre	'Inverse smart optimisation (this is bizarre)'	\
		speed	'Hard optimise for speed (often pretty slow)'	\
		size	'Hard optimise for size (recommended)'		\
		lazy	'Lazy optimisiation (for debugging binaries)'

	bool 'Create binaries with debug symbols' ROCKCFG_DEBUG 0
	bool 'Create statically linked binaries' ROCKCFG_STATIC 0

	bool 'Disable exceptions and rtti in C++' ROCKCFG_LIMITCXX 0
	bool 'Enable c-compiler multilib support' ROCKCFG_MULTILIB 0

	bool 'Disable National Language Support' ROCKCFG_DISABLE_NLS 0
	if [ "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
		pkgremove gettext
	fi

	bool 'Automatic documentation creation' ROCKCFG_CREATE_DOCS 1

	bool 'Create cache files after packages have been built' \
						ROCKCFG_CREATE_CACHE 1

	bool 'Run Paranoia Checks in Build-Target and Build-Pkg' \
						ROCKCFG_PARANOIA_CHECK 1

	bool 'Abbreviate ROCK Config ID with checksum' ROCKCFG_IDCKSUM 0
    block_end
expert_end

%include package/*/*/postconfig.in
%include misc/*/postconfig.in
%include architecture/*/postconfig.in
%include target/*/postconfig.in

pkgfilter sed '/^[XO] --* / d;'

[ $ROCKCFG_EXPERT = 1 ] ||
	ROCKCFG_ID="`echo $ROCKCFG_ID | sed 's,-noexpert.*,,'`"

[ "$ROCKCFG_IDCKSUM" = 1 ] &&
	ROCKCFG_ID="`echo $ROCKCFG_ID | cksum | cut -f1 -d' '`"  

const ROCKCFG_SHORTID "$ROCKCFG_ID"
ROCKCFG_ID="$config-$ROCKCFG_ID"