logo

badwolf

minimalist and privacy-oriented web browser based on WebKitGTK git clone https://hacktivis.me/git/badwolf.git
commit: 527f7f7c377c3ea035aba5b29dba977381f23e4f
parent a81cf070e8b2686ef35a857e80c89beb905d90e5
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 17 Jul 2023 08:45:53 +0200

Move from make(1) to ninja/samurai

Done so translated manpages could be handled and installed correctly.
ninja/make already being in the dependency tree of webkit-gtk.

meson wasn't picked as custom non-default targets are being used, for
example to manually re-generate icons but without build dependency on inkscape.

Diffstat:

M.builds/netbsd.yml7+++++--
M.builds/openbsd.yml7+++++--
M.gitignore9+++++++--
DMakefile124-------------------------------------------------------------------------------
MREADME.md10+++++-----
Abuild.ninja66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mconfigure167+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
7 files changed, 227 insertions(+), 163 deletions(-)

diff --git a/.builds/netbsd.yml b/.builds/netbsd.yml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2019-2022 Badwolf Authors <https://hacktivis.me/projects/badwolf> +# SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf> # SPDX-License-Identifier: BSD-3-Clause image: netbsd/latest @@ -7,13 +7,16 @@ packages: - webkit-gtk - clang - po4a + - ninja sources: - https://hacktivis.me/git/badwolf.git tasks: - clang: | cd badwolf CC=clang ./configure - DESTDIR=/tmp/clang-destdir make clean all test install + ninja clean all + ninja test + DESTDIR=/tmp/clang-destdir ninja install triggers: - action: email condition: failure diff --git a/.builds/openbsd.yml b/.builds/openbsd.yml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2019-2022 Badwolf Authors <https://hacktivis.me/projects/badwolf> +# SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf> # SPDX-License-Identifier: BSD-3-Clause image: openbsd/latest @@ -7,13 +7,16 @@ packages: - gettext-tools - clang-tools-extra - po4a + - ninja sources: - https://hacktivis.me/git/badwolf.git tasks: - clang: | cd badwolf CC=clang ./configure - DESTDIR=/tmp/clang-destdir scan-build make clean all test install + scan-build ninja clean all + ninja test + DESTDIR=/tmp/clang-destdir ninja install triggers: - action: email condition: failure diff --git a/.gitignore b/.gitignore @@ -1,8 +1,13 @@ -# SPDX-FileCopyrightText: 2019-2022 Badwolf Authors <https://hacktivis.me/projects/badwolf> +# SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf> # SPDX-License-Identifier: BSD-3-Clause /badwolf /locale -/config.mk +/config.ninja +/configure.h *.o *.mo + +.ninja_* + +/vgdump diff --git a/Makefile b/Makefile @@ -1,124 +0,0 @@ -# SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf> -# SPDX-License-Identifier: BSD-3-Clause - -# POSIX-ish Makefile with extensions common to *BSD and GNU such as: -# - Usage of backticks for shell evaluation -# - Usage of ?= for defining variables when not already defined -# - Usage of += for appending to a variable - -include config.mk - -SRCS = bookmarks.c userscripts.c fmt.c fmt_test.c uri.c uri_test.c keybindings.c downloads.c badwolf.c -OBJS = bookmarks.o userscripts.o fmt.o uri.o keybindings.o downloads.o badwolf.o -OBJS_test = fmt_test.o uri_test.o bookmarks_test.o -EXE = badwolf -EXE_test = fmt_test uri_test bookmarks_test -TRANS = fr.mo pt_BR.mo tr.mo de.mo vi.mo -TRANS_MAN = badwolf.fr.1 -DOCS = usr.bin.badwolf README.md KnowledgeBase.md interface.md - -GETTEXT_OPTS = --copyright-holder="Badwolf Authors <https://hacktivis.me/projects/badwolf>" --package-name="$(PACKAGE)" --package-version="$(VERSION_FULL)" --msgid-bugs-address="contact+badwolf-msgid@hacktivis.me" - -all: config.mk $(EXE) $(TRANS) po/messages.pot $(TRANS_MAN) po/manpage.pot - -config.mk: configure - @echo "Error: You need to execute ./configure before running make" - @exit 1 - -icons: $(ICON_SIZES) - -icons/hicolor/scalable/apps/badwolf.svg: badwolf.svg - mkdir -p icons/hicolor/scalable/apps - scour --no-line-breaks --enable-id-stripping --remove-metadata $< $@ - -icons/hicolor/%/apps/badwolf.png: icons/hicolor/scalable/apps/badwolf.svg - mkdir -p `dirname $@` - $(INKSCAPE) `echo $@ | cut -d/ -f3 | ./icons_size.sh` $< -o $@ - -po/messages.pot: $(SRCS) po/pot_license.ed - xgettext --keyword=_ --language=C --from-code=UTF-8 -o $@ --add-comments --sort-output --foreign-user --no-location --no-wrap $(GETTEXT_OPTS) $(SRCS) - $(ED) -s $@ <po/pot_license.ed - -po/manpage.pot: badwolf.1 po/pot_license.ed - po4a-gettextize --format man -M utf-8 --master badwolf.1 $(GETTEXT_OPTS) --po $@ - $(ED) -s $@ <po/pot_license.ed - -po/%_man.po: po/manpage.pot badwolf.1 - po4a-updatepo --format man -M utf-8 --master badwolf.1 --msgmerge-opt '--update' $(GETTEXT_OPTS) --po $@ - -po/%.po: po/messages.pot - msgmerge --update --backup=off $@ $< - -${TRANS}: po/${@:.mo=.po} - mkdir -p locale/${@:.mo=}/LC_MESSAGES - $(MSGFMT) -o locale/${@:.mo=}/LC_MESSAGES/$(PACKAGE).mo po/${@:.mo=.po} - -badwolf.fr.1: po/fr_man.po badwolf.1 - po4a-translate --format man -M utf-8 --master badwolf.1 --po po/fr_man.po --localized $@ - -badwolf: $(OBJS) - $(CC) -std=c11 -o $@ $(OBJS) $(LDFLAGS) $(LIBS) - -.c: - $(CC) -std=c11 $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $< - -.c.o: - $(CC) -std=c11 $(CFLAGS) -c -o $@ $< - -uri_test: uri.o uri_test.o - $(CC) -std=c11 -o $@ uri.o uri_test.o $(LDFLAGS) $(LIBS) - -fmt_test: fmt.o fmt_test.o - $(CC) -std=c11 -o $@ fmt.o fmt_test.o $(LDFLAGS) $(LIBS) - -bookmarks_test: bookmarks.o bookmarks_test.o - $(CC) -std=c11 -o $@ bookmarks.o bookmarks_test.o $(LDFLAGS) $(LIBS) - - -.PHONY: test -test: $(EXE_test) - $(DBG) ./uri_test - $(DBG) ./fmt_test - $(DBG) ./bookmarks_test - -.PHONY: lint -lint: - $(MANDOC) -Tlint -Wunsupp,error,warning ./badwolf.1 $(TRANS_MAN) - $(SHELLCHECK) ./configure - $(FLAWFINDER) . - $(REUSE) lint - -.PHONY: install -install: all - mkdir -p $(DESTDIR)$(BINDIR) - cp -p badwolf $(DESTDIR)$(BINDIR)/ - mkdir -p $(DESTDIR)$(MANDIR)/man1 - cp -p badwolf.1 $(DESTDIR)$(MANDIR)/man1/ - # TODO: use $TRANS_MAN - mkdir -p $(DESTDIR)$(MANDIR)/fr/man1 - cp -p badwolf.fr.1 $(DESTDIR)$(MANDIR)/fr/man1/badwolf.1 - mkdir -p $(DESTDIR)$(DATADIR)/locale - cp -r locale/ $(DESTDIR)$(DATADIR)/ - cp interface.css $(DESTDIR)$(DATADIR)/ - mkdir -p $(DESTDIR)$(APPSDIR) - cp -p badwolf.desktop $(DESTDIR)$(APPSDIR)/ - mkdir -p $(DESTDIR)$(DOCDIR) - cp -p $(DOCS) $(DESTDIR)$(DOCDIR)/ - mkdir -p $(DESTDIR)$(PREFIX)/share - cp -r icons $(DESTDIR)$(PREFIX)/share/ - @printf '\nNote: An example AppArmor profile has been installed at '$(DOCDIR)/usr.bin.badwolf'\n' - -.PHONY: clean -clean: - rm -fr locale $(OBJS) $(OBJS_test) $(EXE) $(EXE_test) - -.PHONY: distclean -distclean: clean - rm -fr config.mk - -.PHONY: AUTHORS -AUTHORS: .git - git log --use-mailmap --format='format:%aN <%aE>' --date='format:%Y' | sort | uniq > AUTHORS - -format: *.c *.h - clang-format -style=file -assume-filename=.clang-format -i *.c *.h diff --git a/README.md b/README.md @@ -29,8 +29,8 @@ Motivation from other clients <https://hacktivis.me/articles/www-client%20are%20 ### Translations You need to have gettext installed. If you want a GUI, poedit exists and Weblate is a good web platform that I might consider hosting at some point. -- Syncing POT file with the source code: ``make po/messages.pot`` -- Syncing PO file with the POT file: ``make po/de.po`` +- Syncing POT file with the source code: ``ninja po/messages.pot`` +- Syncing PO file with the POT file: ``ninja po/de.po`` - Initialising a new PO file (example for German, `de_DE`): ``msginit -l de_DE -i po/messages.pot -o po/de.po`` ## Contacts / Discussions @@ -53,7 +53,7 @@ You need to have gettext installed. If you want a GUI, poedit exists and Weblate ## Manual Installation ### Dependencies - POSIX-compatible Shell (i.e. mrsh, dash, lksh) -- POSIX-compatible make(1) (i.e. {Free,Net,Open}BSD make, GNU make) +- [ninja](https://ninja-build.org/) or [samurai](https://github.com/michaelforney/samurai) - A pkg-config implementation (pkgconf is recommended) - C11 Compiler (such as clang or gcc) - [WebKitGTK](https://webkitgtk.org/), only the latest stable(2.32.0+) is supported @@ -70,14 +70,14 @@ Note: Packagers can safely ignore the lint dependencies. ### Compiling ``` -./configure && make +./configure && ninja ``` Note: `configure` is a simple shell script (so not autotools) which supports variables like `PREFIX`. ### Installing ``` -make install +ninja install # DESTDIR is supported ``` diff --git a/build.ninja b/build.ninja @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf> +# SPDX-License-Identifier: BSD-3-Clause + +# Written by hand, config.ninja is the generated one + +rule po2mo + command = mkdir -p "$$(dirname $out)" && msgfmt -o $out $in + +rule translate_manpage + command = po4a-translate --format man -M utf-8 --master badwolf.1 --po $in --localized $out + +rule msgmerge + # touch: msgmerge doesn't always updates timestamps + command = msgmerge --update --backup=off $out $in && touch $out + +rule scour + command = mkdir -p "$$(dirname $out)" && scour --no-line-breaks --enable-id-stripping --remove-metadata $in $out + +rule gen_icon + command = mkdir -p "$$(dirname $out)" && inkscape -w $width -h $height $in -o $out + +rule run_tests + command = for test in $in; do ./$$test || exit 1; done + +rule install + command = sh -e ./install.sh + +include config.ninja + +build po/manpage.pot: xgettext_man badwolf.1 | po/pot_license.ed +build icons/hicolor/scalable/apps/badwolf.svg: scour badwolf.svg + +build uri_test: cc_exe uri_test.c uri.o +build fmt_test: cc_exe fmt_test.c fmt.o +build bookmarks_test: cc_exe bookmarks_test.c bookmarks.o +build test: run_tests uri_test fmt_test bookmarks_test + +rule list_authors + command = git log --use-mailmap --format='format:%aN <%aE>' --date='format:%Y' | sort | uniq >$out +build AUTHORS: list_authors | .git + +rule format + command = clang-format -style=file -assume-filename=.clang-format -i *.c *.h +build format: format + +rule mandoc + command = $MANDOC -Tlint -Wunsupp,error,warning ./badwolf.1 && $MANDOC -Tlint -Wunsupp,error ./badwolf.*.1 +build lint_mandoc: mandoc + +rule shellcheck + command = $SHELLCHECK ./configure +build lint_shellcheck: shellcheck | ./configure + +rule flawfinder + command = $FLAWFINDER . +build lint_flawfinder: flawfinder + +rule reuse + command = $REUSE lint +build lint_reuse: reuse + +rule true + command = true + +build lint: true | lint_mandoc lint_shellcheck lint_flawfinder lint_reuse +build all: phony badwolf diff --git a/configure b/configure @@ -1,16 +1,29 @@ #!/bin/sh - -# SPDX-FileCopyrightText: 2019-2022 Badwolf Authors <https://hacktivis.me/projects/badwolf> +# SPDX-FileCopyrightText: 2019-2023 Badwolf Authors <https://hacktivis.me/projects/badwolf> # SPDX-License-Identifier: BSD-3-Clause VERSION=1.2.0 VERSION_FULL=${VERSION}$(./version.sh) -ICON_SIZES="$(for i in 24 32 48 64 128 256; do printf 'icons/hicolor/%sx%s/apps/badwolf.png ' $i $i ; done)" DEPS="gtk+-3.0 libxml-2.0" +SRCS="bookmarks.c userscripts.c fmt.c fmt_test.c uri.c uri_test.c keybindings.c downloads.c badwolf.c" +OBJS="bookmarks.o userscripts.o fmt.o uri.o keybindings.o downloads.o badwolf.o" +OBJS_test="fmt_test.o uri_test.o bookmarks_test.o" +EXE=badwolf +EXE_test="fmt_test uri_test bookmarks_test" +DOCS="usr.bin.badwolf README.md KnowledgeBase.md interface.md" + +TRANS="fr pt_BR tr de vi" +TRANS_MAN="fr tr" + +lint_targets="" + min_webkitgtk=2.32.0 min_glib_guri=2.66.0 +arg0="$0" +args="$@" + usage() { cat <<END Usage: [variables] configure [variables] @@ -138,7 +151,7 @@ fi printf 'Checking %s command existance ...' "${MANDOC}" if command -v "${MANDOC}" >/dev/null ; is_ok then - : + lint_targets="${lint_targets} lint_mandoc" else echo 'Warning: manpage linting via mandoc(1) disabled' MANDOC="true" @@ -147,7 +160,7 @@ fi printf 'Checking %s command existance ...' "${SHELLCHECK}" if command -v "${SHELLCHECK}" >/dev/null ; is_ok then - : + lint_targets="${lint_targets} lint_shellcheck" else echo 'Warning: shell linting via shellcheck(1) disabled' SHELLCHECK="true" @@ -156,7 +169,7 @@ fi printf 'Checking %s command existance ...' "${FLAWFINDER}" if command -v "${FLAWFINDER}" >/dev/null ; is_ok then - : + lint_targets="${lint_targets} lint_flawfinder" else echo 'Warning: C analysis via flawfinder(1) disabled' SHELLCHECK="true" @@ -165,7 +178,7 @@ fi printf 'Checking %s command existance ...' "${REUSE}" if command -v "${REUSE}" >/dev/null ; is_ok then - : + lint_targets="${lint_targets} lint_reuse" else echo 'Warning: License linting via reuse(1) disabled' REUSE="true" @@ -251,38 +264,136 @@ get_libs() { "${PKGCONFIG}" --libs "${DEPS}"; } DEPS_libs="$(get_libs)" required -## Configuration write +echo -printf '\nWriting to config.mk ...' -cat >config.mk <<EOF -# Autogenerated by ./configure -PACKAGE = Badwolf -VERSION = ${VERSION} -VERSION_FULL = ${VERSION_FULL} +printf 'Writing to configure.h ...' +cat >configure.h <<EOF +#define DATADIR "${DATADIR}" +#define PACKAGE "Badwolf" +#define _XOPEN_SOURCE 700 +#define _POSIX_C_SOURCE 200809L +#define VERSION "${VERSION_FULL}" +EOF +is_ok -PREFIX = ${PREFIX} -BINDIR = ${BINDIR} -MANDIR = ${MANDIR} -DOCDIR = ${DOCDIR} -DATADIR = ${DATADIR} -APPSDIR = ${APPSDIR} +## Configuration write +printf 'Writing to config.ninja ...' +cat >config.ninja <<EOF +# Autogenerated by $arg0 $args +rule gen_config + command = $arg0 "$args" + generator = 1 +build config.ninja: gen_config configure + +PREFIX = ${PREFIX} PKGCONFIG = ${PKGCONFIG} +MSGFMT = ${MSGFMT} +INKSCAPE = ${INKSCAPE} CC = ${CC} +CFLAGS = ${CFLAGS} +LDFLAGS = ${LDFLAGS} ED = ${ED} -INKSCAPE = ${INKSCAPE} -MSGFMT = ${MSGFMT} -DBG = ${DBG} MANDOC = ${MANDOC} SHELLCHECK = ${SHELLCHECK} FLAWFINDER = ${FLAWFINDER} REUSE = ${REUSE} -CFLAGS = ${CFLAGS} -DDATADIR=\"\${DATADIR}\" -DPACKAGE=\"\${PACKAGE}\" -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"\${VERSION_FULL}\" ${DEPS_cflags} -LDFLAGS = ${LDFLAGS} -LIBS = ${DEPS_libs} -ICON_SIZES = ${ICON_SIZES} +DEPS_cflags = ${DEPS_cflags} +DEPS_libs = ${DEPS_libs} + +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" + +rule xgettext + 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 + +rule xgettext_man + command = po4a-gettextize --format man -M utf-8 --master \$in \$GETTEXT_OPTS --po \$out && ed -s \$out <po/pot_license.ed + +rule cc_exe + command = \$CC -std=c11 \$CFLAGS -include configure.h \$DEPS_cflags -o \$out \$in \$LDFLAGS \$DEPS_libs + +rule cc_obj + command = \$CC -std=c11 \$CFLAGS -include configure.h \$DEPS_cflags -c -o \$out \$in + +build po/messages.pot: xgettext ${SRCS} | po/pot_license.ed +build badwolf: cc_exe ${OBJS} + +EOF +all="badwolf" + +for obj in ${OBJS}; do + echo -n "build ${obj}: cc_obj ${obj//.o/.c} | " + grep '#include "' "${obj//.o/.c}" | sed -e 's;#include ";;' -e 's;";;' | tr '\n' ' ' + echo +done >>config.ninja + +for trans in ${TRANS}; do + echo "build po/${trans}.po: msgmerge po/messages.pot" + echo "build locale/${trans}/LC_MESSAGES/Badwolf.mo: po2mo po/${trans}.po" + all="${all} locale/${trans}/LC_MESSAGES/Badwolf.mo" +done >>config.ninja + +for man in ${TRANS_MAN}; do + echo "build po/${man}_man.po: xgettext_man badwolf.1" + echo "build badwolf.${man}.1: translate_manpage po/${man}_man.po" + all="${all} badwolf.${man}.1" +done >>config.ninja + +for i in 24 32 48 64 128 256; do + echo "build icons/hicolor/${i}x${i}/apps/badwolf.png: gen_icon icons/hicolor/scalable/apps/badwolf.svg + width = $i + height = $i" + # Not default, only there to ease regeneration of icons +done >>config.ninja + +cat >>config.ninja <<EOF +default ${all} + +rule clean + command = rm ${all} + +build install: install | ${all} +build clean: clean EOF + +is_ok + +printf 'Writing to ./install.sh ...' +cat >install.sh <<EOF +# Autogenerated by $arg0 $args + +# doins <DIR> <filename ...> +doins() { + dir="\${DESTDIR}/\$1"; shift + mkdir -p "\${dir}/" || exit 1 + + echo "\$@ → \${dir}/" + cp -pr "\$@" "\${dir}/" +} +# newins <DIR> <orig-filename> <dest-filename> +newins() { + dir="\${DESTDIR}/\$1"; shift + mkdir -p "\${dir}/" || exit 1 + + echo "\$2 → \${dir}/\$3" + cp -pr "\$2" "\${dir}/\$3" +} + +doins "${BINDIR}" ./badwolf +doins "${MANDIR}/man1" ./badwolf.1 +for man in ${TRANS_MAN}; do + newins "${MANDIR}/\${man}/man1" "./badwolf.\${man}.1" "badwolf.1" +done +doins "${DATADIR}" ./locale +doins "${DATADIR}" ./interface.css +doins "${APPSDIR}" badwolf.desktop +doins "${DOCDIR}" ${DOCS} +doins "${PREFIX}/share" icons + +printf "\nNote: An example AppArmor profile has been installed at '${DOCDIR}/usr.bin.badwolf'\n" +EOF + is_ok -echo 'Done, you can now run make' +echo 'Done, you can now run ninja or samu'