blob: f3fe40bc46f019ff4e52152143aa8fbeb63ba2d3 [file] [log] [blame]
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Luca Boccassi <luca.boccassi@microsoft.com>
Date: Mon, 17 Jan 2022 18:12:03 +0000
Subject: [PATCH] Support makefile variables
Makefile*: use CFLAGS/CPPFLAGS/LDFLAGS
Makefile*: allow compiler and install variables to be overridden
Makefile.sharedlibrary: allow destdir and libdir to be overridden
Makefile.sharedlibrary: generate pkg-config file
Forwarded: https://github.com/svaarala/duktape/pull/2457
---
Makefile.cmdline | 5 ++--
Makefile.codepage | 5 ++--
Makefile.dukdebug | 5 ++--
Makefile.eval | 5 ++--
Makefile.eventloop | 5 ++--
Makefile.hello | 5 ++--
Makefile.jsoncbor | 5 ++--
Makefile.jxpretty | 5 ++--
Makefile.sandbox | 5 ++--
Makefile.sharedlibrary | 48 ++++++++++++++++++++-----------
duktape.pc.in | 10 +++++++
11 files changed, 68 insertions(+), 35 deletions(-)
create mode 100644 duktape.pc.in
diff --git a/Makefile.cmdline b/Makefile.cmdline
index 235566b8..0b020510 100644
--- a/Makefile.cmdline
+++ b/Makefile.cmdline
@@ -8,7 +8,8 @@ DUKTAPE_SOURCES = src/duktape.c
CMDLINE_SOURCES = \
examples/cmdline/duk_cmdline.c
-CC = gcc
+CC ?= gcc
+CC := $(CC)
CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
CCOPTS += -I./examples/cmdline -I./src # duktape.h and duk_config.h must be in include path
CCLIBS = -lm
@@ -40,7 +41,7 @@ CMDLINE_SOURCES += extras/module-duktape/duk_module_duktape.c
# http://wiki.duktape.org/Configuring.html
duk: $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES)
- $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS)
linenoise/linenoise.c: linenoise
linenoise:
diff --git a/Makefile.codepage b/Makefile.codepage
index f6ef1582..29fa6ffc 100644
--- a/Makefile.codepage
+++ b/Makefile.codepage
@@ -1,6 +1,7 @@
-CC = gcc
+CC ?= gcc
+CC := $(CC)
codepage:
- $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
src/duktape.c examples/codepage-conv/duk_codepage_conv.c \
examples/codepage-conv/test.c -lm
diff --git a/Makefile.dukdebug b/Makefile.dukdebug
index 9fafcc3f..aa289d2e 100644
--- a/Makefile.dukdebug
+++ b/Makefile.dukdebug
@@ -10,7 +10,8 @@ CMDLINE_SOURCES = \
examples/cmdline/duk_cmdline.c \
examples/debug-trans-socket/duk_trans_socket_unix.c
-CC = gcc
+CC ?= gcc
+CC := $(CC)
CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
CCOPTS += -I./prep -I./examples/cmdline -I./examples/debug-trans-socket
CCOPTS += -DDUK_CMDLINE_DEBUGGER_SUPPORT # enable --debugger in ./duk
@@ -38,4 +39,4 @@ duk: $(CMDLINE_SOURCES)
-DDUK_USE_INTERRUPT_COUNTER \
-DDUK_USE_DEBUGGER_DUMPHEAP \
-DDUK_USE_DEBUGGER_INSPECT
- $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS)
diff --git a/Makefile.eval b/Makefile.eval
index 530f74a8..ce831a69 100644
--- a/Makefile.eval
+++ b/Makefile.eval
@@ -2,8 +2,9 @@
# Example Makefile for building the eval example
#
-CC = gcc
+CC ?= gcc
+CC := $(CC)
eval:
- $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
src/duktape.c examples/eval/eval.c -lm
diff --git a/Makefile.eventloop b/Makefile.eventloop
index 1a75587b..ab1b2f72 100644
--- a/Makefile.eventloop
+++ b/Makefile.eventloop
@@ -2,14 +2,15 @@
# Example Makefile for building the eventloop example
#
-CC = gcc
+CC ?= gcc
+CC := $(CC)
evloop:
@echo "NOTE: The eventloop is an example intended to be used on Linux"
@echo " or other common UNIX variants. It is not fully portable."
@echo ""
- $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \
examples/eventloop/main.c \
examples/eventloop/c_eventloop.c \
examples/eventloop/poll.c \
diff --git a/Makefile.hello b/Makefile.hello
index c12b8e09..61269337 100644
--- a/Makefile.hello
+++ b/Makefile.hello
@@ -13,7 +13,8 @@ DUKTAPE_SOURCES = src/duktape.c
# Compiler options are quite flexible. GCC versions have a significant impact
# on the size of -Os code, e.g. gcc-4.6 is much worse than gcc-4.5.
-CC = gcc
+CC ?= gcc
+CC := $(CC)
CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer
CCOPTS += -I./src # for combined sources
CCLIBS = -lm
@@ -29,4 +30,4 @@ DEFINES =
# For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer
hello: $(DUKTAPE_SOURCES) examples/hello/hello.c
- $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS)
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS)
diff --git a/Makefile.jsoncbor b/Makefile.jsoncbor
index 30387a2f..8f234004 100644
--- a/Makefile.jsoncbor
+++ b/Makefile.jsoncbor
@@ -2,9 +2,10 @@
# Example Makefile for building the jsoncbor example
#
-CC = gcc
+CC ?= gcc
+CC := $(CC)
jsoncbor:
- $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc -Iextras/cbor \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc -Iextras/cbor \
src/duktape.c extras/cbor/duk_cbor.c extras/cbor/jsoncbor.c \
-lm
diff --git a/Makefile.jxpretty b/Makefile.jxpretty
index 7ab00cec..aa53aa8b 100644
--- a/Makefile.jxpretty
+++ b/Makefile.jxpretty
@@ -2,9 +2,10 @@
# Example Makefile for building the jxpretty example
#
-CC = gcc
+CC ?= gcc
+CC := $(CC)
jxpretty:
- $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \
src/duktape.c examples/jxpretty/jxpretty.c \
-lm
diff --git a/Makefile.sandbox b/Makefile.sandbox
index 26bb5ffc..d1d69ce4 100644
--- a/Makefile.sandbox
+++ b/Makefile.sandbox
@@ -2,8 +2,9 @@
# Example Makefile for building the sandbox example
#
-CC = gcc
+CC ?= gcc
+CC := $(CC)
sandbox:
- $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \
src/duktape.c examples/sandbox/sandbox.c -lm
diff --git a/Makefile.sharedlibrary b/Makefile.sharedlibrary
index ace206a1..11620aa7 100644
--- a/Makefile.sharedlibrary
+++ b/Makefile.sharedlibrary
@@ -24,7 +24,9 @@
# convention is to set soname version to (100*MAJOR + MINOR), e.g. 104 for
# Duktape 1.4.x, so that it gets automatically bumped for major and minor
# releases (potentially binary incompatible), but not for patch releases.
+# The formatted version is used for the pkg-config file.
DUK_VERSION = 20600
+DUK_VERSION_FORMATTED = 2.6.0
SONAME_VERSION = 206
REAL_VERSION = $(SONAME_VERSION).$(DUK_VERSION)
@@ -45,44 +45,58 @@ else
endif
# Change to actual path for actual distribution packaging.
-INSTALL_PREFIX = /usr/local
+INSTALL_PREFIX ?= /usr/local
+INSTALL_PREFIX := $(INSTALL_PREFIX)
+DESTDIR ?=
+DESTDIR := $(DESTDIR)
+LIBDIR ?= /lib
+LIBDIR := $(LIBDIR)
# The 'noline' variant may be more appropriate for some distributions; it
# doesn't have #line directives in the combined source.
DUKTAPE_SRCDIR = ./src
#DUKTAPE_SRCDIR = ./src-noline
-CC = gcc
+CC ?= gcc
+CC := $(CC)
.PHONY: all
-all: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX)
+all: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) duktape.pc
# If the default duk_config.h is not suitable for the distribution, modify it
# before compiling the shared library and copy the same, edited duk_config.h
# to $INSTALL_PREFIX/include on installation.
libduktape.$(SO_REALNAME_SUFFIX):
- $(CC) -shared -fPIC -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktape.$(SO_SONAME_SUFFIX) \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fPIC -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktape.$(SO_SONAME_SUFFIX) \
-o $@ $(DUKTAPE_SRCDIR)/duktape.c
libduktaped.$(SO_REALNAME_SUFFIX):
- $(CC) -shared -fPIC -g -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktaped.$(SO_SONAME_SUFFIX) \
+ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fPIC -g -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktaped.$(SO_SONAME_SUFFIX) \
-o $@ $(DUKTAPE_SRCDIR)/duktape.c
+duktape.pc:
+ sed -e "s|@PREFIX@|$(INSTALL_PREFIX)|" \
+ -e "s|@LIBDIR@|$(LIBDIR)|" \
+ -e "s|@VERSION@|$(DUK_VERSION_FORMATTED)|" \
+ duktape.pc.in \
+ > duktape.pc
+
# Symlinks depend on platform conventions.
.PHONY: install
-install: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX)
- mkdir -p $(INSTALL_PREFIX)/lib/
- cp $+ $(INSTALL_PREFIX)/lib/
- rm -f $(INSTALL_PREFIX)/lib/libduktape.so $(INSTALL_PREFIX)/lib/libduktape.$(SO_SONAME_SUFFIX)
- ln -s libduktape.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktape.so
- ln -s libduktape.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktape.$(SO_SONAME_SUFFIX)
- rm -f $(INSTALL_PREFIX)/lib/libduktaped.so $(INSTALL_PREFIX)/lib/libduktaped.$(SO_SONAME_SUFFIX)
- ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktaped.so
- ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktaped.$(SO_SONAME_SUFFIX)
- mkdir -p $(INSTALL_PREFIX)/include/
- cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(INSTALL_PREFIX)/include/
+install: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) duktape.pc
+ mkdir -p $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/pkgconfig
+ cp $+ $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/
+ rm -f $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.so $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.$(SO_SONAME_SUFFIX)
+ ln -s libduktape.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.so
+ ln -s libduktape.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.$(SO_SONAME_SUFFIX)
+ rm -f $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.so $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.$(SO_SONAME_SUFFIX)
+ ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.so
+ ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.$(SO_SONAME_SUFFIX)
+ mv $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/duktape.pc $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/pkgconfig/
+ mkdir -p $(DESTDIR)$(INSTALL_PREFIX)/include/
+ cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(DESTDIR)$(INSTALL_PREFIX)/include/
CCOPTS = -I./examples/cmdline
duk:
- $(CC) $(CCOPTS) -I$(INSTALL_PREFIX)/include -L$(INSTALL_PREFIX)/lib -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm
+ $(CC) $(CCOPTS) -I$(INSTALL_PREFIX)/include -L$(INSTALL_PREFIX)$(LIBDIR) -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm
diff --git a/duktape.pc.in b/duktape.pc.in
new file mode 100644
index 00000000..0985c67e
--- /dev/null
+++ b/duktape.pc.in
@@ -0,0 +1,10 @@
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=${prefix}@LIBDIR@
+includedir=${prefix}/include
+
+Name: duktape
+Description: Embeddable Javascript engine
+Version: @VERSION@
+Libs: -L${libdir} -lduktape
+Cflags: -I${includedir}