From c5fca92a08a8a63ad4d746b4d3a44a9cf724ea61 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 7 Sep 2021 02:46:07 +0200 Subject: Change buildsystem to use a ./configure script This is done to support webkit2gtk-4.1 (libsoup3) vs. webkit2gtk-4.0 (libsoup2). It will also be useful once WebKitGTK with support for GTK4 lands in badwolf. --- .gitignore | 1 + Makefile | 39 +++++----------------- README.md | 4 +-- configure | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ version.sh | 13 +++++--- 5 files changed, 130 insertions(+), 37 deletions(-) create mode 100755 configure diff --git a/.gitignore b/.gitignore index fba98ae..b1e22a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /badwolf /locale +/config.mk *.o *.mo diff --git a/Makefile b/Makefile index 10bd767..b8d8e3e 100644 --- a/Makefile +++ b/Makefile @@ -3,29 +3,8 @@ # - Usage of ?= for defining variables when not already defined # - Usage of += for appending to a variable -PACKAGE = Badwolf -VERSION = 1.1.0 -VERSION_FULL = $(VERSION)`./version.sh` - -PREFIX ?= /usr/local -BINDIR ?= $(PREFIX)/bin -MANDIR ?= $(PREFIX)/share/man -DOCDIR ?= $(PREFIX)/share/doc/badwolf-$(VERSION) -DATADIR ?= $(PREFIX)/share/badwolf -APPSDIR ?= $(PREFIX)/share/applications - -CC ?= cc -CFLAGS ?= -g -O2 -pie -fPIE -CFLAGS += -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wconversion -Wsign-conversion -Werror=implicit-function-declaration -Werror=implicit-int -Werror=vla $(EXTRA_CFLAGS) -DBG ?= -PKGCONFIG ?= pkg-config -MSGFMT ?= msgfmt -INKSCAPE ?= inkscape - -# for i in 24 32 48 64 128 256; do echo icons/hicolor/${i}x${i}/apps/badwolf.png; done | tr '\n' ' ' -ICON_SIZES = icons/hicolor/24x24/apps/badwolf.png icons/hicolor/32x32/apps/badwolf.png icons/hicolor/48x48/apps/badwolf.png icons/hicolor/64x64/apps/badwolf.png icons/hicolor/128x128/apps/badwolf.png icons/hicolor/256x256/apps/badwolf.png - -DEPS = gtk+-3.0 webkit2gtk-4.0 libsoup-2.4 libxml-2.0 +include config.mk + SRCS = bookmarks.c uri.c uri_test.c keybindings.c downloads.c badwolf.c OBJS = bookmarks.o uri.o keybindings.o downloads.o badwolf.o OBJS_test = uri_test.o @@ -34,11 +13,11 @@ EXE_test = uri_test TRANS = fr.mo pt_BR.mo tr.mo de.mo DOCS = usr.bin.badwolf README.md KnowledgeBase.md interface.txt -CDEPS = -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION_FULL)\" -CDEPS += `$(PKGCONFIG) --cflags $(DEPS)` -LIBS = `$(PKGCONFIG) --libs $(DEPS)` +all: config.mk $(EXE) $(TRANS) po/messages.pot -all: $(EXE) $(TRANS) po/messages.pot +config.mk: configure + @echo "Error: You need to execute ./configure before running make" + @exit 1 icons: $(ICON_SIZES) @@ -64,10 +43,10 @@ badwolf: $(OBJS) $(CC) -std=c11 -o $@ $(OBJS) $(LDFLAGS) $(LIBS) .c: - $(CC) -std=c11 $(CFLAGS) $(CDEPS) $(LDFLAGS) $(LIBS) -o $@ $< + $(CC) -std=c11 $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@ $< .c.o: - $(CC) -std=c11 $(CFLAGS) $(CDEPS) -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) @@ -95,7 +74,7 @@ install: all .PHONY: clean clean: - rm -fr locale $(OBJS) $(OBJS_test) $(EXE) $(EXE_test) + rm -fr locale config.mk $(OBJS) $(OBJS_test) $(EXE) $(EXE_test) format: *.c *.h clang-format -style=file -assume-filename=.clang-format -i *.c *.h diff --git a/README.md b/README.md index d99da03..5f61b0a 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,13 @@ You need to have gettext installed. If you want a GUI, poedit exists and Weblate Dependencies are: - C11 Compiler (such as clang or gcc) -- [WebKitGTK](https://webkitgtk.org/), only the latest stable is supported +- [WebKitGTK](https://webkitgtk.org/), only the latest stable(2.32.0+) is supported - [libxml-2.0](http://www.xmlsoft.org/), no known version limitation - POSIX make with extension for shell in variables (works with GNU, {Net,Free,Open}BSD) - A pkg-config implementation (pkgconf is recommended) - (optionnal) gettext implementation (such as GNU Gettext) -Compilation is done with `make`, install with `make install` (`DESTDIR` and `PREFIX` environment variables are supported, amongs other common ones). An example AppArmor profile is provided at `usr.bin.badwolf`, please do some long runtime checks before shipping it or a modified version, help can be provided but with no support. +Compilation is done with `./configure && make`, install with `make install` (`DESTDIR` and `PREFIX` environment variables are supported, amongs other common ones). An example AppArmor profile is provided at `usr.bin.badwolf`, please do some long runtime checks before shipping it or a modified version, help can be provided but with no support. You'll also need inkscape (command line only) if you want to regenerate the icons, for example after modifying them or adding a new size. These aren't needed for normal installation as it is bundled. diff --git a/configure b/configure new file mode 100755 index 0000000..17510a0 --- /dev/null +++ b/configure @@ -0,0 +1,110 @@ +#!/bin/sh +VERSION=1.1.0 +VERSION_FULL=${VERSION}$(./version.sh) +PREFIX="${PREFIX:-/usr/local}" +BINDIR="${BINDIR:-${PREFIX}/bin}" +MANDIR="${MANDIR:-${PREFIX}/share/man}" +DOCDIR="${DOCDIR:-${PREFIX}/share/doc/badwolf-${VERSION}}" +DATADIR="${DATADIR:-${PREFIX}/share/badwolf}" +APPSDIR="${APPSDIR:-${PREFIX}/share/applications}" + +PKGCONFIG="${PKGCONFIG:-pkg-config}" +MSGFMT="${MSGFMT:-msgfmt}" +INKSCAPE="${INKSCAPE:-inkscape}" +CC="${CC:-cc}" +CFLAGS="${CFLAGS:--g -O2 -pie -fPIE} -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wconversion -Wsign-conversion -Werror=implicit-function-declaration -Werror=implicit-int -Werror=vla ${EXTRA_CFLAGS}" + +DEPS="gtk+-3.0 libxml-2.0" + +is_ok() { + status="$?" + + if test "$status" == 0; then + printf " OK\n" + else + printf " FAIL\n" + fi + + return $status +} + +required() { + is_ok || exit 1 +} + +pkg_config_check() { + printf 'Checking: %s %s ...' "${PKGCONFIG}" "$*" + "${PKGCONFIG}" "$@" + is_ok +} + +printf 'Checking %s command existance ...' "${PKGCONFIG}" +command -v "${PKGCONFIG}" >/dev/null ; required + +printf 'Checking %s command existance ...' "${CC}" +command -v "${CC}" >/dev/null ; required + +for dep in ${DEPS} +do + pkg_config_check --exists "$dep" || exit 1 +done + +case "${WITH_WEBKITGTK}n" in + 4.1n) + pkg_config_check --atleast-version=2.32.0 webkit2gtk-4.1 || exit 1 + DEPS="${DEPS} webkit2gtk-4.1 libsoup-3.0" + ;; + 4.0n) + pkg_config_check --atleast-version=2.32.0 webkit2gtk-4.0 || exit 1 + DEPS="${DEPS} webkit2gtk-4.0 libsoup-2.4" + ;; + n) + echo "warning: Packagers should specify the ABI version (4.0 or 4.1) in WITH_WEBKITGTK" >&2 + if pkg_config_check --atleast-version=2.32.0 webkit2gtk-4.1 + then + DEPS="${DEPS} webkit2gtk-4.1 libsoup-3.0" + else + pkg_config_check --atleast-version=2.32.0 webkit2gtk-4.0 || exit 1 + DEPS="${DEPS} webkit2gtk-4.0 libsoup-2.4" + fi + ;; + *) + echo "error: invalid webkit2gtk version in WITH_WEBKITGTK environment variable, must be 4.0 or 4.1" >&2 + exit 1 + ;; +esac + +get_cflags() { "${PKGCONFIG}" --cflags "${DEPS}"; } +DEPS_cflags="$(get_cflags)" +get_libs() { "${PKGCONFIG}" --libs "${DEPS}"; } +DEPS_libs="$(get_libs)" + +ICON_SIZES="$(for i in 24 32 48 64 128 256; do printf 'icons/hicolor/%sx%s/apps/badwolf.png ' $i $i ; done)" + +printf 'Writing to config.mk ...' +cat >config.mk </dev/null) -branch=$(git --git-dir="$(dirname $0)/.git" rev-parse --abbrev-ref HEAD | sed -r 's/.*[^0-9A-Za-z-]([0-9A-Za-z-]*)$/\1/g') - -if [ -n "$hash" ] || [ -n "$branch" ] +if command -v git 2>/dev/null >/dev/null then - printf '+g%s.%s' "$hash" "$branch" + hash=$(git --git-dir="$(dirname $0)/.git" rev-parse --short HEAD 2>/dev/null) + branch=$(git --git-dir="$(dirname $0)/.git" rev-parse --abbrev-ref HEAD 2>/dev/null | sed -r 's/.*[^0-9A-Za-z-]([0-9A-Za-z-]*)$/\1/g') + + if [ -n "$hash" ] || [ -n "$branch" ] + then + printf '+g%s.%s' "$hash" "$branch" + fi fi echo -- cgit v1.3.1-23-gd82d