#!/usr/local/bin/onyx-5.1.2
# This file is automatically generated.
################################################################################
#
# Copyright (C) 1996-2005 Jason Evans <jasone@canonware.com>.
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice(s), this list of conditions and the following disclaimer
#    unmodified other than the allowable addition of one or more
#    copyright notices.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice(s), this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################
#
# Version: Onyx 5.1.2
#
# Script that provides the build flags to use with libonyx.
#
################################################################################

# Define usage string.
#
# - usage_string #string
$usage_string
`Usage: onyx_config [--help] [--version] [--features]
                   [--prefix] [--bindir] [--datadir] [--libdir]
                   [--includedir] [--mandir] [--onyx-path]
                   [--cppflags] [--cflags] [--ldflags] [--libs]
'
def

# Print usage to stderr.
#
# - usage -
$usage {
    stderr
    usage_string
    write pop
} def

# Print a string, after stripping off leading, trailing, and extra internal
# whitespace.
#
#string strip_print -
    $strip_print {
	`^\s*(\S.*\S)\s*$' `\1' <$s true> subst pop
	`\s+' ` ' <$s true> subst pop
	print
    } def


# Dictionary of procedures associated with command line flags.
$flags <
    `--help' {
	usage_string print flush
	0 die
    }
    `--prefix' {
	`/usr/local' strip_print
    }
    `--bindir' {
	`/usr/local/bin' strip_print
    }
    `--datadir' {
	`/usr/local/share' strip_print
    }
    `--libdir' {
	`/usr/local/lib' strip_print
    }
    `--includedir' {
	`/usr/local/include' strip_print
    }
    `--mandir' {
	`/usr/local/man' strip_print
    }
    `--onyx-path' {
	`/usr/local/bin/onyx-5.1.2' strip_print
    }
    `--version' {
	`Canonware Onyx, version 5.1.2.' strip_print
    }
    `--features' {
	mark # Use for counting number of feature strings on stack.
	    ` oop'
	    ` handle'
	    ` threads'
	    ` real'
	    ` regex'
	    ` posix'
	    ` posix_file'
	    ` socket'
	    ` modules'
	    ` inlines'
	counttomark dup 0 gt {
	    ncat strip_print
	} if
	pop # Remove mark.
    }
    `--cppflags' {
	` -D_REENTRANT -I/usr/local/include'
	`-I/usr/local/include ' exch cat
	strip_print
    }
    `--cflags' {
	`-O2 -pipe -fno-strict-aliasing' strip_print
    }
    `--ldflags' {
	` -L/usr/local/lib'
	`-Wl,-rpath,/usr/local/lib ' exch cat
	strip_print
    }
    `--libs' {
	`-lonyx  -pthread -lm -lpcre' strip_print
    }
> def

# Make sure at least one argument was specified.
argv length 2 lt {
    # No arguments specified.
    usage
    1 die
} if

# Iteratively process command line arguments.
argv dup length dec 1 exch getinterval
0 1 2 idup length dec {
    #args #index
    dup 0 gt {
	# Print a spacer between iterations.
	` ' print
    } if
    under get
    #args #arg
    flags over known {
	# Call procedure associated with flag.
	flags exch get eval
    }{
	# Unknown flag.
	usage
	1 die
    } ifelse
} for

# Finish up with a newline.
`
' print
