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.

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