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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
From: "John V. Belmonte" <jbelmonte@debian.org>
Date: Tue, 26 Aug 2014 16:20:49 +0200
Subject: debian_make
===================================================================
---
Makefile | 29 ++++++++++++++++++++++++++++-
src/Makefile | 33 +++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 209a132..98f9e31 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ PLAT= none
INSTALL_TOP= /usr/local
INSTALL_BIN= $(INSTALL_TOP)/bin
INSTALL_INC= $(INSTALL_TOP)/include
-INSTALL_LIB= $(INSTALL_TOP)/lib
+INSTALL_LIB= $(INSTALL_TOP)/lib/$(DEB_HOST_MULTIARCH)
INSTALL_MAN= $(INSTALL_TOP)/man/man1
#
# You probably want to make INSTALL_LMOD and INSTALL_CMOD consistent with
@@ -126,3 +126,35 @@ lecho:
.PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho
# (end of Makefile)
+
+# Use libtool for binary installs, etc.
+
+export V
+ifeq (,$(VERBOSE))
+ VERBOSITY = --quiet
+else
+ VERBOSITY = --verbose
+endif
+export LIBTOOLCC = $(LIBTOOL) $(VERBOSITY) --tag=CC
+export LIBTOOLCXX = $(LIBTOOL) $(VERBOSITY) --tag=CXX
+# See libtool manual about how to set this
+export LIB_VERSION = 0:0:0
+
+debian_clean:
+ cd src; $(MAKE) $@
+
+debian_test: debian_linux
+ src/lua$(V) test/hello.lua
+
+debian_install: debian_linux
+ cd src; mkdir -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN)
+ cd src; $(LIBTOOLCC) --mode=install $(INSTALL_EXEC) lua$(V) luac$(V) $(INSTALL_BIN)
+ cd src; $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
+ cd src; $(LIBTOOLCC) --mode=install $(INSTALL_DATA) liblua$(V).la $(INSTALL_LIB)
+ cd src; $(LIBTOOLCXX) --mode=install $(INSTALL_DATA) liblua$(V)-c++.la $(INSTALL_LIB)
+ $(foreach NAME,$(TO_MAN),$(INSTALL_DATA) doc/$(NAME) $(INSTALL_MAN)/$(basename $(NAME))$(V)$(suffix $(NAME));)
+
+# ISSUE: MYCFLAGS not honored in the case of a CFLAGS override
+debian_linux:
+ cd src; $(MAKE) debian_all CFLAGS+=-DLUA_USE_LINUX \
+ LIB_LIBS="-lm -ldl" LUA_LIBS="-lreadline" LDFLAGS="$(LDFLAGS)"
diff --git a/src/Makefile b/src/Makefile
index e0d4c9f..8860c3b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,14 +7,17 @@
# Your platform. See PLATS for possible values.
PLAT= none
-CC= gcc
-CFLAGS= -O2 -Wall $(MYCFLAGS)
-AR= ar rcu
-RANLIB= ranlib
+CC ?= gcc
+CXX ?= g++
+CFLAGS ?= -O2 -Wall $(MYCFLAGS)
+CXXFLAGS ?= -O2 -Wall $(MYCXXFLAGS)
+AR ?= ar rcu
+RANLIB ?= ranlib
RM= rm -f
-LIBS= -lm $(MYLIBS)
+LIBS ?= -lm $(MYLIBS)
MYCFLAGS=
+MYCXXFLAGS=
MYLDFLAGS=
MYLIBS=
@@ -180,3 +183,36 @@ print.o: print.c ldebug.h lstate.h lua.h
ltm.h lzio.h lmem.h lopcodes.h lundump.h
# (end of Makefile)
+
+# The following rules use libtool for compiling and linking in order to
+# provide shared library support. While we are at it, our desired version
+# suffixes are added to the targets, preventing conflicts with rules in
+# the upstream makefile.
+
+LIB_NAME = liblua$(V).la
+LIBPP_NAME = liblua$(V)-c++.la
+LIB_OBJS = $(CORE_O:.o=.lo) $(LIB_O:.o=.lo)
+LIBPP_OBJS = $(CORE_O:%.o=%-c++.lo) $(LIB_O:%.o=%-c++.lo)
+
+%-c++.lo %-c++.o: %.c
+ $(LIBTOOLCXX) --mode=compile $(CXX) -o $*-c++.lo -c $(CPPFLAGS) $(CXXFLAGS) $<
+%.lo %.o: %.c
+ $(LIBTOOLCC) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $<
+
+$(LIB_NAME) $(LIB_NAME:.la=.a): $(LIB_OBJS)
+ $(LIBTOOLCC) --mode=link $(CC) -version-info $(LIB_VERSION) \
+ -rpath $(RPATH) -Wl,--version-script,../debian/version-script -o $(LIB_NAME) $(LIB_OBJS) $(LIB_LIBS) $(LDFLAGS)
+$(LIBPP_NAME) $(LIBPP_NAME:.la=.a): $(LIBPP_OBJS)
+ $(LIBTOOLCXX) --mode=link $(CXX) -version-info $(LIB_VERSION) \
+ -rpath $(RPATH) -Wl,--version-script,../debian/version-script -o $(LIBPP_NAME) $(LIBPP_OBJS) $(LIB_LIBS) $(LDFLAGS)
+
+lua$(V): $(LUA_O) $(LIB_NAME)
+ $(LIBTOOLCC) --mode=link $(CC) -Wl,--version-script,../debian/version-script -static -Wl,-E -o $@ $(LUA_O) $(LIB_NAME) $(LUA_LIBS) $(LDFLAGS)
+
+luac$(V): $(LUAC_O) $(LIB_NAME)
+ $(LIBTOOLCC) --mode=link $(CC) -static -o $@ $(LUAC_O) $(LIB_NAME) $(LDFLAGS)
+
+debian_clean:
+ $(LIBTOOLCC) --mode=clean $(RM) $(LUA_O:.o=.lo) $(LUAC_O:.o=.lo) $(LIB_OBJS) $(LIBPP_OBJS) $(LIB_NAME) $(LIBPP_NAME) lua$(V) luac$(V)
+
+debian_all: $(LIB_NAME) $(LIBPP_NAME) lua$(V) luac$(V)
|