Commit 2830e104 authored by Dmitry Smirnov's avatar Dmitry Smirnov Committed by Julius Plenz

GNU Make best practice

parent 609e03d4
default: all #!/usr/bin/make -f
all: cachestats cachedel nocache.so # -*- makefile -*-
.PHONY: test
GCC = gcc $(CFLAGS) PREFIX ?= /usr/local
%.c: Makefile MANDIR ?= /share/man/man1
cachestats: cachestats.c BINDIR ?= /bin
$(GCC) -Wall -o cachestats cachestats.c LIBDIR ?= /lib
cachedel: cachedel.c mandir = $(DESTDIR)$(PREFIX)$(MANDIR)
$(GCC) -Wall -o cachedel cachedel.c bindir = $(DESTDIR)$(PREFIX)$(BINDIR)
nocache.o: nocache.c libdir = $(DESTDIR)$(PREFIX)$(LIBDIR)
$(GCC) -Wall -fPIC -c -o nocache.o nocache.c
fcntl_helpers.o: fcntl_helpers.c CACHE_BINS=cachedel cachestats
$(GCC) -Wall -fPIC -c -o fcntl_helpers.o fcntl_helpers.c NOCACHE_BINS=nocache.o fcntl_helpers.o
nocache.so: nocache.o fcntl_helpers.o MANPAGES=$(wildcard man/*.1)
$(GCC) -Wall -pthread -shared -Wl,-soname,nocache.so -o nocache.so nocache.o fcntl_helpers.o -ldl
CFLAGS+= -Wall
install: all GCC = gcc $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
install -m 0644 nocache.so /usr/local/lib
install -m 0755 nocache.global /usr/local/bin/nocache .PHONY: all
all: $(CACHE_BINS) nocache.so nocache
test:
cd t; prove -v . $(CACHE_BINS):
$(GCC) -o $@ $@.c
$(NOCACHE_BINS):
$(GCC) -fPIC -c -o $@ $(@:.o=.c)
nocache.global:
sed 's!##libdir##!$(subst $(DESTDIR),,$(libdir))!' <nocache.in >$@
clean: nocache:
rm -f cachestats cachedel fcntl_helpers.o nocache.o nocache.so 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 .
#!/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 #!/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 if [ "$1" = "-n" ]; then
export NOCACHE_NR_FADVISE="$2" 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