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

GNU Make best practice

parent 609e03d4
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 .
#!/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