grim/guifications3
Clone
Summary
Browse
Changes
Graph
the start of modularizing type traversal...
org.guifications.gf3
2009-09-16, Gary Kramlich
ec63325104e2
file is
Executable
the start of modularizing type traversal...
#!/bin/sh
# Guifications - The end-all, be-all notification framework
# Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###############################################################################
# Globals
###############################################################################
SEQ_COMMAND
=
"seq"
###############################################################################
# A list library similar to the lists in TCL
# Copyright (C) 2009 Ethan Blanton
###############################################################################
lappend
()
{
__list
=
$1
if
lempty
$__list
;
then
eval
"
$__list
=
$2
"
else
eval
"
$__list
=\"\$
$__list
\"
$2
\"\""
fi
}
lindex
()
{
eval
__list
=
\$
$1
cat
<<EOF | sed -e "$2!d"
$__list
EOF
}
lempty
()
{
eval
test
-z
\"\$
$1
\"
}
llength
()
{
eval
__list
=
\$
$1
cat
<<EOF | wc -l
$__list
EOF
}
lrange
()
{
catlist
$1
|
sed
-e
"
$2
,
$3
!d"
}
catlist
()
{
eval
__list
=
\$
$1
cat
<<EOF
$__list
EOF
}
echolist
()
{
__list
=
$1
catlist
$1
|
while
read
ITEM
;
do
echo
${
ITEM
}
done
}
lreplace
()
{
__listname
=
$1
__listindex
=
$2
__listvalue
=
$3
eval
"
$__listname
=\`catlist
$__listname
| sed -e '
${
__listindex
}
c\\\\
$__listvalue
'\`"
}
linsert
()
{
__listname
=
$1
__listindex
=
$2
__listvalue
=
$3
eval
"
$__listname
=\`catlist
$__listname
| sed -e '
${
__listindex
}
i\\\\
$__listvalue
'\`"
}
lsearch
()
{
catlist
$1
|
sed
-n
"/
$2
/{
=
q
}"
}
###############################################################################
# Some helper functions
###############################################################################
add_command
()
{
CMD
=
${
1
}
shift
# we need to make sure to entry something into the array for args even if
# it's empty. If it is, we set it to NONE, which we check for later
ARGS
=
"
${
@
}
"
lappend
COMMANDS
${
CMD
}
lappend
FLAGS
"\"
${
ARGS
}
\""
}
check_config_file
()
{
test
"
${
ARGS_FILE
}
"
||
ARGS_FILE
=
"autogen.args"
printf
"checking for argument file %s: "
${
ARGS_FILE
}
if
test
-f
${
ARGS_FILE
}
;
then
echo
"found."
printf
"sourcing %s ... "
${
ARGS_FILE
}
.
${
ARGS_FILE
}
echo
"done."
else
echo
"not found."
fi
}
check_command
()
{
CMD
=
$1
printf
"checking for
${
CMD
}
... "
BIN
=
`
which
${
CMD
}
`
if
[
x
"
${
BIN
}
"
=
x
""
]
;
then
echo
"not found."
echo
"
${
CMD
}
is required to build
${
PACKAGE
}
!"
exit
1
;
fi
echo
"
${
BIN
}
"
}
check_commands
()
{
catlist
COMMANDS
|
while
read
CMD
;
do
check_command
${
CMD
}
done
}
run_command
()
{
CMD
=
$1
shift
# we need to make sure to use a six-character template because some versions
# of mktemp blow up on anything shorter or longer.
OUTPUT
=
`
mktemp
autogen-XXXXXX
`
# we have to stash ${@} into a variable, otherwise printf has "issues" if
# ${@} was expanded from a variable. Fortunately, this lets us clean up
# the output a bit too.
ARGS
=
"
${
@
}
"
if
[
x
"
${
ARGS
}
"
!
=
x
""
]
;
then
ARGS
=
"
${
ARGS
}
"
fi
printf
"running '
${
CMD
}${
ARGS
}
' ... "
${
CMD
}
${
@
}
>
${
OUTPUT
}
2
>
&
1
if
[
$?
!
=
0
]
;
then
echo
"failed."
cat
${
OUTPUT
}
rm
-f
${
OUTPUT
}
exit
1
else
echo
"done."
cat
${
OUTPUT
}
rm
-f
${
OUTPUT
}
fi
}
run_commands
()
{
LEN
=
`
llength
COMMANDS
`
for
i
in
`
${
SEQ_COMMAND
}
1
${
LEN
}
`
;
do
CMD
=
`
lindex
COMMANDS
${
i
}
`
ARGS
=
`
lindex
FLAGS
${
i
}
`
run_command
${
CMD
}
${
ARGS
}
done
}
run_configure
()
{
echo
"running configure
${
@
}
..."
./configure
${
CONFIGURE_FLAGS
}
"
${
@
}
"
}
add_default_commands
()
{
add_command
"libtoolize"
" -c -f --automake"
add_command
"intltoolize"
" -c -f --automake"
add_command
"aclocal"
add_command
"autoheader"
add_command
"automake"
"-a -c -f --gnu"
add_command
"autoconf"
"-f"
}
add_default_library_commands
()
{
add_default_commands
INDEX
=
`
lsearch
COMMANDS
aclocal
`
linsert
COMMANDS
${
INDEX
}
"gtkdocize"
linsert
FLAGS
${
INDEX
}
"--copy"
}
find_command
()
{
echo
`
lsearch
COMMANDS
${
1
}
`
}
update_command
()
{
OLD_COMMAND
=
$1
NEW_COMMAND
=
$2
shift
2
ARGS
=
${
@
}
INDEX
=
`
find_command
${
OLD_COMMAND
}
`
test
${
INDEX
}
||
return
COMMANDS
[
${
INDEX
}
]=
${
NEW_COMMAND
}
test
${
ARGS
}
&&
FLAGS
[
${
INDEX
}
]=
${
ARGS
}
}
###############################################################################
# Platform specific stuff
###############################################################################
platform_bsd
()
{
SEQ_COMMAND
=
"jot -"
}
platform_osx
()
{
# run the bsd platform specific stuff too
platform_bsd
# change libtoolize to glibtoolize
update_command
"libtoolize"
"glibtoolize"
# look for fink and add it's aclocal dir to the aclocal flags
FLAGS
=
""
if
[
-d
/sw/share/aclocal
]
;
then
FLAGS
=
"-I /sw/share/aclocal"
fi
update_command
"aclocal"
"aclocal"
"
${
FLAGS
}
"
}
check_platform
()
{
PLATFORM
=
$(
uname
-s
)
printf
"adjusting for platform '%s' ... "
${
PLATFORM
}
case
${
PLATFORM
}
in
*BSD*
)
platform_bsd
;;
Darwin*
)
platform_osx
;;
esac
echo
"done."
}
###############################################################################
# API
###############################################################################
autogen
()
{
FIGLET
=
`
which
figlet
`
if
[
x
"
${
FIGLET
}
"
!
=
x
""
]
;
then
${
FIGLET
}
${
PACKAGE
}
echo
"build system is being generated"
else
echo
"autogenerating build system for '
${
PACKAGE
}
'"
fi
check_config_file
check_platform
check_commands
run_commands
run_configure
"
${
@
}
"
}