summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile68
-rwxr-xr-xtools/install.sh48
3 files changed, 89 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index 312d2dc..f7d2ad7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
lariza
we_adblock.so
+*.d
diff --git a/Makefile b/Makefile
index f05e448..9c3e1bb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,53 +1,65 @@
-CFLAGS += -Wall -Wextra -Wno-unused-parameter -O3
+.POSIX:
+
+_CFLAGS = $(CFLAGS) -Wall -Wextra -Wno-unused-parameter -O3
__NAME__ = lariza
__NAME_UPPERCASE__ = LARIZA
-INSTALL = install
-INSTALL_PROGRAM = $(INSTALL)
-INSTALL_DATA = $(INSTALL) -m 644
-
-prefix = /usr/local
-exec_prefix = $(prefix)
-bindir = $(exec_prefix)/bin
-libdir = $(exec_prefix)/lib
-datarootdir = $(prefix)/share
-mandir = $(datarootdir)/man
-man1dir = $(mandir)/man1
-datadir = $(prefix)/share
+INSTALL = ./tools/install.sh
+INSTALL_PROGRAM = $(INSTALL) -Dm 755
+INSTALL_DATA = $(INSTALL) -Dm 644
+PREFIX = /usr/local
+EXEC_PREFIX = $(PREFIX)
+BINDIR = $(EXEC_PREFIX)/bin
+LIBDIR = $(EXEC_PREFIX)/lib
+DATAROOTDIR = $(PREFIX)/share
+MANDIR = $(DATAROOTDIR)/man
+MAN1DIR = $(MANDIR)/man1
+DATADIR = $(PREFIX)/share
-.PHONY: all clean install installdirs
all: $(__NAME__) we_adblock.so
+-include browser.c.d
+-include we_adblock.c.d
+
$(__NAME__): browser.c
- $(CC) $(CFLAGS) $(LDFLAGS) \
+ $(CC) $(_CFLAGS) $(LDFLAGS) \
-D__NAME__=\"$(__NAME__)\" \
-D__NAME_UPPERCASE__=\"$(__NAME_UPPERCASE__)\" \
- -o $@ $< \
+ -MD -MF browser.c.d \
+ -o $@ browser.c \
`pkg-config --cflags --libs gtk+-3.0 glib-2.0 webkit2gtk-4.0`
we_adblock.so: we_adblock.c
- $(CC) $(CFLAGS) $(LDFLAGS) \
+ $(CC) $(_CFLAGS) $(LDFLAGS) \
-D__NAME__=\"$(__NAME__)\" \
-D__NAME_UPPERCASE__=\"$(__NAME_UPPERCASE__)\" \
- -shared -o $@ -fPIC $< \
+ -MD -MF we_adblock.c.d \
+ -shared -o $@ -fPIC we_adblock.c \
`pkg-config --cflags --libs glib-2.0 webkit2gtk-4.0`
-install: all installdirs
- $(INSTALL_PROGRAM) $(__NAME__) $(DESTDIR)$(bindir)/$(__NAME__)
- $(INSTALL_DATA) man1/$(__NAME__).1 $(DESTDIR)$(man1dir)/$(__NAME__).1
+install: all
+ $(INSTALL_PROGRAM) $(__NAME__) $(DESTDIR)$(BINDIR)/$(__NAME__)
+ $(INSTALL_DATA) man1/$(__NAME__).1 $(DESTDIR)$(MAN1DIR)/$(__NAME__).1
$(INSTALL_DATA) man1/$(__NAME__).usage.1 \
- $(DESTDIR)$(man1dir)/$(__NAME__).usage.1
+ $(DESTDIR)$(MAN1DIR)/$(__NAME__).usage.1
$(INSTALL_PROGRAM) we_adblock.so \
- $(DESTDIR)$(libdir)/$(__NAME__)/web_extensions/we_adblock.so
+ $(DESTDIR)$(LIBDIR)/$(__NAME__)/web_extensions/we_adblock.so
$(INSTALL_DATA) user-scripts/hints.js \
- $(DESTDIR)$(datadir)/$(__NAME__)/user-scripts/hints.js
+ $(DESTDIR)$(DATADIR)/$(__NAME__)/user-scripts/hints.js
-installdirs:
- mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir) \
- $(DESTDIR)$(libdir)/$(__NAME__)/web_extensions \
- $(DESTDIR)$(datadir)/$(__NAME__)/user-scripts
+uninstall:
+ rm -f $(DESTDIR)$(BINDIR)/$(__NAME__) \
+ $(DESTDIR)$(MAN1DIR)/$(__NAME__).1 \
+ $(DESTDIR)$(MAN1DIR)/$(__NAME__).usage.1
+ rm -rf $(DESTDIR)$(LIBDIR)/$(__NAME__) \
+ $(DESTDIR)$(DATADIR)/$(__NAME__)
clean:
rm -f $(__NAME__) we_adblock.so
+
+allclean: clean
+ rm -f browser.c.d we_adblock.c.d
+
+.PHONY: all allclean clean install uninstall
diff --git a/tools/install.sh b/tools/install.sh
new file mode 100755
index 0000000..4641973
--- /dev/null
+++ b/tools/install.sh
@@ -0,0 +1,48 @@
+#!/bin/sh -e
+# Portable install version that supports -D -m and -t
+# We have our own extension flag -s for running sed on the given files while
+# installing.
+die() { printf '%s\n' "$@" >&2; exit 1;}
+usage() {
+ die "usage: ${0##*/} [-D] [-m mode] [-s sedscript] source dest" \
+ " or: ${0##*/} [-D] [-m mode] [-s sedscript] [-t dir] [source...]"
+}
+
+sed=''
+mkdirp=''
+target=''
+mode=0755
+
+while getopts 'Dm:s:t:h' opt; do
+ case $opt in
+ D) mkdirp=1 ;;
+ s) sed=$OPTARG ;;
+ t) target=$OPTARG ;;
+ m) mode=$OPTARG ;;
+ *) usage
+ esac
+done
+
+shift "$((OPTIND - 1))"
+
+if [ "$target" ]; then
+ [ "$mkdirp" ] || [ -d "$target" ] || die "$target doesn't exist"
+ mkdir -p "$target"
+ for arg; do
+ [ -d "$target/${arg##*/}" ] && die "$target/${arg##*/} is a directory"
+ if [ "$sed" ]; then
+ sed "$sed" < "$arg" > "$target/${arg##*/}"
+ else
+ cp "$arg" "$target"
+ fi
+
+ chmod "$mode" "$target/${arg##*/}"
+ done
+else
+ case "$2" in */*) [ "$mkdirp" ] || [ -d "${2%/*}" ] || die "${2%/*} doesn't exist"
+ mkdir -p "${2%/*}"
+ esac
+ [ -d "$2" ] && die "$2 is a directory"
+ if [ "$sed" ]; then sed "$sed" < "$1" > "$2"; else cp "$1" "$2"; fi
+ chmod "$mode" "$2"
+fi