I've realised that what I'm trying to do is to define
the flag variables before ./configure is executed on
the same line which I've been told is the most recent
method.
Essentially, it's the same process as typing it on the
command line, but all the variables and commands
are held in variables.
On-the-fly or dynamic seems to be appropriate words
to describe what I'm trying to do.
Just to nail the lid shut on this one, I'd like
to use it through a function as below, but a
straight translation from the previous post
to one that uses eval in a function seems to
generate a 'command not found' error.
For future reference, this is an approximate
representation of the system so far. The method
suggested works and generates identical output
whilst processing.
I may have been overwhelmed with a working
system that I may have began to think a little
too far ahead with the possibilities when trying
to incorporate it into a function. However, I
still think it *might* be of some interest.
#!/bin/bash
declare -a FLAGS
FLAGS[0]="CFLAGS=\"-arch x86_64 -g -Os -pipe -no-cpp-precomp\""
FLAGS[1]="LDFLAGS=\"-arch x86_64 -bind_at_load\""
declare -a OPTION
OPTION[0]="./configure"
OPTION[1]="--bindir=/usr/local/bin"
OPTION[2]="--datarootdir=/usr/local/share"
OPTION[3]="--mandir=/usr/local/man"
declare -a CONFIG
declare do_flags=true
## check if array is not null
if [ -n "${FLAGS}" ]; then
## check if flags prefix ./configure
if $do_flags
then CONFIG=( "${FLAGS[@]}" )
fi
fi
## append options to array
CONFIG=( "${CONFIG[@]}" "${OPTION[@]}" )
## check contents of array
echo "${CONFIG[@]}"
## execute contents of array (disabled)
## eval "${CONFIG[@]}"
## check dynamic variables
eval "${FLAGS[@]}"
echo "CFLAGS=$CFLAGS"
echo "LDFLAGS=$LDFLAGS"