Graphical package manager for pacman based on pamac 5.x.x
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.

configure 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #!/bin/sh
  2. # Autotools-style (./configure) wrapper for CMake
  3. # <https://github.com/nemequ/configure-cmake>
  4. #
  5. # *** IMPORTANT ***
  6. #
  7. # You must include the GNUInstallDirs module (which comes with
  8. # CMake) in your project. Just put "include (GNUInstallDirs)" in
  9. # you CMakeLists.txt and you should be good.
  10. #
  11. # This script was originally written for Squash
  12. # <https://quixdb.github.io/squash/> by Evan Nemerson
  13. # <evan@nemerson.com>, but has been spun off into a separate
  14. # repository. Please feel free to copy it into your own repository,
  15. # though I would appreciate it if you would post improvements, bugs,
  16. # feature requests, etc. to the issue tracker at
  17. # <https://github.com/nemequ/configure-cmake/issues>.
  18. #
  19. # To the extent possible under law, the author(s) hereby waive all
  20. # copyright and related or neighboring rights to this work. For
  21. # details, see <https://creativecommons.org/publicdomain/zero/1.0/>
  22. TOP_SRCDIR="$(dirname $0)"
  23. CMAKE_CMD="cmake ${TOP_SRCDIR}"
  24. BUILD_TYPE="Debug"
  25. PREFIX=/usr/local
  26. LIBDIR=
  27. CMAKE_ARGS=
  28. if [ -e "${TOP_SRCDIR}/.configure-custom.sh" ]; then
  29. . "${TOP_SRCDIR}/.configure-custom.sh"
  30. fi
  31. quote() {
  32. echo "$1" | sed -e "s|'|'\\\\''|g; 1s/^/'/; \$s/\$/'/"
  33. }
  34. extract_var_string() {
  35. VAR_NAME=$1
  36. VAR_NAME=$(echo $1 | sed -e 's/[ \t]*$//')
  37. if [ "x$2" != "x" ]; then
  38. VAR_VALUE=$2
  39. else
  40. VAR_VALUE=yes
  41. fi
  42. if [ "x$3" != "x" ]; then
  43. VAR_UC_NAME=$3
  44. else
  45. VAR_UC_NAME=$(echo "$1" | tr '[:lower:]' '[:upper:]' | tr -c '[:alnum:]' '_' | sed 's/_$//g')
  46. fi
  47. }
  48. set_config_var() {
  49. is_with=n
  50. case "$1" in
  51. "--enable-"*)
  52. name="${1#--enable-}"
  53. cfg="${ENABLE_VARS}"
  54. ;;
  55. "--disable-"*)
  56. name="${1#--disable-}";
  57. cfg="${DISABLE_VARS}";
  58. ;;
  59. "--with-"*)
  60. # IFS="=" read -ra WITHARGS <<< "${1}"
  61. name="${1#--with-}"
  62. cfg="${WITH_VARS}"
  63. is_with=y
  64. ;;
  65. esac
  66. found=n
  67. for varstring in $cfg; do
  68. extract_var_string $(echo "${varstring}" | tr '|' ' ')
  69. if [ "x$VAR_NAME" = "x$name" ]; then
  70. found=y
  71. break;
  72. fi
  73. done
  74. if [ "$found" = "y" ]; then
  75. if [ "x$is_with" = "xy" ]; then
  76. CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "$2")"
  77. else
  78. CMAKE_ARGS="$CMAKE_ARGS -D${VAR_UC_NAME}=$(quote "${VAR_VALUE}")"
  79. fi
  80. else
  81. echo "Unknown parameter: ${1}"
  82. exit 1
  83. fi
  84. }
  85. prefix_to_offset() {
  86. expr $(echo "${1}" | awk '{ print length }') + 1
  87. }
  88. print_help() {
  89. cat <<EOF >&2
  90. -h, --help display this help and exit
  91. --disable-debug disable debugging mode
  92. --pass-thru pass remaining arguments through to CMake
  93. --prefix=PREFIX install architecture-independent files in PREFIX
  94. [$PREFIX]
  95. --bindir=DIR user executables [PREFIX/bin]
  96. --sbindir=DIR system admin executables [PREFIX/sbin]
  97. --libexecdir=DIR program executables [PREFIX/libexec]
  98. --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
  99. --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
  100. --localstatedir=DIR modifiable single-machine data [PREFIX/var]
  101. --libdir=DIR object code libraries [PREFIX/lib]
  102. --includedir=DIR C header files [PREFIX/include]
  103. --oldincludedir=DIR C header files for non-gcc [/usr/include]
  104. --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
  105. --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
  106. --infodir=DIR info documentation [DATAROOTDIR/info]
  107. --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
  108. --mandir=DIR man documentation [DATAROOTDIR/man]
  109. --docdir=DIR documentation root [DATAROOTDIR/doc/PROJECT_NAME]
  110. EOF
  111. first=y
  112. for varstring in ${ENABLE_VARS}; do
  113. if [ $first = 'y' ]; then
  114. echo ""
  115. first=n
  116. fi
  117. extract_var_string $(echo "${varstring}" | tr '|' ' ')
  118. var_doc_name="ENABLE_${VAR_UC_NAME}_DOC"
  119. eval "docstring=\$$var_doc_name"
  120. if [ "x${docstring}" = "x" ]; then
  121. printf " --enable-%-14s enable %s support\n" "${VAR_NAME}" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
  122. else
  123. printf " --enable-%-14s %s\n" "${VAR_NAME}" "$docstring"
  124. fi
  125. done
  126. first=y
  127. for varstring in ${DISABLE_VARS}; do
  128. if [ $first = 'y' ]; then
  129. echo ""
  130. first=n
  131. fi
  132. extract_var_string $(echo "${varstring}" | tr '|' ' ')
  133. var_doc_name="DISABLE_${VAR_UC_NAME}_DOC"
  134. eval "docstring=\$$var_doc_name"
  135. if [ "x${docstring}" = "x" ]; then
  136. printf " --disable-%-13s disable %s support\n" "${VAR_NAME}" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
  137. else
  138. printf " --disable-%-13s %s\n" "${VAR_NAME}" "$docstring"
  139. fi
  140. done
  141. first=y
  142. for varstring in ${WITH_VARS}; do
  143. if [ $first = 'y' ]; then
  144. echo ""
  145. first=n
  146. fi
  147. extract_var_string $(echo "${varstring}" | tr '|' ' ')
  148. var_doc_name="WITH_${VAR_UC_NAME}_DOC"
  149. eval "docstring=\$$var_doc_name"
  150. paraminfo="${VAR_NAME}=${VAR_VALUE}"
  151. if [ "x${docstring}" = "x" ]; then
  152. printf " --with-%-16s enable %s support\n" "$paraminfo" "$(echo -n "${VAR_NAME}" | tr '-' ' ')"
  153. else
  154. printf " --with-%-16s %s\n" "$paraminfo" "$docstring"
  155. fi
  156. done
  157. exit 0
  158. }
  159. while [ $# != 0 ]; do
  160. case "$1" in
  161. "--prefix="*)
  162. PREFIX="${1#*=}";;
  163. "--prefix")
  164. PREFIX="${2}"; shift;;
  165. "--bindir="*)
  166. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_BINDIR=$(quote "${1#*=}")";;
  167. "--bindir")
  168. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_BINDIR=$(quote "$2")"; shift;;
  169. "--sbindir="*)
  170. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SBINDIR=$(quote "${1#*=}")";;
  171. "--sbindir")
  172. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SBINDIR=$(quote "$2")"; shift;;
  173. "--libexecdir="*)
  174. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LIBEXECDIR=$(quote "${1#*=}")";;
  175. "--libexecdir")
  176. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LIBEXECDIR=$(quote "$2")"; shift;;
  177. "--sysconfdir="*)
  178. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SYSCONFDIR=$(quote "${1#*=}")";;
  179. "--sysconfdir")
  180. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SYSCONFDIR=$(quote "$2")"; shift;;
  181. "--sharedstatedir="*)
  182. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SHAREDSTATEDIR=$(quote "${1#*=}")";;
  183. "--sharedstatedir")
  184. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_SHAREDSTATEDIR=$(quote "$2")"; shift;;
  185. "--localstatedir="*)
  186. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALSTATEDIR=$(quote "${1#*=}")";;
  187. "--localstatedir")
  188. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALSTATEDIR=$(quote "$2")"; shift;;
  189. "--libdir="*)
  190. LIBDIR="${1#*=}";;
  191. "--libdir")
  192. LIBDIR="${2}"; shift;;
  193. "--includedir="*)
  194. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INCLUDEDIR=$(quote "${1#*=}")";;
  195. "--includedir")
  196. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INCLUDEDIR=$(quote "$2")"; shift;;
  197. "--oldincludedir="*)
  198. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_OLDINCLUDEDIR=$(quote "${1#*=}")";;
  199. "--oldincludedir")
  200. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_OLDINCLUDEDIR=$(quote "$2")"; shift;;
  201. "--datarootdir="*)
  202. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATAROOTDIR=$(quote "${1#*=}")";;
  203. "--datarootdir")
  204. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATAROOTDIR=$(quote "$2")"; shift;;
  205. "--datadir="*)
  206. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATADIR=$(quote "${1#*=}")";;
  207. "--datadir")
  208. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DATADIR=$(quote "$2")"; shift;;
  209. "--infodir="*)
  210. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INFODIR=$(quote "${1#*=}")";;
  211. "--infodir")
  212. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_INFODIR=$(quote "$2")"; shift;;
  213. "--localedir="*)
  214. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALEDIR=$(quote "${1#*=}")";;
  215. "--localedir")
  216. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_LOCALEDIR=$(quote "$2")"; shift;;
  217. "--mandir="*)
  218. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_MANDIR=$(quote "${1#*=}")";;
  219. "--mandir")
  220. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_MANDIR=$(quote "$2")"; shift;;
  221. "--docdir="*)
  222. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "${1#*=}")";;
  223. "--docdir")
  224. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_DOCDIR=$(quote "$2")"; shift;;
  225. "CC="*)
  226. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$(quote "${1#*=}")";;
  227. "CXX="*)
  228. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_COMPILER=$(quote "${1#*=}")";;
  229. "CFLAGS="*)
  230. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_FLAGS=$(quote "${1#*=}")";;
  231. "CXXFLAGS="*)
  232. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_FLAGS=$(quote "${1#*=}")";;
  233. "LDFLAGS="*)
  234. LDFLAGS="$LDFLAGS ${1#*=}";;
  235. "--help")
  236. print_help;;
  237. "-h")
  238. print_help;;
  239. # This flag is the only one which may be a bit surprising to
  240. # people. Autotools always builds with debugging symbols enabled
  241. # (AFAIK), but for cmake you have to do -DCMAKE_BUILD_TYPE=Debug.
  242. # Unfortunately this can change other things as well, so although
  243. # I realize there is no --disable-debug flag I thought it would be
  244. # prudent to support one here.
  245. "--disable-debug")
  246. BUILD_TYPE="Release";;
  247. "--pass-thru")
  248. shift;
  249. while [ $# != 0 ]; do
  250. CMAKE_ARGS="$CMAKE_ARGS $(quote "${1}")";
  251. shift;
  252. done;;
  253. "--enable-"*)
  254. set_config_var "$1"
  255. ;;
  256. "--disable-"*)
  257. set_config_var "$1"
  258. ;;
  259. "--with-"*)
  260. name=$(echo "${1#--with-}" | awk '{split($1,v,"="); print v[1]}')
  261. case "${1}" in
  262. "--with-${name}="*)
  263. set_config_var "--with-${name}" "${1#--with-${name}=}";;
  264. "--with-${name}")
  265. set_config_var "$1" "$2";
  266. shift;;
  267. esac
  268. ;;
  269. *)
  270. echo "$0: error: unrecognized option: \`$1'" >&2
  271. echo "Try \`$0 --help' for more information" >&2
  272. exit -1
  273. esac;
  274. shift
  275. done
  276. if [ "x${LIBDIR}" = "x" ]; then
  277. LIBDIR="${PREFIX}/lib"
  278. fi
  279. # Unlike CFLAGS/CXXFLAGS/CC/CXX, LDFLAGS isn't handled by CMake, so we
  280. # need to parse it here.
  281. if [ "x${LDFLAGS}" != "x" ]; then
  282. for varname in EXE MODULE SHARED STATIC; do
  283. CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_${varname}_LINKER_FLAGS=$(quote "$LDFLAGS")"
  284. done
  285. fi
  286. eval "cmake ${TOP_SRCDIR} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_INSTALL_LIBDIR=${LIBDIR} ${CMAKE_ARGS}"