logo

httpc

barebones HTTP client, intended for simple usage like downloading filesgit clone https://hacktivis.me/git/httpc.git

configure (2168B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2019 Haelwenn (lanodan) Monnier <contact+httpc@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. DEPS="libtls"
  5. arg0="$0"
  6. args="$@"
  7. usage() {
  8. cat <<END
  9. Usage: [variables] configure [variables]
  10. Variables:
  11. PREFIX=DIR
  12. BINDIR=DIR
  13. MANDIR=DIR
  14. PKGCONFIG=BIN
  15. CC=BIN
  16. CFLAGS=OPTIONS
  17. LDFLAGS=OPTIONS
  18. Variables are set in the following order: Default, Environment, Arguments
  19. Dependencies: See README.md
  20. END
  21. }
  22. is_ok() {
  23. status="$?"
  24. if test $status -eq 0; then
  25. printf " OK\n"
  26. else
  27. printf " FAIL\n"
  28. fi
  29. return $status
  30. }
  31. required() {
  32. is_ok || exit 1
  33. }
  34. pkg_config_check() {
  35. printf 'Checking: %s %s ...' "${PKGCONFIG}" "$*"
  36. "${PKGCONFIG}" "$@"
  37. is_ok
  38. }
  39. ## User configuration
  40. # defaults
  41. : ${PREFIX:=/usr/local}
  42. : ${PKGCONFIG:=pkg-config}
  43. : ${CC:=cc}
  44. : ${CFLAGS:=-g -O2 -D_FORTIFY_SOURCE=2}
  45. # Also allow variables through arguments
  46. for i; do
  47. case "$i" in
  48. -h|--help)
  49. usage
  50. exit 1
  51. ;;
  52. -*)
  53. printf "Unknown argument ‘%s’\n" "${i}"
  54. usage
  55. exit 1
  56. ;;
  57. *=*)
  58. # shellcheck disable=SC2163
  59. export "$i"
  60. shift
  61. ;;
  62. *)
  63. printf "Unknown argument ‘%s’\n" "${i}"
  64. usage
  65. exit 1
  66. ;;
  67. esac
  68. done
  69. # Fallback definitions for dirs, based on $PREFIX
  70. : ${BINDIR:=${PREFIX}/bin}
  71. : ${MANDIR:=${PREFIX}/share/man}
  72. ## System checks
  73. # commands
  74. printf 'Checking %s command existance ...' "${PKGCONFIG}"
  75. command -v "${PKGCONFIG}" >/dev/null ; required
  76. printf 'Checking %s command existance ...' "${CC}"
  77. command -v "${CC}" >/dev/null ; required
  78. echo
  79. # pkg-config
  80. for dep in ${DEPS}
  81. do
  82. pkg_config_check --exists "$dep" || exit 1
  83. done
  84. printf 'Using pkg-config to get CFLAGS for %s ...' "${DEPS}"
  85. get_cflags() { "${PKGCONFIG}" --cflags "${DEPS}"; }
  86. DEPS_cflags="$(get_cflags)"
  87. required
  88. printf 'Using pkg-config to get LIBS for %s ...' "${DEPS}"
  89. get_libs() { "${PKGCONFIG}" --libs "${DEPS}"; }
  90. DEPS_libs="$(get_libs)"
  91. required
  92. echo
  93. ## Configuration write
  94. printf 'Writing to config.mk ...'
  95. cat >config.mk <<EOF
  96. # Autogenerated by $arg0 $args
  97. PREFIX = ${PREFIX}
  98. CC = ${CC}
  99. CFLAGS = ${CFLAGS}
  100. LDFLAGS = ${LDFLAGS}
  101. DEPS_cflags = ${DEPS_cflags}
  102. DEPS_libs = ${DEPS_libs}
  103. EOF
  104. is_ok
  105. echo 'Done, you can now run make'