1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
#!/bin/bash
#
# autogen.sh - Tools for manipulating Jalali representation of Iranian calendar
# and necessary conversations to Gregorian calendar.
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Ashkan Ghassemi.
#
# This file is part of libjalali.
#
# libjalali is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# libjalali 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with libjalali. If not, see <http://www.gnu.org/licenses/>.
#
# @OPTIONS
OPTS="anch"
LONG_OPTS="nocolor,clean,help,alternative"
# @USAGE
function usage() {
echo -e "Jalali calendar library autogen build script."
echo -e "usage: autogen.sh [-nch]"
echo -e "try \`autogen.sh --help\' for more information."
}
# @HELP
function help() {
echo -e "usage: autogen.sh [-nch]..."
echo -ne "Invokes GNU build system tools in order to create"
echo -e " necessary configuration scripts.\n"
echo -e "Operation modes:"
echo -e " -a, --alternative\tdo not invoke autoreconf"
echo -e " -n, --nocolor\t\tdisable output colors"
echo -ne " -c, --clean\t\tremove all auto-generated scripts"
echo -e " and files from source tree"
echo -e " -h, --help\t\tprint this help, then exit\n"
echo -e "Report bugs to <ghassemi@ftml.net>."
echo -e "Jalali calendar home page: <http://nongnu.org/jcal>."
}
# echoes ``ok'' if parameter is zero, ''failed'' otherwise.
function printk() {
local STAT=$1
if [ $1 -eq 0 ]; then
echo -e "${GREEN}ok${RESET}"
else
echo -e "${RED}failed${RESET}"
fi
return ${STAT}
}
# performs make distclean and removes auto-generated files by GNU build system.
function clean() {
local STAT
# files
local FUBARS=( "autom4te.cache" "Makefile.in" "m4" "aclocal.m4"
"configure" "config.sub" "config.guess" "config.log"
"config.status" "depcomp" "install-sh" "libtool" "ltmain.sh"
"missing" "src/Makefile.in" "man/Makefile.in"
"test_kit/jalali/Makefile.in" "test_kit/jalali/Makefile"
"test_kit/Makefile.in" "test_kit/Makefile"
"test_kit/jalali/.deps" "test_kit/jtime/.deps"
"test_kit/jtime/Makefile.in" "test_kit/jalali/Makefile"
"libjalali/Makefile.in" "INSTALL" )
echo -e "${GREEN}*${RESET} ${YELLOW}cleaning source tree...${RESET}"
# Makefile is present.
if test -f Makefile; then
echo -ne "${GREEN}* ${RESET}${YELLOW}performing distclean on"
echo -ne " sources if possible...${RESET} "
make distclean >/dev/null 2>&1
let STAT=$?
printk ${STAT}
if [ ${STAT} -ne 0 ]; then
echo -ne "${RED}error${RESET}: cannot perform make distclean."
echo -e " run make distclean manually and check for erros."
fi
fi
for i in ${FUBARS[@]}; do
if [ -f $i ] || [ -d $i ]; then
echo -ne "${GREEN}*${RESET} ${YELLOW}deleting $i...${RESET} "
rm -rf $i
printk 0
fi
done
echo -e "${GREEN}* done${RESET}"
}
# Setting colors to vt100 standard values, NULL if 0 gets passed to set_color()
function set_colors() {
local HAS_COLOR=$1
if [ ${HAS_COLOR} -eq 1 ]; then
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
CYAN="\033[1;36m"
RESET="\033[0m"
else
RED=""
GREEN=""
YELLOW=""
CYAN=""
RESET=""
fi
}
# @is_present() $SERVICE $NAME $OUTPUT $EXIT
# Checks whether a service is present on system.
# $SERVICE is the path to service.
# $NAME is the service name.
# $OUTPUT specifies whether is_present() should work silently or not.
# $EXIT specifies whther is_present() should exit on the event of
# service not found.
function is_present() {
local SERVICE=$1
local NAME=$2
local OUTPUT=$3
local EXIT=$4
local PRESENT=0
if [ -n "${SERVICE}" ]; then
let PRESENT=1
fi
if [ ${OUTPUT} -eq 1 ]; then
echo -ne "${GREEN}*${RESET} checking for ${YELLOW}${NAME}${RESET}... "
if [ ${PRESENT} -eq 1 ]; then
echo -e "${GREEN}yes${RESET}"
else
echo -e "${RED}no${RESET}"
fi
fi
if [ ${PRESENT} -eq 0 ] && [ ${EXIT} -eq 1 ]; then
echo -ne "${RED}error${RESET}: ${YELLOW}${NAME}${RESET} was not found"
echo -e "on your system. autogen.sh cannot continue."
exit 1
fi
return ${PRESENT}
}
# Checking for tools
# aclocal, libtoolize, autoconf, automake and autoreconf
function check_services() {
local STAT
ACLOCAL="$(which aclocal 2>/dev/null)"
is_present "${ACLOCAL}" "aclocal" 1 1
# glibtoolize glue-patch
LIBTOOLIZE="$(which glibtoolize 2>/dev/null)"
STAT=$?
is_present "${LIBTOOLIZE}" "glibtoolize" 1 0
if [ ${STAT} -ne 0 ]; then
LIBTOOLIZE="$(which libtoolize 2>/dev/null)"
is_present "${LIBTOOLIZE}" "libtoolize" 1 1
fi
AUTOCONF="$(which autoconf 2>/dev/null)"
is_present "${AUTOCONF}" "autoconf" 1 1
AUTOMAKE="$(which automake 2>/dev/null)"
is_present "${AUTOMAKE}" "automake" 1 1
AUTORECONF="$(which autoreconf 2>/dev/null)"
is_present "${AUTORECONF}" "autoreconf" 1 0
echo -e "${GREEN}* done${RESET}\n"
}
# @perform() $SERVICE $NAME $EXIT $PARAMS
# runs a service with a set of parameters.
# $SERVICE is the path to the service.
# $NAME is the service name.
# $EXIT specifies whether perform() should exit on the event of
# encoutering any errors or not.
# $PARAMS are the parameters passed to the service.
function perform() {
local SERVICE=$1
local NAME=$2
local EXIT=$3
local PARAMS=$4
local SSTAT
echo -ne "${GREEN}*${RESET} running ${YELLOW}${NAME}${RESET} ${CYAN}${PARAMS}${RESET}... "
${SERVICE} ${PARAMS} >/dev/null 2>&1
let STAT=$?
printk ${STAT}
if [ ${STAT} -ne 0 ]; then
echo -ne "${RED}error${RESET}: cannot run ${YELLOW}${NAME}${RESET}."
echo -e " please run ${NAME} manually and check for errors."
fi
if [ ${EXIT} -eq 1 ] && [ ${STAT} -ne 0 ]; then
exit 1
fi
}
# Operation modes.
CLEAN=0
HELP=0
COLOR=1
ALTERN=0
which which 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "cannot find \`\`which''. autogen cannot continue."
exit 1
fi
# Parsing command-line arguments
GETOPT=`which getopt 2>/dev/null`
if [ -z ${GETOPT} ]; then
echo -ne "warning: getopt(1) was not found on your system."
echo -e " command line arguments will be ignored."
else
TEMP=`${GETOPT} -o ${OPTS} -l ${LONG_OPTS} -n 'autogen.sh' -- "$@"`
for i in $TEMP; do
case $i in
-c|--clean) let CLEAN=1;;
-n|--nocolor) let COLOR=0;;
-h|--help) let HELP=1;;
-a|--alternative) let ALTERN=1;;
esac
done
fi
# Setting colors.
set_colors ${COLOR}
# HELP
if [ ${HELP} -eq 1 ]; then
help
exit 0
fi
# CLEAN
if [ ${CLEAN} -eq 1 ]; then
clean
exit 0
fi
# Checking for services.
check_services
# alternative method.
if [ -z "${AUTORECONF}" ] || [ ${ALTERN} -eq 1 ]; then
echo -e "using alternative method: ${YELLO}manual${RESET}"
perform "${LIBTOOLIZE}" "libtoolize" "1" "--force --copy --install"
perform "${ACLOCAL}" "aclocal" "1" "--force"
perform "${AUTOMAKE}" "automake" "1" "--add-missing --force-missing --copy"
perform "${AUTOCONF}" "autoconf" "1" "--force"
echo -e "${GREEN}* done${RESET}"
# autoreconf method
else
echo -e "using prefered method: ${YELLOW}autoreconf${RESET}"
perform "${LIBTOOLIZE}" "libtoolize" "1" "--force --copy --install"
perform "${AUTORECONF}" "autoreconf" "1" "--force --install"
echo -e "${GREEN}* done${RESET}"
fi
exit 0
|