1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
From: Christian Kastner <debian@kvr.at>
Date: Fri, 31 Oct 2014 14:57:39 +0100
Subject: Makefile enhancements
Add support for building a shared library, and handle compiler flags properly
(for hardening, etc.).
Three new targets debian-{build,install,clean} are added which build and
install the libraries as we want them.
Forwareded: not-needed
Last-Update: 2014-10-31
Makefile | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index daa1262..cb49655 100644
@@ -8,20 +8,33 @@ AR = ar
VERSION = 1.0
+# Upstream doesn't ship MAJOR/MINOR, but we assume them
+MAJOR_VERSION = $(shell echo $(VERSION) | sed -re 's/([0-9]+)\..*/\1/')
+MINOR_VERSION = $(shell echo $(VERSION) | sed -re 's/.*\.([0-9]+)/\1/')
DIRNAME= rscode-$(VERSION)
+# Installation destinations
+incdir ?= /usr/include/rscode/
+libdir ?= /usr/lib/
+incdest = $(DESTDIR)$(incdir)
+libdest = $(DESTDIR)$(libdir)
+
CC = gcc
# OPTIMIZE_FLAGS = -O69
-DEBUG_FLAGS = -g
-CFLAGS = -Wall -Wstrict-prototypes $(OPTIMIZE_FLAGS) $(DEBUG_FLAGS) -I..
-LDFLAGS = $(OPTIMIZE_FLAGS) $(DEBUG_FLAGS)
+# DEBUG_FLAGS = -g
+CFLAGS ?= -Wall -Wstrict-prototypes $(OPTIMIZE_FLAGS) $(DEBUG_FLAGS) -I..
+LDFLAGS ?= $(OPTIMIZE_FLAGS) $(DEBUG_FLAGS)
+CFLAGS_STATIC = $(CFLAGS) -I.
+CFLAGS_SHARED = $(CFLAGS) -I. -fPIC
LIB_CSRC = rs.c galois.c berlekamp.c crcgen.c
LIB_HSRC = ecc.h
LIB_OBJS = rs.o galois.o berlekamp.o crcgen.o
TARGET_LIB = libecc.a
+STATIC_LIB = librscode.a
+SHARED_LIB = librscode.so.$(MAJOR_VERSION).$(MINOR_VERSION)
TEST_PROGS = example
TARGETS = $(TARGET_LIB) $(TEST_PROGS)
@@ -46,5 +59,31 @@ dist:
depend:
makedepend $(SRCS)
+
+$(SHARED_LIB):$(LIB_CSRC) $(LIB_HSRC)
+ $(CC) $(CFLAGS_SHARED) $(CPPFLAGS) $(LDFLAGS) -shared \
+ -Wl,-soname,librscode.so.$(MAJOR_VERSION) \
+ -o $@ $(LIB_CSRC)
+ ln -s $@ librscode.so.$(MAJOR_VERSION)
+ ln -s librscode.so.$(MAJOR_VERSION) librscode.so
+
+$(STATIC_LIB): $(LIB_CSRC) $(LIB_HSRC)
+ $(CC) $(CFLAGS_STATIC) $(CPPFLAGS) -c $(LIB_CSRC)
+ $(AR) cq $@ $(LIB_OBJS)
+
+debian-build: $(SHARED_LIB) $(STATIC_LIB)
+
+debian-install: debian-build
+ install -d $(libdest)
+ install -d $(incdest)
+ install $(LIB_HSRC) -m 644 $(incdest)
+ install $(STATIC_LIB) -m 644 $(libdest)
+ install $(SHARED_LIB) -m 644 $(libdest)
+ cd $(libdest) && ln -s $(SHARED_LIB) librscode.so.$(MAJOR_VERSION)
+ cd $(libdest) && ln -s librscode.so.$(MAJOR_VERSION) librscode.so
+
+debian-clean: clean
+ rm -f librscode*
+
# DO NOT DELETE THIS LINE -- make depend depends on it.
|