Commit d248d42c authored by Julius Plenz's avatar Julius Plenz

Merge branch 'makefile-improvement'

* makefile-improvement: Adjust README for Makefile update. GNU Make best practice (Closes issue #14.)
parents 609e03d4 87ee1d32
default: all
all: cachestats cachedel nocache.so
.PHONY: test
#!/usr/bin/make -f
# -*- makefile -*-
GCC = gcc $(CFLAGS)
%.c: Makefile
cachestats: cachestats.c
$(GCC) -Wall -o cachestats cachestats.c
cachedel: cachedel.c
$(GCC) -Wall -o cachedel cachedel.c
nocache.o: nocache.c
$(GCC) -Wall -fPIC -c -o nocache.o nocache.c
fcntl_helpers.o: fcntl_helpers.c
$(GCC) -Wall -fPIC -c -o fcntl_helpers.o fcntl_helpers.c
nocache.so: nocache.o fcntl_helpers.o
$(GCC) -Wall -pthread -shared -Wl,-soname,nocache.so -o nocache.so nocache.o fcntl_helpers.o -ldl
install: all
install -m 0644 nocache.so /usr/local/lib
install -m 0755 nocache.global /usr/local/bin/nocache
test:
cd t; prove -v .
PREFIX ?= /usr/local
MANDIR ?= /share/man/man1
BINDIR ?= /bin
LIBDIR ?= /lib
mandir = $(DESTDIR)$(PREFIX)$(MANDIR)
bindir = $(DESTDIR)$(PREFIX)$(BINDIR)
libdir = $(DESTDIR)$(PREFIX)$(LIBDIR)
CACHE_BINS=cachedel cachestats
NOCACHE_BINS=nocache.o fcntl_helpers.o
MANPAGES=$(wildcard man/*.1)
CFLAGS+= -Wall
GCC = gcc $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
.PHONY: all
all: $(CACHE_BINS) nocache.so nocache
$(CACHE_BINS):
$(GCC) -o $@ $@.c
$(NOCACHE_BINS):
$(GCC) -fPIC -c -o $@ $(@:.o=.c)
nocache.global:
sed 's!##libdir##!$(subst $(DESTDIR),,$(libdir))!' <nocache.in >$@
clean:
rm -f cachestats cachedel fcntl_helpers.o nocache.o nocache.so
nocache:
sed 's!##libdir##!$$(dirname "$$0")!' <nocache.in >$@
chmod a+x $@
nocache.so: $(NOCACHE_BINS)
$(GCC) -pthread -shared -Wl,-soname,nocache.so -o nocache.so $(NOCACHE_BINS) -ldl
$(mandir) $(libdir) $(bindir):
mkdir -v -p $@
install: all $(mandir) $(libdir) $(bindir) nocache.global
install -m 0644 nocache.so $(libdir)
install -m 0755 nocache.global $(bindir)/nocache
install -m 0755 $(CACHE_BINS) $(bindir)
install -m 0644 $(MANPAGES) $(mandir)
.PHONY: uninstall
uninstall:
cd $(mandir) && $(RM) -v $(notdir $(MANPAGES))
$(RM) -v $(bindir)/nocache $(libdir)/nocache.so
.PHONY: clean distclean
clean distclean:
$(RM) -v $(CACHE_BINS) $(NOCACHE_BINS) nocache.so nocache nocache.global
.PHONY: test
test: all
cd t; prove -v .
......@@ -14,16 +14,17 @@ Use case: backup processes that should not interfere with the present
state of the cache.
Install and Use
---------------
Installation and Usage
----------------------
Just type `make`. Then, prepend `./nocache` to your command:
./nocache cp -a ~/ /mnt/backup/home-$(hostname)
You can also put the `nocache.so` file to a location like
`/usr/local/lib` and do `LD_PRELOAD=/usr/local/lib/nocache.so`.
(This is what the `install` target will do.)
The command `make install` will install the shared library, man
pages and the `nocache`, `cachestats` and `cachedel` commands
under `/usr/local`. You can specify an alternate prefix by using
`make install PREFIX=/usr`.
Debian unstable packages are available at http://packages.debian.org/sid/nocache.
Please note that `nocache` will only build on a system that has
......
#!/bin/sh
BASEDIR="/usr/local"
libnocache="$BASEDIR/lib/nocache.so"
export LD_PRELOAD="$libnocache $LD_PRELOAD"
if [ "$1" = "-n" ]; then
export NOCACHE_NR_FADVISE="$2"
shift 2
fi
exec "$@"
#!/bin/sh
NOCACHE_PATH=$(dirname "$0")
libnocache="$NOCACHE_PATH/nocache.so"
export LD_PRELOAD="$libnocache $LD_PRELOAD"
export LD_PRELOAD="##libdir##/nocache.so $LD_PRELOAD"
if [ "$1" = "-n" ]; then
export NOCACHE_NR_FADVISE="$2"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment