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.

302 lines
5.2KB

  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2008 Jonathan Moore Liles
  4. # This file is licensed under version 2 of the GPL.
  5. . scripts/colors
  6. # support functions for 'configure' scripts.
  7. fatal ()
  8. {
  9. echo "$BOLD$RED$*$SGR0" > /dev/stderr
  10. exit 255
  11. }
  12. UPDATE=no
  13. HELP=no
  14. split ()
  15. {
  16. while [ $# -gt 0 ]
  17. do
  18. echo $1
  19. shift 1
  20. done
  21. }
  22. if [ $# -gt 0 ]
  23. then
  24. case "$1" in
  25. --update)
  26. UPDATE=yes
  27. shift 1
  28. ;;
  29. --help)
  30. HELP=yes
  31. shift 1
  32. ;;
  33. *)
  34. # fatal "This is not an autoconf script. Run it without any options and you will be prompted."
  35. ;;
  36. esac
  37. if [ $# -gt 0 ]
  38. then
  39. echo "## options" > make.conf
  40. split "$@" | sed '
  41. s/--\(enable\|disable\)-\([^ =]\+\)/--\1-\U\2/g;
  42. s/--enable-\([^ =]\+\)=\(.*\)/USE_\1=\2/g;
  43. s/--enable-\([^ =]\+\)/USE_\1=yes/g;
  44. s/--disable-\([^ =]\+\)/USE_\1=no/g;
  45. s/--\([^ =]\+\)/\1/g;
  46. ' | sed -n '/^[^ =]\+=./p' >> make.conf
  47. UPDATE=yes;
  48. fi
  49. fi
  50. ask ()
  51. {
  52. local A D
  53. D="`eval echo \\$$2`"
  54. D=${D:-$3}
  55. if [ $HELP = yes ]
  56. then
  57. echo -en "\t"
  58. if [ "$D" = yes ] || [ "$D" = no ]
  59. then
  60. if [ "$D" = yes ]
  61. then
  62. echo -n "$2" | sed s/^USE_/--enable-/ | tr '[[:upper:]]' '[[:lower:]]'
  63. else
  64. echo -n "$2" | sed s/^USE_/--disable-/ | tr '[[:upper:]]' '[[:lower:]]'
  65. fi
  66. else
  67. echo -n "--$2" | tr '[[:upper:]]' '[[:lower:]]'
  68. fi
  69. echo -e "\t$1"
  70. return
  71. fi
  72. echo -n "$BLACK$BOLD::$SGR0 ${1}? [$BOLD${D}$SGR0] "
  73. if [ $UPDATE = yes ]
  74. then
  75. A="$D"
  76. echo
  77. else
  78. read A
  79. A=${A:-$D}
  80. fi
  81. if [ "$3" = yes ] || [ "$3" = no ]
  82. then
  83. case "$A" in
  84. no | n | N) A=no ;;
  85. yes | y | Y) A=yes ;;
  86. * ) fatal "Invalid response. Must be 'yes' or 'no'" ;;
  87. esac
  88. fi
  89. append "${2}=${A:-$D}"
  90. }
  91. ok ()
  92. {
  93. echo "$BOLD${GREEN}ok${SGR0}"
  94. }
  95. failed ()
  96. {
  97. echo "$BOLD${RED}failed!${SGR0}" > /dev/stderr
  98. rm -f make.conf
  99. }
  100. using ()
  101. {
  102. [ "`eval echo \\$USE_$1`" = yes ]
  103. return $?
  104. }
  105. upcase ()
  106. {
  107. echo "$*" | tr '[[:lower:]]' '[[:upper:]]'
  108. }
  109. extract_options ()
  110. {
  111. local line name value
  112. if [ -f make.conf ]
  113. then
  114. {
  115. while read line
  116. do
  117. [ "$line" = "## options" ] && break
  118. done
  119. while read line
  120. do
  121. if [ "$line" = "## libs" ]
  122. then
  123. break
  124. else
  125. name=${line%=*}
  126. value=${line#*=}
  127. eval "$name='$value'"
  128. fi
  129. done
  130. } < make.conf
  131. fi
  132. }
  133. begin ()
  134. {
  135. echo -n "Checking sanity..."
  136. require_command pkg-config pkg-config > /dev/null
  137. ok
  138. }
  139. begin_options ()
  140. {
  141. # get the old values
  142. extract_options
  143. if [ $HELP = yes ]
  144. then
  145. echo "****"
  146. echo "This is not an autoconf script! Run without any arguments and you will be prompted."
  147. echo "Alternatively, you may use the following autoconf style arguments for"
  148. echo "non-interactive configuration."
  149. echo "****"
  150. echo
  151. echo " Available options:"
  152. echo
  153. else
  154. echo > make.conf
  155. append "# This file was automatically generated on `date`. Any changes may be lost!"
  156. append "## options"
  157. if [ $UPDATE = yes ]
  158. then
  159. echo "--- Updating configuration ---"
  160. else
  161. echo "--- Configuration required ---"
  162. fi
  163. fi
  164. }
  165. begin_tests ()
  166. {
  167. [ $HELP = yes ] && exit 0
  168. append "## libs"
  169. extract_options
  170. }
  171. append ()
  172. {
  173. echo "$1" >> make.conf
  174. }
  175. end ()
  176. {
  177. echo "--- Configuration complete ---"
  178. touch make.conf
  179. }
  180. require_command ()
  181. {
  182. echo -n "Checking for ${BOLD}$1${SGR0}..."
  183. if ! [ -x "`which $2`" ]
  184. then
  185. failed
  186. fatal "Command $1 not found."
  187. else
  188. ok
  189. fi
  190. }
  191. require_package ()
  192. {
  193. local name
  194. echo -n "Checking for $BOLD$1$SGR0..."
  195. if ! pkg-config --exists $3
  196. then
  197. failed
  198. fatal "Required package $1 doesn't appear to be installed."
  199. elif ! pkg-config --atleast-version $2 $3
  200. then
  201. failed
  202. fatal "The installed version of $1 (`pkg-config --mod-version $3`) is too old."
  203. fi
  204. name="`upcase \"$1\"`"
  205. append "${name}_LIBS=`pkg-config --libs $3`"
  206. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  207. ok
  208. return 0
  209. }
  210. _test_version ()
  211. {
  212. [ $1 $4 $5 ] && [ $2 $4 $6 ] && [ $3 $4 $7 ]
  213. }
  214. test_version ()
  215. {
  216. local IFS
  217. IFS='.'
  218. if [ $2 != -ge ] && [ $2 != -le ]
  219. then
  220. fatal "Syntax error"
  221. fi
  222. _test_version $1 $2 $3
  223. }
  224. version_of ()
  225. {
  226. echo `pkg-config --modversion $1`
  227. }
  228. require_FLTK ()
  229. {
  230. local use
  231. echo -n "Checking for ${BOLD}FLTK${SGR0}..."
  232. FLTK_VERSION=`fltk-config --version`
  233. if ! test_version $FLTK_VERSION -ge $1
  234. then
  235. failed
  236. fatal "The installed FLTK version ($FLTK_VERSION) is too old."
  237. else
  238. ok
  239. fi
  240. use=
  241. while [ $# -gt 1 ]
  242. do
  243. shift 1
  244. use="$use --use-$1"
  245. done
  246. append "FLTK_LIBS=`fltk-config $use --ldflags`"
  247. append "FLTK_CFLAGS=`fltk-config $use --cflags`"
  248. }