logo

badwolf

minimalist and privacy-oriented web browser based on WebKitGTK git clone https://anongit.hacktivis.me/git/badwolf.git/

configure (9582B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf>
  3. # SPDX-License-Identifier: BSD-3-Clause
  4. VERSION=1.4.0
  5. VERSION_FULL=${VERSION}$(./version.sh)
  6. DEPS="gtk+-3.0 libxml-2.0 glib-2.0 webkit2gtk-4.1"
  7. SRCS="bookmarks.c userscripts.c fmt.c fmt_test.c uri.c uri_test.c keybindings.c downloads.c badwolf.c man_uri_scheme.c"
  8. OBJS="bookmarks.o userscripts.o fmt.o uri.o keybindings.o downloads.o badwolf.o man_uri_scheme.o"
  9. OBJS_test="fmt_test.o uri_test.o bookmarks_test.o"
  10. EXE=badwolf
  11. EXE_test="fmt_test uri_test bookmarks_test"
  12. DOCS="usr.bin.badwolf README.md KnowledgeBase.md interface.md"
  13. TRANS="fr pt_BR sr tr de vi"
  14. TRANS_MAN="de fr sr tr vi"
  15. lint_targets=""
  16. min_webkitgtk=2.32.0
  17. min_glib_guri=2.66.0
  18. arg0="$0"
  19. args="$@"
  20. usage() {
  21. cat <<END
  22. Usage: [variables] configure [variables]
  23. Variables:
  24. PREFIX=DIR
  25. BINDIR=DIR
  26. MANDIR=DIR
  27. DOCDIR=DIR
  28. DATADIR=DIR
  29. APPSDIR=DIR
  30. PKG_CONFIG=BIN
  31. MSGFMT=BIN
  32. INKSCAPE=BIN
  33. CC=BIN
  34. CFLAGS=OPTIONS
  35. CMD_ED=BIN
  36. LDFLAGS=OPTIONS
  37. EXTRA_CFLAGS=OPTIONS
  38. XGETTEXT=BIN
  39. MSGMERGE=BIN
  40. MANDOC=BIN
  41. SHELLCHECK=BIN
  42. FLAWFINDER=BIN
  43. REUSE=BIN
  44. ENABLE_NLS=0|1
  45. Variables are set in the following order: Default, Environment, Arguments
  46. Dependencies: See README.md
  47. END
  48. }
  49. is_ok() {
  50. status="$?"
  51. if test $status -eq 0; then
  52. printf " OK\n"
  53. else
  54. printf " FAIL\n"
  55. fi
  56. return $status
  57. }
  58. required() {
  59. is_ok || exit 1
  60. }
  61. pkg_config_check() {
  62. printf 'Checking: %s %s ...' "${PKG_CONFIG}" "$*"
  63. "${PKG_CONFIG}" "$@"
  64. is_ok
  65. }
  66. ## User configuration
  67. # defaults
  68. PREFIX="${PREFIX:-/usr/local}"
  69. PKG_CONFIG="${PKG_CONFIG:-${PKGCONFIG:-pkg-config}}"
  70. MSGFMT="${MSGFMT:-msgfmt}"
  71. INKSCAPE="${INKSCAPE:-inkscape}"
  72. CC="${CC:-cc}"
  73. CFLAGS="${CFLAGS:--g -O2 -D_FORTIFY_SOURCE=2}"
  74. CMD_ED="${CMD_ED:-ed}"
  75. XGETTEXT="${XGETTEXT:-xgettext}"
  76. MSGMERGE="${MSGMERGE:-msgmerge}"
  77. MANDOC="${MANDOC:-mandoc}"
  78. SHELLCHECK="${SHELLCHECK:-shellcheck}"
  79. FLAWFINDER="${FLAWFINDER:-flawfinder}"
  80. REUSE="${REUSE:-reuse}"
  81. ENABLE_NLS="${ENABLE_NLS:-1}"
  82. # Also allow variables through arguments
  83. for i; do
  84. case "$i" in
  85. -h|--help)
  86. usage
  87. exit 1
  88. ;;
  89. -*)
  90. printf "Unknown argument ‘%s’\n" "${i}"
  91. usage
  92. exit 1
  93. ;;
  94. *=*)
  95. # shellcheck disable=SC2163
  96. export "$i"
  97. shift
  98. ;;
  99. *)
  100. printf "Unknown argument ‘%s’\n" "${i}"
  101. usage
  102. exit 1
  103. ;;
  104. esac
  105. done
  106. # Fallback definitions for dirs, based on $PREFIX
  107. BINDIR="${BINDIR:-${PREFIX}/bin}"
  108. MANDIR="${MANDIR:-${PREFIX}/share/man}"
  109. DOCDIR="${DOCDIR:-${PREFIX}/share/doc/badwolf-${VERSION}}"
  110. DATADIR="${DATADIR:-${PREFIX}/share/badwolf}"
  111. APPSDIR="${APPSDIR:-${PREFIX}/share/applications}"
  112. # Add some extra CFLAGS
  113. CFLAGS="${CFLAGS} -Wall -Wextra -Wconversion -Wsign-conversion -Werror=implicit-function-declaration -Werror=implicit-int -Werror=vla ${EXTRA_CFLAGS}"
  114. ## System checks
  115. # commands
  116. printf 'Checking %s command existence ...' "${PKG_CONFIG}"
  117. command -v "${PKG_CONFIG}" >/dev/null ; required
  118. printf 'Checking %s command existence ...' "${CC}"
  119. command -v "${CC}" >/dev/null ; required
  120. printf 'Checking %s command existence ...' "${CMD_ED}"
  121. if command -v "${CMD_ED}" >/dev/null ; is_ok
  122. then
  123. :
  124. else
  125. echo 'Warning: Updating of *.pot translation files disabled, you may want to install ed(1)'
  126. CMD_ED="false"
  127. fi
  128. printf 'Checking %s command existence ...' "${MANDOC}"
  129. if command -v "${MANDOC}" >/dev/null ; is_ok
  130. then
  131. lint_targets="${lint_targets} lint_mandoc"
  132. else
  133. echo 'Warning: manpage linting via mandoc(1) disabled'
  134. MANDOC="true"
  135. fi
  136. if test 1 -eq $ENABLE_NLS; then
  137. printf 'Checking %s command existence ...' "${XGETTEXT}"
  138. if command -v "${XGETTEXT}" >/dev/null ; is_ok
  139. then
  140. :
  141. else
  142. echo 'Warning: translation updates disabled'
  143. XGETTEXT="true"
  144. fi
  145. printf 'Checking %s command existence ...' "${MSGMERGE}"
  146. if command -v "${MSGMERGE}" >/dev/null ; is_ok
  147. then
  148. :
  149. else
  150. echo 'Warning: translation updates disabled'
  151. MSGMERGE="true"
  152. fi
  153. else
  154. echo 'notice: translations disabled'
  155. TRANS=""
  156. TRANS_MAN=""
  157. XGETTEXT="true"
  158. MSGMERGE="true"
  159. fi
  160. printf 'Checking %s command existence ...' "${SHELLCHECK}"
  161. if command -v "${SHELLCHECK}" >/dev/null ; is_ok
  162. then
  163. lint_targets="${lint_targets} lint_shellcheck"
  164. else
  165. echo 'Warning: shell linting via shellcheck(1) disabled'
  166. SHELLCHECK="true"
  167. fi
  168. printf 'Checking %s command existence ...' "${FLAWFINDER}"
  169. if command -v "${FLAWFINDER}" >/dev/null ; is_ok
  170. then
  171. lint_targets="${lint_targets} lint_flawfinder"
  172. else
  173. echo 'Warning: C analysis via flawfinder(1) disabled'
  174. FLAWFINDER="true"
  175. fi
  176. printf 'Checking %s command existence ...' "${REUSE}"
  177. if command -v "${REUSE}" >/dev/null ; is_ok
  178. then
  179. lint_targets="${lint_targets} lint_reuse"
  180. else
  181. echo 'Warning: License linting via reuse(1) disabled'
  182. REUSE="true"
  183. fi
  184. echo
  185. # pkg-config
  186. for dep in ${DEPS}
  187. do
  188. pkg_config_check --exists "$dep" || exit 1
  189. done
  190. printf 'Using pkg-config to get CFLAGS for %s ...' "${DEPS}"
  191. get_cflags() { "${PKG_CONFIG}" --cflags "${DEPS}"; }
  192. DEPS_cflags="$(get_cflags)"
  193. required
  194. printf 'Using pkg-config to get LIBS for %s ...' "${DEPS}"
  195. get_libs() { "${PKG_CONFIG}" --libs "${DEPS}"; }
  196. DEPS_libs="$(get_libs)"
  197. required
  198. echo
  199. printf 'Writing to configure.h ...'
  200. cat >configure.h <<EOF
  201. #define DATADIR "${DATADIR}"
  202. #define PACKAGE "Badwolf"
  203. #define _XOPEN_SOURCE 700
  204. #define _POSIX_C_SOURCE 200809L
  205. #define VERSION "${VERSION_FULL}"
  206. EOF
  207. is_ok
  208. ## Configuration write
  209. printf 'Writing to config.ninja ...'
  210. cat >config.ninja <<EOF
  211. # Autogenerated by $arg0 $args
  212. rule gen_config
  213. command = $arg0 "$args"
  214. generator = 1
  215. build config.ninja: gen_config configure
  216. PREFIX = ${PREFIX}
  217. PKG_CONFIG = ${PKG_CONFIG}
  218. MSGFMT = ${MSGFMT}
  219. INKSCAPE = ${INKSCAPE}
  220. CC = ${CC}
  221. CFLAGS = ${CFLAGS}
  222. LDFLAGS = ${LDFLAGS}
  223. CMD_ED = ${CMD_ED}
  224. MANDOC = ${MANDOC}
  225. XGETTEXT = ${XGETTEXT}
  226. MSGMERGE = ${MSGMERGE}
  227. SHELLCHECK = ${SHELLCHECK}
  228. FLAWFINDER = ${FLAWFINDER}
  229. REUSE = ${REUSE}
  230. DEPS_cflags = ${DEPS_cflags}
  231. DEPS_libs = ${DEPS_libs}
  232. GETTEXT_OPTS = --copyright-holder="Badwolf Authors <https://hacktivis.me/projects/badwolf>" --package-name="Badwolf" --package-version="${VERSION_FULL}" --msgid-bugs-address="contact+badwolf-msgid@hacktivis.me"
  233. rule xgettext
  234. command = \$XGETTEXT --keyword=_ --language=C --from-code=UTF-8 -o \$out --add-comments --sort-output --foreign-user --no-location --no-wrap \$GETTEXT_OPTS \$in && \$CMD_ED -s \$out <po/pot_license.ed
  235. rule msgmerge
  236. # touch: msgmerge doesn't always updates timestamps
  237. command = \$MSGMERGE --update --backup=off \$out \$in && touch \$out
  238. rule xgettext_man
  239. command = if test -e \$out; $
  240. then po4a-updatepo --format man -M utf-8 --master \$in \$GETTEXT_OPTS --po \$out && \$CMD_ED -s \$out <po/pot_license.ed;$
  241. else po4a-gettextize --format man -M utf-8 --master \$in \$GETTEXT_OPTS --po \$out && \$CMD_ED -s \$out <po/pot_license.ed;$
  242. fi
  243. rule cc_exe
  244. command = \$CC -std=c11 \$CFLAGS -include configure.h \$DEPS_cflags -o \$out \$in \$LDFLAGS \$DEPS_libs
  245. rule cc_obj
  246. command = \$CC -std=c11 \$CFLAGS -include configure.h \$DEPS_cflags -c -o \$out \$in
  247. build badwolf: cc_exe ${OBJS}
  248. EOF
  249. all="badwolf"
  250. for obj in ${OBJS}; do
  251. obj_c="$(echo "$obj" | sed -e 's;\.o;.c;g')"
  252. echo -n "build ${obj}: cc_obj ${obj_c} | "
  253. grep '#include "' "${obj_c}" | sed -e 's;#include ";;' -e 's;";;' | tr '\n' ' '
  254. echo
  255. done >>config.ninja
  256. if [ "$CMD_ED" != "false" ]; then
  257. echo "build po/messages.pot: xgettext ${SRCS} | po/pot_license.ed"
  258. echo 'build po/manpage.pot: xgettext_man badwolf.1 | po/pot_license.ed'
  259. fi >>config.ninja
  260. for trans in ${TRANS}; do
  261. echo "build po/${trans}.po: msgmerge po/messages.pot"
  262. echo "build locale/${trans}/LC_MESSAGES/Badwolf.mo: po2mo po/${trans}.po"
  263. all="${all} locale/${trans}/LC_MESSAGES/Badwolf.mo"
  264. done >>config.ninja
  265. for man in ${TRANS_MAN}; do
  266. echo "build po/${man}_man.po: xgettext_man badwolf.1"
  267. echo "build badwolf.${man}.1: translate_manpage po/${man}_man.po"
  268. bundled="${bundled} badwolf.${man}.1"
  269. trans_man="${trans_man} badwolf.${man}.1"
  270. done >>config.ninja
  271. for i in 24 32 48 64 128 256; do
  272. echo "build icons/hicolor/${i}x${i}/apps/badwolf.png: gen_icon icons/hicolor/scalable/apps/badwolf.svg
  273. width = $i
  274. height = $i"
  275. bundled="${bundled} icons/hicolor/${i}x${i}"
  276. icons_list="${icons_list} icons/hicolor/${i}x${i}/apps/badwolf.png"
  277. done >>config.ninja
  278. cat >>config.ninja <<EOF
  279. build icons: phony | ${icons_list}
  280. build trans_man: phony | ${trans_man}
  281. build bundled: phony | icons trans_man
  282. default ${all}
  283. rule remove
  284. command = rm -fr \${in} \${foo}
  285. build install: install | ${all}
  286. build clean: remove
  287. foo = ${all} ${OBJS} ${OBJS_test}
  288. build distclean: remove | clean
  289. foo = config.ninja configure.h install.sh
  290. build fullclean: remove | distclean
  291. foo = ${bundled}
  292. EOF
  293. is_ok
  294. printf 'Writing to ./install.sh ...'
  295. cat >install.sh <<EOF
  296. # Autogenerated by $arg0 $args
  297. # doins <DIR> <filename ...>
  298. doins() {
  299. dir="\${DESTDIR}/\$1"; shift
  300. mkdir -p "\${dir}/" || exit 1
  301. echo "\$@ → \${dir}/"
  302. cp -pr "\$@" "\${dir}/"
  303. }
  304. # newins <DIR> <orig-filename> <dest-filename>
  305. newins() {
  306. dir="\${DESTDIR}/\$1"
  307. mkdir -p "\${dir}/" || exit 1
  308. echo "\$2 → \${dir}/\$3"
  309. cp -pr "\$2" "\${dir}/\$3"
  310. }
  311. doins "${BINDIR}" ./badwolf
  312. doins "${MANDIR}/man1" ./badwolf.1
  313. if test 1 -eq ${ENABLE_NLS}; then
  314. for man in ${TRANS_MAN}; do
  315. newins "${MANDIR}/\${man}/man1" "./badwolf.\${man}.1" "badwolf.1"
  316. done
  317. doins "${DATADIR}" ./locale
  318. fi
  319. doins "${DATADIR}" ./interface.css
  320. doins "${APPSDIR}" badwolf.desktop
  321. doins "${DOCDIR}" ${DOCS}
  322. doins "${PREFIX}/share" icons
  323. printf "\nNote: An example AppArmor profile has been installed at '${DOCDIR}/usr.bin.badwolf'\n"
  324. EOF
  325. is_ok
  326. echo 'Done, you can now run ninja or samu'