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.

298 lines
5.1KB

  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. ok
  132. }
  133. warn ()
  134. {
  135. echo "${BOLD}${YELLOW}* ${SGR0}$*"
  136. }
  137. begin_options ()
  138. {
  139. # get the old values
  140. extract_options
  141. if [ $HELP = yes ]
  142. then
  143. warn "This is not an autoconf script! Run without any arguments and you will be prompted."
  144. warn "Alternatively, you may use the following autoconf style arguments for"
  145. warn "non-interactive configuration."
  146. echo
  147. echo " Available options:"
  148. echo
  149. else
  150. echo > make.conf
  151. append "# This file was automatically generated on `date`. Any changes may be lost!"
  152. append "## options"
  153. if [ $UPDATE = yes ]
  154. then
  155. echo "--- Updating configuration ---"
  156. else
  157. echo "--- Configuration required ---"
  158. fi
  159. fi
  160. }
  161. begin_tests ()
  162. {
  163. [ $HELP = yes ] && exit 0
  164. append "## libs"
  165. extract_options
  166. }
  167. append ()
  168. {
  169. echo "$1" >> make.conf
  170. }
  171. end ()
  172. {
  173. echo "--- Configuration complete ---"
  174. touch make.conf
  175. }
  176. require_command ()
  177. {
  178. echo -n "Checking for ${BOLD}$1${SGR0}..."
  179. if ! [ -x "`which $2`" ]
  180. then
  181. failed
  182. fatal "Command $1 not found."
  183. else
  184. ok
  185. fi
  186. }
  187. require_package ()
  188. {
  189. local name
  190. echo -n "Checking for $BOLD$1$SGR0..."
  191. if ! pkg-config --exists $3
  192. then
  193. failed
  194. fatal "Required package $1 doesn't appear to be installed."
  195. elif ! pkg-config --atleast-version $2 $3
  196. then
  197. failed
  198. fatal "The installed version of $1 (`pkg-config --mod-version $3`) is too old."
  199. fi
  200. name="`upcase \"$1\"`"
  201. append "${name}_LIBS=`pkg-config --libs $3`"
  202. append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
  203. ok
  204. return 0
  205. }
  206. _test_version ()
  207. {
  208. [ $1 $4 $5 ] && [ $2 $4 $6 ] && [ $3 $4 $7 ]
  209. }
  210. test_version ()
  211. {
  212. local IFS
  213. IFS='.'
  214. if [ $2 != -ge ] && [ $2 != -le ]
  215. then
  216. fatal "Syntax error"
  217. fi
  218. _test_version $1 $2 $3
  219. }
  220. version_of ()
  221. {
  222. echo `pkg-config --modversion $1`
  223. }
  224. require_FLTK ()
  225. {
  226. local use
  227. echo -n "Checking for ${BOLD}FLTK${SGR0}..."
  228. FLTK_VERSION=`fltk-config --version`
  229. if ! test_version $FLTK_VERSION -ge $1
  230. then
  231. failed
  232. fatal "The installed FLTK version ($FLTK_VERSION) is too old."
  233. else
  234. ok
  235. fi
  236. use=
  237. while [ $# -gt 1 ]
  238. do
  239. shift 1
  240. use="$use --use-$1"
  241. done
  242. append "FLTK_LIBS=`fltk-config $use --ldflags`"
  243. append "FLTK_CFLAGS=`fltk-config $use --cflags`"
  244. }