Blob Blame History Raw
From a2e679af00bf0ed2d98c8ada4f6c9daf8d5ff3e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Mon, 13 Oct 2014 11:07:20 +0200
Subject: [PATCH] Install file into DESTDIR and LIBDIR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch adds two new "make install" arguments:

LIBDIR to specify path for library (/usr/lib by default)
DESTDIR to prepend a path for all installed files as used by packagers
(default is none).

E.g. "make install DESTDIR=/tmp/dest LIBDIR=/usr/lib64" will install:

/tmp/dest/usr/include/csnappy.h
/tmp/dest/usr/lib64/libcsnappy.so

So one can collect /tmp/dest/ content and distribute it as tar
archives or any other pre-compiled package.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 Makefile | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index f93c3cc..15600d5 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,8 @@ else
 CFLAGS += $(OPT_FLAGS)
 endif
 LDFLAGS = -Wl,-O1 -Wl,--no-undefined
+PREFIX := /usr
+LIBDIR := $(PREFIX)/lib
 
 all: test
 
@@ -88,12 +90,14 @@ unaligned_test_android: unaligned_test.c unaligned_arm.s
 	-Wl,--no-undefined -Wl,-z,noexecstack -lc -lm -o unaligned_test_android
 
 install: csnappy.h libcsnappy.so
-	cp csnappy.h /usr/include/
-	cp libcsnappy.so /usr/lib/
+	install -d "$(DESTDIR)$(PREFIX)"/include
+	install -m 0644 csnappy.h "$(DESTDIR)$(PREFIX)"/include/
+	install -d "$(DESTDIR)$(LIBDIR)"
+	install libcsnappy.so "$(DESTDIR)$(LIBDIR)"
 
 uninstall:
-	rm -f /usr/include/csnappy.h
-	rm -f /usr/lib/libcsnappy.so
+	rm -f "$(DESTDIR)$(PREFIX)"/include/csnappy.h
+	rm -f "$(DESTDIR)$(LIBDIR)"/libcsnappy.so
 
 clean:
 	rm -f *.o *_debug libcsnappy.so cl_tester
-- 
1.9.3