Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
8.3KB

  1. #!/bin/sh
  2. # Copyright (C) 2008 Jonathan Moore Liles #
  3. # #
  4. # This program is free software; you can redistribute it and/or modify it #
  5. # under the terms of the GNU General Public License as published by the #
  6. # Free Software Foundation; either version 2 of the License, or (at your #
  7. # option) any later version. #
  8. # #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT #
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
  12. # more details. #
  13. # #
  14. # You should have received a copy of the GNU General Public License along #
  15. # with This program; see the file COPYING. If not,write to the Free Software #
  16. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
  17. #
  18. . scripts/colors
  19. #####
  20. ## support functions for 'configure' scripts.
  21. fatal ()
  22. {
  23. echo "$BOLD$RED$*$SGR0" > /dev/stderr
  24. exit 255
  25. }
  26. UPDATE=no
  27. HELP=no
  28. split ()
  29. {
  30. while [ $# -gt 0 ]
  31. do
  32. echo $1
  33. shift 1
  34. done
  35. }
  36. if [ $# -gt 0 ]
  37. then
  38. case "$1" in
  39. --update)
  40. UPDATE=yes
  41. shift 1
  42. ;;
  43. --help)
  44. HELP=yes
  45. shift 1
  46. ;;
  47. *)
  48. # fatal "This is not an autoconf script. Run it without any options and you will be prompted."
  49. ;;
  50. esac
  51. if [ $# -gt 0 ]
  52. then
  53. echo "## options" > .config
  54. split "$@" | sed '
  55. s/--\(enable\|disable\)-\([^ =]\+\)/--\1-\U\2/g;
  56. s/--enable-\([^ =]\+\)=\(.*\)/USE_\1=\2/g;
  57. s/--enable-\([^ =]\+\)/USE_\1=yes/g;
  58. s/--disable-\([^ =]\+\)/USE_\1=no/g;
  59. s/--\([^ =]\+\)/\1/g;
  60. ' | sed -n '/^[^ =]\+=./p' >> .config
  61. UPDATE=yes;
  62. fi
  63. fi
  64. if [ $HELP != yes ] && [ $UPDATE != yes ]
  65. then
  66. if ! ( [ -t 0 ] && [ -t 1 ] )
  67. then
  68. fatal "not a terminal!"
  69. fi
  70. fi
  71. ask ()
  72. {
  73. local A D O
  74. D="`eval echo \\$$2`"
  75. D=${D:-$3}
  76. if [ $HELP = yes ]
  77. then
  78. if [ "$3" = yes ] || [ "$3" = no ]
  79. then
  80. O=`echo -n "$2" | sed s/^USE_/--enable-/ | tr '[[:upper:]]' '[[:lower:]]'`
  81. else
  82. O=`echo -n "--$2" | tr '[[:upper:]]' '[[:lower:]]'`
  83. fi
  84. printf " ${BOLD}${GREEN}%-15s${SGR0}\t%-40s (currently: ${BOLD}%s${SGR0})\n" "$O" "$1" "$D"
  85. return
  86. fi
  87. echo -n "$BLACK$BOLD::$SGR0 ${1}? [$BOLD${D}$SGR0] "
  88. if [ $UPDATE = yes ]
  89. then
  90. A="$D"
  91. echo
  92. else
  93. read A
  94. A=${A:-$D}
  95. fi
  96. if [ "$3" = yes ] || [ "$3" = no ]
  97. then
  98. case "$A" in
  99. no | n | N) A=no ;;
  100. yes | y | Y) A=yes ;;
  101. * ) fatal "Invalid response. Must be 'yes' or 'no'" ;;
  102. esac
  103. fi
  104. append "${2}=${A:-$D}"
  105. eval "${2}='${A:-$D}'"
  106. }
  107. ok ()
  108. {
  109. echo ' '`tput cuf 30`"$BOLD${GREEN}ok${SGR0} ${*:+${BOLD}${BLACK}($*)${SGR0}}"
  110. }
  111. failed ()
  112. {
  113. echo ' '`tput cuf 30`"$BOLD${RED}failed!${SGR0}" > /dev/stderr
  114. rm -f .config
  115. }
  116. missing ()
  117. {
  118. echo ' '`tput cuf 30`"$BOLD${YELLOW}missing!${SGR0}" > /dev/stderr
  119. }
  120. using ()
  121. {
  122. [ "`eval echo \\$USE_$1`" = yes ]
  123. return $?
  124. }
  125. upcase ()
  126. {
  127. echo "$*" | tr '[[:lower:]]' '[[:upper:]]'
  128. }
  129. extract_options ()
  130. {
  131. local line name value
  132. if [ -f .config ]
  133. then
  134. {
  135. while read line
  136. do
  137. [ "$line" = "## options" ] && break
  138. done
  139. while read line
  140. do
  141. if [ "$line" = "## libs" ]
  142. then
  143. break
  144. else
  145. name=${line%=*}
  146. value=${line#*=}
  147. eval "$name='$value'"
  148. fi
  149. done
  150. } < .config
  151. fi
  152. }
  153. begin ()
  154. {
  155. echo -n "Checking sanity..."
  156. require_command tput tput > /dev/null
  157. require_command pkg-config pkg-config > /dev/null
  158. require_command fltk-config lib/fltk/fltk-config >/dev/null
  159. require_command sed sed > /dev/null
  160. ok
  161. }
  162. warn ()
  163. {
  164. echo " ${BOLD}${YELLOW}* ${SGR0}${BOLD}$*"
  165. }
  166. info ()
  167. {
  168. echo "${BOLD}${CYAN}--- ${SGR0}$*"
  169. }
  170. begin_options ()
  171. {
  172. # get the old values
  173. extract_options
  174. if [ $HELP = yes ]
  175. then
  176. echo
  177. warn "This is a ${BOLD}non-configure${SGR0} script. Run without any arguments and you will be prompted"
  178. warn "with configuration choices. Alternatively, you may use the following autoconf style"
  179. warn "arguments for non-interactive configuration."
  180. echo
  181. echo " Available options:"
  182. echo
  183. else
  184. echo > .config
  185. append "# This file was automatically generated on `date`. Any changes may be lost!"
  186. append "## options"
  187. if [ $UPDATE = yes ]
  188. then
  189. info "Updating configuration"
  190. else
  191. info "Configuration required"
  192. fi
  193. fi
  194. }
  195. begin_tests ()
  196. {
  197. if [ $HELP = yes ]
  198. then
  199. echo
  200. exit 0;
  201. fi
  202. append "## libs"
  203. extract_options
  204. }
  205. append ()
  206. {
  207. echo "$1" >> .config
  208. }
  209. end ()
  210. {
  211. info "Configuration complete"
  212. touch .config
  213. }
  214. require_command ()
  215. {
  216. echo -n "Checking for ${BOLD}$1${SGR0}..."
  217. local name;
  218. if [ -x "$2" ]
  219. then
  220. name="$PWD/$2"
  221. ok "$name"
  222. elif [ -x "`which "$2"`" ]
  223. then
  224. name="`which "$2"`"
  225. ok "$name"
  226. else
  227. failed
  228. fatal "Command $1 not found."
  229. fi
  230. append "$1=$name"
  231. }
  232. require_package ()
  233. {
  234. local name
  235. echo -n "Checking for $BOLD$1$SGR0..."
  236. if ! pkg-config --exists $3
  237. then
  238. failed
  239. fatal "Required package $1 doesn't appear to be installed."
  240. elif ! pkg-config --atleast-version $2 $3
  241. then
  242. failed
  243. fatal "The installed version of $1 (`pkg-config --mod-version $3`) is too old."
  244. fi
  245. name="`upcase \"$1\"`"
  246. append "${name}_LIBS=`pkg-config --libs $3 | sed 's/,\\?--as-needed//g'`"
  247. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  248. ok `pkg-config --modversion "$3"`
  249. return 0
  250. }
  251. suggest_package ()
  252. {
  253. local name
  254. echo -n "Checking for $BOLD$1$SGR0..."
  255. if ! pkg-config --exists $3
  256. then
  257. missing
  258. warn "Suggested package $1 doesn't appear to be installed. Some functionality may be missing from your build."
  259. warn "Continuing without $1...\n"
  260. return 1;
  261. elif ! pkg-config --atleast-version $2 $3
  262. then
  263. missing
  264. warn "The installed version of suggested package $1 (`pkg-config --mod-version $3`) is too old."
  265. warn "Continuing without $1..."
  266. return 1;
  267. fi
  268. name="`upcase \"$1\"`"
  269. append "${name}_LIBS=`pkg-config --libs $3 | sed 's/,\\?--as-needed//g'`"
  270. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  271. ok `pkg-config --modversion "$3"`
  272. return 0
  273. }
  274. _test_version ()
  275. {
  276. if [ $# = 6 ]
  277. then
  278. [ $1 -gt $4 ] && return 0
  279. [ $1 -eq $4 ] && [ $2 -gt $5 ] && return 0
  280. [ $1 -eq $4 ] && [ $2 -eq $5 ] && [ $3 -gt $6 ] && return 0
  281. [ $1 -eq $4 ] && [ $2 -eq $5 ] && [ $3 -eq $6 ] && return 0
  282. return 1
  283. elif [ $# = 4 ]
  284. then
  285. [ $1 -gt $3 ] && return 0
  286. [ $1 -eq $3 ] && [ $2 -eq $4 ] && return 0
  287. return 1
  288. fi
  289. }
  290. # return true if #1 is greater than or equal to $2
  291. test_version ()
  292. {
  293. local IFS
  294. IFS='.'
  295. _test_version $1 $2
  296. }
  297. version_of ()
  298. {
  299. echo `pkg-config --modversion $1`
  300. }
  301. hostname_resolvable ()
  302. {
  303. ping -c1 `hostname` >/dev/null 2>/dev/null
  304. }
  305. require_FLTK ()
  306. {
  307. local use
  308. echo -n "Checking for ${BOLD}FLTK${SGR0}..."
  309. FLTK_VERSION=`lib/fltk/fltk-config --version`
  310. if ! test_version $FLTK_VERSION $1
  311. then
  312. failed
  313. fatal "The installed FLTK version ($FLTK_VERSION) is too old."
  314. else
  315. ok $FLTK_VERSION
  316. fi
  317. use=
  318. while [ $# -gt 1 ]
  319. do
  320. shift 1
  321. use="$use --use-$1"
  322. done
  323. append "FLTK_LIBS=`lib/fltk/fltk-config $use --libs | sed 's/,\\?--as-needed//g'`"
  324. append "FLTK_LDFLAGS=`lib/fltk/fltk-config $use --ldflags | sed 's/,\\?--as-needed//g'`"
  325. append "FLTK_CFLAGS=`lib/fltk/fltk-config $use --cflags`"
  326. }