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.

308 lines
5.3KB

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