logo

badwolf

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

configure (11181B)


  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.2.0
  5. VERSION_FULL=${VERSION}$(./version.sh)
  6. DEPS="gtk+-3.0 libxml-2.0"
  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. PKGCONFIG=BIN
  31. MSGFMT=BIN
  32. INKSCAPE=BIN
  33. CC=BIN
  34. CFLAGS=OPTIONS
  35. 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. WITH_WEBKITGTK=(4.0|4.1)
  45. WITH_URI_PARSER=(guri|libsoup2)
  46. Variables are set in the following order: Default, Environment, Arguments
  47. Dependencies: See README.md
  48. END
  49. }
  50. is_ok() {
  51. status="$?"
  52. if test $status -eq 0; then
  53. printf " OK\n"
  54. else
  55. printf " FAIL\n"
  56. fi
  57. return $status
  58. }
  59. required() {
  60. is_ok || exit 1
  61. }
  62. pkg_config_check() {
  63. printf 'Checking: %s %s ...' "${PKGCONFIG}" "$*"
  64. "${PKGCONFIG}" "$@"
  65. is_ok
  66. }
  67. ## User configuration
  68. # defaults
  69. PREFIX="${PREFIX:-/usr/local}"
  70. PKGCONFIG="${PKGCONFIG:-pkg-config}"
  71. MSGFMT="${MSGFMT:-msgfmt}"
  72. INKSCAPE="${INKSCAPE:-inkscape}"
  73. CC="${CC:-cc}"
  74. CFLAGS="${CFLAGS:--g -O2 -D_FORTIFY_SOURCE=2}"
  75. ED="${ED:-ed}"
  76. XGETTEXT="${XGETTEXT:-xgettext}"
  77. MSGMERGE="${MSGMERGE:-msgmerge}"
  78. MANDOC="${MANDOC:-mandoc}"
  79. SHELLCHECK="${SHELLCHECK:-shellcheck}"
  80. FLAWFINDER="${FLAWFINDER:-flawfinder}"
  81. REUSE="${REUSE:-reuse}"
  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 ...' "${PKGCONFIG}"
  117. command -v "${PKGCONFIG}" >/dev/null ; required
  118. printf 'Checking %s command existence ...' "${CC}"
  119. command -v "${CC}" >/dev/null ; required
  120. printf 'Checking %s command existence ...' "${ED}"
  121. if command -v "${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. 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. printf 'Checking %s command existence ...' "${XGETTEXT}"
  137. if command -v "${XGETTEXT}" >/dev/null ; is_ok
  138. then
  139. :
  140. else
  141. echo 'Warning: translation updates disabled'
  142. XGETTEXT="true"
  143. fi
  144. printf 'Checking %s command existence ...' "${MSGMERGE}"
  145. if command -v "${MSGMERGE}" >/dev/null ; is_ok
  146. then
  147. :
  148. else
  149. echo 'Warning: translation updates disabled'
  150. MSGMERGE="true"
  151. fi
  152. printf 'Checking %s command existence ...' "${SHELLCHECK}"
  153. if command -v "${SHELLCHECK}" >/dev/null ; is_ok
  154. then
  155. lint_targets="${lint_targets} lint_shellcheck"
  156. else
  157. echo 'Warning: shell linting via shellcheck(1) disabled'
  158. SHELLCHECK="true"
  159. fi
  160. printf 'Checking %s command existence ...' "${FLAWFINDER}"
  161. if command -v "${FLAWFINDER}" >/dev/null ; is_ok
  162. then
  163. lint_targets="${lint_targets} lint_flawfinder"
  164. else
  165. echo 'Warning: C analysis via flawfinder(1) disabled'
  166. FLAWFINDER="true"
  167. fi
  168. printf 'Checking %s command existence ...' "${REUSE}"
  169. if command -v "${REUSE}" >/dev/null ; is_ok
  170. then
  171. lint_targets="${lint_targets} lint_reuse"
  172. else
  173. echo 'Warning: License linting via reuse(1) disabled'
  174. REUSE="true"
  175. fi
  176. echo
  177. # pkg-config
  178. for dep in ${DEPS}
  179. do
  180. pkg_config_check --exists "$dep" || exit 1
  181. done
  182. case "${WITH_WEBKITGTK}n" in
  183. 4.1n)
  184. pkg_config_check --atleast-version="${min_webkitgtk}" webkit2gtk-4.1 || exit 1
  185. DEPS="${DEPS} webkit2gtk-4.1"
  186. ;;
  187. 4.0n)
  188. pkg_config_check --atleast-version="${min_webkitgtk}" webkit2gtk-4.0 || exit 1
  189. DEPS="${DEPS} webkit2gtk-4.0"
  190. ;;
  191. n)
  192. echo "notice: Packagers should consider setting the ABI version (4.0 or 4.1) in WITH_WEBKITGTK" >&2
  193. if pkg_config_check --atleast-version="${min_webkitgtk}" webkit2gtk-4.1
  194. then
  195. DEPS="${DEPS} webkit2gtk-4.1"
  196. else
  197. pkg_config_check --atleast-version="${min_webkitgtk}" webkit2gtk-4.0 || exit 1
  198. DEPS="${DEPS} webkit2gtk-4.0"
  199. fi
  200. ;;
  201. *)
  202. echo "error: invalid webkit2gtk version in WITH_WEBKITGTK environment variable, must be 4.0 or 4.1" >&2
  203. exit 1
  204. ;;
  205. esac
  206. case "${WITH_URI_PARSER}n" in
  207. gurin)
  208. echo "URI parser selected: GUri from glib-2.0"
  209. pkg_config_check --atleast-version="${min_glib_guri}" glib-2.0 || exit 1
  210. DEPS="${DEPS} glib-2.0"
  211. ;;
  212. libsoup2n)
  213. echo "URI parser selected: libsoup-2.4"
  214. pkg_config_check libsoup-2.4 || exit 1
  215. DEPS="${DEPS} libsoup-2.4"
  216. CFLAGS="${CFLAGS} -DUSE_LIBSOUP2"
  217. if echo "${DEPS}" | grep -q 'webkit2gtk-4.1'
  218. then
  219. echo 'warning: libsoup2 selected while WebKitGTK with libsoup3 API is used' >&2
  220. fi
  221. ;;
  222. n)
  223. echo "notice: Packagers should consider setting the URI parsing library (guri or libsoup2) in WITH_URI_PARSER" >&2
  224. if echo "${DEPS}" | grep -q 'webkit2gtk-4.0'
  225. then
  226. pkg_config_check libsoup-2.4 || exit 1
  227. echo "URI parser selected: libsoup-2.4"
  228. DEPS="${DEPS} libsoup-2.4"
  229. CFLAGS="${CFLAGS} -DUSE_LIBSOUP2"
  230. else
  231. pkg_config_check --atleast-version="${min_glib_guri}" glib-2.0 || exit 1
  232. echo "URI parser selected: GUri from glib-2.0"
  233. DEPS="${DEPS} glib-2.0"
  234. fi
  235. ;;
  236. *)
  237. echo "error: invalid uri provider in WITH_URI_PARSER environment variable, must be guri or libsoup2" >&2
  238. ;;
  239. esac
  240. printf 'Using pkg-config to get CFLAGS for %s ...' "${DEPS}"
  241. get_cflags() { "${PKGCONFIG}" --cflags "${DEPS}"; }
  242. DEPS_cflags="$(get_cflags)"
  243. required
  244. printf 'Using pkg-config to get LIBS for %s ...' "${DEPS}"
  245. get_libs() { "${PKGCONFIG}" --libs "${DEPS}"; }
  246. DEPS_libs="$(get_libs)"
  247. required
  248. echo
  249. printf 'Writing to configure.h ...'
  250. cat >configure.h <<EOF
  251. #define DATADIR "${DATADIR}"
  252. #define PACKAGE "Badwolf"
  253. #define _XOPEN_SOURCE 700
  254. #define _POSIX_C_SOURCE 200809L
  255. #define VERSION "${VERSION_FULL}"
  256. EOF
  257. is_ok
  258. ## Configuration write
  259. printf 'Writing to config.ninja ...'
  260. cat >config.ninja <<EOF
  261. # Autogenerated by $arg0 $args
  262. rule gen_config
  263. command = $arg0 "$args"
  264. generator = 1
  265. build config.ninja: gen_config configure
  266. PREFIX = ${PREFIX}
  267. PKGCONFIG = ${PKGCONFIG}
  268. MSGFMT = ${MSGFMT}
  269. INKSCAPE = ${INKSCAPE}
  270. CC = ${CC}
  271. CFLAGS = ${CFLAGS}
  272. LDFLAGS = ${LDFLAGS}
  273. ED = ${ED}
  274. MANDOC = ${MANDOC}
  275. XGETTEXT = ${XGETTEXT}
  276. MSGMERGE = ${MSGMERGE}
  277. SHELLCHECK = ${SHELLCHECK}
  278. FLAWFINDER = ${FLAWFINDER}
  279. REUSE = ${REUSE}
  280. DEPS_cflags = ${DEPS_cflags}
  281. DEPS_libs = ${DEPS_libs}
  282. 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"
  283. rule xgettext
  284. command = \$XGETTEXT --keyword=_ --language=C --from-code=UTF-8 -o \$out --add-comments --sort-output --foreign-user --no-location --no-wrap \$GETTEXT_OPTS \$in && \$ED -s \$out <po/pot_license.ed
  285. rule msgmerge
  286. # touch: msgmerge doesn't always updates timestamps
  287. command = \$MSGMERGE --update --backup=off \$out \$in && touch \$out
  288. rule xgettext_man
  289. command = if test -e \$out; $
  290. then po4a-updatepo --format man -M utf-8 --master \$in \$GETTEXT_OPTS --po \$out && \$ED -s \$out <po/pot_license.ed;$
  291. else po4a-gettextize --format man -M utf-8 --master \$in \$GETTEXT_OPTS --po \$out && \$ED -s \$out <po/pot_license.ed;$
  292. fi
  293. rule cc_exe
  294. command = \$CC -std=c11 \$CFLAGS -include configure.h \$DEPS_cflags -o \$out \$in \$LDFLAGS \$DEPS_libs
  295. rule cc_obj
  296. command = \$CC -std=c11 \$CFLAGS -include configure.h \$DEPS_cflags -c -o \$out \$in
  297. build badwolf: cc_exe ${OBJS}
  298. EOF
  299. all="badwolf"
  300. for obj in ${OBJS}; do
  301. obj_c="$(echo "$obj" | sed -e 's;\.o;.c;g')"
  302. echo -n "build ${obj}: cc_obj ${obj_c} | "
  303. grep '#include "' "${obj_c}" | sed -e 's;#include ";;' -e 's;";;' | tr '\n' ' '
  304. echo
  305. done >>config.ninja
  306. if [ "$ED" != "false" ]; then
  307. echo "build po/messages.pot: xgettext ${SRCS} | po/pot_license.ed"
  308. echo 'build po/manpage.pot: xgettext_man badwolf.1 | po/pot_license.ed'
  309. fi >>config.ninja
  310. for trans in ${TRANS}; do
  311. echo "build po/${trans}.po: msgmerge po/messages.pot"
  312. echo "build locale/${trans}/LC_MESSAGES/Badwolf.mo: po2mo po/${trans}.po"
  313. all="${all} locale/${trans}/LC_MESSAGES/Badwolf.mo"
  314. done >>config.ninja
  315. for man in ${TRANS_MAN}; do
  316. echo "build po/${man}_man.po: xgettext_man badwolf.1"
  317. echo "build badwolf.${man}.1: translate_manpage po/${man}_man.po"
  318. bundled="${bundled} badwolf.${man}.1"
  319. trans_man="${trans_man} badwolf.${man}.1"
  320. done >>config.ninja
  321. for i in 24 32 48 64 128 256; do
  322. echo "build icons/hicolor/${i}x${i}/apps/badwolf.png: gen_icon icons/hicolor/scalable/apps/badwolf.svg
  323. width = $i
  324. height = $i"
  325. bundled="${bundled} icons/hicolor/${i}x${i}"
  326. icons_list="${icons_list} icons/hicolor/${i}x${i}/apps/badwolf.png"
  327. done >>config.ninja
  328. cat >>config.ninja <<EOF
  329. build icons: phony | ${icons_list}
  330. build trans_man: phony | ${trans_man}
  331. build bundled: phony | icons trans_man
  332. default ${all}
  333. rule remove
  334. command = rm -fr \${in} \${foo}
  335. build install: install | ${all}
  336. build clean: remove
  337. foo = ${all} ${OBJS} ${OBJS_test}
  338. build distclean: remove | clean
  339. foo = config.ninja configure.h install.sh
  340. build fullclean: remove | distclean
  341. foo = ${bundled}
  342. EOF
  343. is_ok
  344. printf 'Writing to ./install.sh ...'
  345. cat >install.sh <<EOF
  346. # Autogenerated by $arg0 $args
  347. # doins <DIR> <filename ...>
  348. doins() {
  349. dir="\${DESTDIR}/\$1"; shift
  350. mkdir -p "\${dir}/" || exit 1
  351. echo "\$@ → \${dir}/"
  352. cp -pr "\$@" "\${dir}/"
  353. }
  354. # newins <DIR> <orig-filename> <dest-filename>
  355. newins() {
  356. dir="\${DESTDIR}/\$1"
  357. mkdir -p "\${dir}/" || exit 1
  358. echo "\$2 → \${dir}/\$3"
  359. cp -pr "\$2" "\${dir}/\$3"
  360. }
  361. doins "${BINDIR}" ./badwolf
  362. doins "${MANDIR}/man1" ./badwolf.1
  363. for man in ${TRANS_MAN}; do
  364. newins "${MANDIR}/\${man}/man1" "./badwolf.\${man}.1" "badwolf.1"
  365. done
  366. doins "${DATADIR}" ./locale
  367. doins "${DATADIR}" ./interface.css
  368. doins "${APPSDIR}" badwolf.desktop
  369. doins "${DOCDIR}" ${DOCS}
  370. doins "${PREFIX}/share" icons
  371. printf "\nNote: An example AppArmor profile has been installed at '${DOCDIR}/usr.bin.badwolf'\n"
  372. EOF
  373. is_ok
  374. echo 'Done, you can now run ninja or samu'