Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Luca Boccassi <luca.boccassi@microsoft.com> |
| 3 | Date: Mon, 17 Jan 2022 18:12:03 +0000 |
| 4 | Subject: [PATCH] Support makefile variables |
| 5 | |
| 6 | Makefile*: use CFLAGS/CPPFLAGS/LDFLAGS |
| 7 | Makefile*: allow compiler and install variables to be overridden |
| 8 | Makefile.sharedlibrary: allow destdir and libdir to be overridden |
| 9 | Makefile.sharedlibrary: generate pkg-config file |
| 10 | |
| 11 | Forwarded: https://github.com/svaarala/duktape/pull/2457 |
| 12 | --- |
| 13 | Makefile.cmdline | 5 ++-- |
| 14 | Makefile.codepage | 5 ++-- |
| 15 | Makefile.dukdebug | 5 ++-- |
| 16 | Makefile.eval | 5 ++-- |
| 17 | Makefile.eventloop | 5 ++-- |
| 18 | Makefile.hello | 5 ++-- |
| 19 | Makefile.jsoncbor | 5 ++-- |
| 20 | Makefile.jxpretty | 5 ++-- |
| 21 | Makefile.sandbox | 5 ++-- |
| 22 | Makefile.sharedlibrary | 48 ++++++++++++++++++++----------- |
| 23 | duktape.pc.in | 10 +++++++ |
| 24 | 11 files changed, 68 insertions(+), 35 deletions(-) |
| 25 | create mode 100644 duktape.pc.in |
| 26 | |
| 27 | diff --git a/Makefile.cmdline b/Makefile.cmdline |
| 28 | index 235566b8..0b020510 100644 |
| 29 | --- a/Makefile.cmdline |
| 30 | +++ b/Makefile.cmdline |
| 31 | @@ -8,7 +8,8 @@ DUKTAPE_SOURCES = src/duktape.c |
| 32 | CMDLINE_SOURCES = \ |
| 33 | examples/cmdline/duk_cmdline.c |
| 34 | |
| 35 | -CC = gcc |
| 36 | +CC ?= gcc |
| 37 | +CC := $(CC) |
| 38 | CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer |
| 39 | CCOPTS += -I./examples/cmdline -I./src # duktape.h and duk_config.h must be in include path |
| 40 | CCLIBS = -lm |
| 41 | @@ -40,7 +41,7 @@ CMDLINE_SOURCES += extras/module-duktape/duk_module_duktape.c |
| 42 | # http://wiki.duktape.org/Configuring.html |
| 43 | |
| 44 | duk: $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) |
| 45 | - $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) |
| 46 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) |
| 47 | |
| 48 | linenoise/linenoise.c: linenoise |
| 49 | linenoise: |
| 50 | diff --git a/Makefile.codepage b/Makefile.codepage |
| 51 | index f6ef1582..29fa6ffc 100644 |
| 52 | --- a/Makefile.codepage |
| 53 | +++ b/Makefile.codepage |
| 54 | @@ -1,6 +1,7 @@ |
| 55 | -CC = gcc |
| 56 | +CC ?= gcc |
| 57 | +CC := $(CC) |
| 58 | |
| 59 | codepage: |
| 60 | - $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ |
| 61 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ |
| 62 | src/duktape.c examples/codepage-conv/duk_codepage_conv.c \ |
| 63 | examples/codepage-conv/test.c -lm |
| 64 | diff --git a/Makefile.dukdebug b/Makefile.dukdebug |
| 65 | index 9fafcc3f..aa289d2e 100644 |
| 66 | --- a/Makefile.dukdebug |
| 67 | +++ b/Makefile.dukdebug |
| 68 | @@ -10,7 +10,8 @@ CMDLINE_SOURCES = \ |
| 69 | examples/cmdline/duk_cmdline.c \ |
| 70 | examples/debug-trans-socket/duk_trans_socket_unix.c |
| 71 | |
| 72 | -CC = gcc |
| 73 | +CC ?= gcc |
| 74 | +CC := $(CC) |
| 75 | CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer |
| 76 | CCOPTS += -I./prep -I./examples/cmdline -I./examples/debug-trans-socket |
| 77 | CCOPTS += -DDUK_CMDLINE_DEBUGGER_SUPPORT # enable --debugger in ./duk |
| 78 | @@ -38,4 +39,4 @@ duk: $(CMDLINE_SOURCES) |
| 79 | -DDUK_USE_INTERRUPT_COUNTER \ |
| 80 | -DDUK_USE_DEBUGGER_DUMPHEAP \ |
| 81 | -DDUK_USE_DEBUGGER_INSPECT |
| 82 | - $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) |
| 83 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) $(CMDLINE_SOURCES) $(CCLIBS) |
| 84 | diff --git a/Makefile.eval b/Makefile.eval |
| 85 | index 530f74a8..ce831a69 100644 |
| 86 | --- a/Makefile.eval |
| 87 | +++ b/Makefile.eval |
| 88 | @@ -2,8 +2,9 @@ |
| 89 | # Example Makefile for building the eval example |
| 90 | # |
| 91 | |
| 92 | -CC = gcc |
| 93 | +CC ?= gcc |
| 94 | +CC := $(CC) |
| 95 | |
| 96 | eval: |
| 97 | - $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ |
| 98 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ |
| 99 | src/duktape.c examples/eval/eval.c -lm |
| 100 | diff --git a/Makefile.eventloop b/Makefile.eventloop |
| 101 | index 1a75587b..ab1b2f72 100644 |
| 102 | --- a/Makefile.eventloop |
| 103 | +++ b/Makefile.eventloop |
| 104 | @@ -2,14 +2,15 @@ |
| 105 | # Example Makefile for building the eventloop example |
| 106 | # |
| 107 | |
| 108 | -CC = gcc |
| 109 | +CC ?= gcc |
| 110 | +CC := $(CC) |
| 111 | |
| 112 | evloop: |
| 113 | @echo "NOTE: The eventloop is an example intended to be used on Linux" |
| 114 | @echo " or other common UNIX variants. It is not fully portable." |
| 115 | @echo "" |
| 116 | |
| 117 | - $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ |
| 118 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ |
| 119 | examples/eventloop/main.c \ |
| 120 | examples/eventloop/c_eventloop.c \ |
| 121 | examples/eventloop/poll.c \ |
| 122 | diff --git a/Makefile.hello b/Makefile.hello |
| 123 | index c12b8e09..61269337 100644 |
| 124 | --- a/Makefile.hello |
| 125 | +++ b/Makefile.hello |
| 126 | @@ -13,7 +13,8 @@ DUKTAPE_SOURCES = src/duktape.c |
| 127 | # Compiler options are quite flexible. GCC versions have a significant impact |
| 128 | # on the size of -Os code, e.g. gcc-4.6 is much worse than gcc-4.5. |
| 129 | |
| 130 | -CC = gcc |
| 131 | +CC ?= gcc |
| 132 | +CC := $(CC) |
| 133 | CCOPTS = -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer |
| 134 | CCOPTS += -I./src # for combined sources |
| 135 | CCLIBS = -lm |
| 136 | @@ -29,4 +30,4 @@ DEFINES = |
| 137 | # For debugging, use -O0 -g -ggdb, and don't add -fomit-frame-pointer |
| 138 | |
| 139 | hello: $(DUKTAPE_SOURCES) examples/hello/hello.c |
| 140 | - $(CC) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS) |
| 141 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $(DEFINES) $(CCOPTS) $(DUKTAPE_SOURCES) examples/hello/hello.c $(CCLIBS) |
| 142 | diff --git a/Makefile.jsoncbor b/Makefile.jsoncbor |
| 143 | index 30387a2f..8f234004 100644 |
| 144 | --- a/Makefile.jsoncbor |
| 145 | +++ b/Makefile.jsoncbor |
| 146 | @@ -2,9 +2,10 @@ |
| 147 | # Example Makefile for building the jsoncbor example |
| 148 | # |
| 149 | |
| 150 | -CC = gcc |
| 151 | +CC ?= gcc |
| 152 | +CC := $(CC) |
| 153 | |
| 154 | jsoncbor: |
| 155 | - $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc -Iextras/cbor \ |
| 156 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc -Iextras/cbor \ |
| 157 | src/duktape.c extras/cbor/duk_cbor.c extras/cbor/jsoncbor.c \ |
| 158 | -lm |
| 159 | diff --git a/Makefile.jxpretty b/Makefile.jxpretty |
| 160 | index 7ab00cec..aa53aa8b 100644 |
| 161 | --- a/Makefile.jxpretty |
| 162 | +++ b/Makefile.jxpretty |
| 163 | @@ -2,9 +2,10 @@ |
| 164 | # Example Makefile for building the jxpretty example |
| 165 | # |
| 166 | |
| 167 | -CC = gcc |
| 168 | +CC ?= gcc |
| 169 | +CC := $(CC) |
| 170 | |
| 171 | jxpretty: |
| 172 | - $(CC) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ |
| 173 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -Wall -Wextra -O2 -Isrc \ |
| 174 | src/duktape.c examples/jxpretty/jxpretty.c \ |
| 175 | -lm |
| 176 | diff --git a/Makefile.sandbox b/Makefile.sandbox |
| 177 | index 26bb5ffc..d1d69ce4 100644 |
| 178 | --- a/Makefile.sandbox |
| 179 | +++ b/Makefile.sandbox |
| 180 | @@ -2,8 +2,9 @@ |
| 181 | # Example Makefile for building the sandbox example |
| 182 | # |
| 183 | |
| 184 | -CC = gcc |
| 185 | +CC ?= gcc |
| 186 | +CC := $(CC) |
| 187 | |
| 188 | sandbox: |
| 189 | - $(CC) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ |
| 190 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ -std=c99 -O2 -Wall -Wextra -Isrc/ \ |
| 191 | src/duktape.c examples/sandbox/sandbox.c -lm |
| 192 | diff --git a/Makefile.sharedlibrary b/Makefile.sharedlibrary |
| 193 | index ace206a1..11620aa7 100644 |
| 194 | --- a/Makefile.sharedlibrary |
| 195 | +++ b/Makefile.sharedlibrary |
| 196 | @@ -24,7 +24,9 @@ |
| 197 | # convention is to set soname version to (100*MAJOR + MINOR), e.g. 104 for |
| 198 | # Duktape 1.4.x, so that it gets automatically bumped for major and minor |
| 199 | # releases (potentially binary incompatible), but not for patch releases. |
| 200 | +# The formatted version is used for the pkg-config file. |
| 201 | DUK_VERSION = 20600 |
| 202 | +DUK_VERSION_FORMATTED = 2.6.0 |
| 203 | SONAME_VERSION = 206 |
| 204 | REAL_VERSION = $(SONAME_VERSION).$(DUK_VERSION) |
| 205 | |
| 206 | @@ -45,44 +45,58 @@ else |
| 207 | endif |
| 208 | |
| 209 | # Change to actual path for actual distribution packaging. |
| 210 | -INSTALL_PREFIX = /usr/local |
| 211 | +INSTALL_PREFIX ?= /usr/local |
| 212 | +INSTALL_PREFIX := $(INSTALL_PREFIX) |
| 213 | +DESTDIR ?= |
| 214 | +DESTDIR := $(DESTDIR) |
| 215 | +LIBDIR ?= /lib |
| 216 | +LIBDIR := $(LIBDIR) |
| 217 | |
| 218 | # The 'noline' variant may be more appropriate for some distributions; it |
| 219 | # doesn't have #line directives in the combined source. |
| 220 | DUKTAPE_SRCDIR = ./src |
| 221 | #DUKTAPE_SRCDIR = ./src-noline |
| 222 | |
| 223 | -CC = gcc |
| 224 | +CC ?= gcc |
| 225 | +CC := $(CC) |
| 226 | |
| 227 | .PHONY: all |
| 228 | -all: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) |
| 229 | +all: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) duktape.pc |
| 230 | |
| 231 | # If the default duk_config.h is not suitable for the distribution, modify it |
| 232 | # before compiling the shared library and copy the same, edited duk_config.h |
| 233 | # to $INSTALL_PREFIX/include on installation. |
| 234 | |
| 235 | libduktape.$(SO_REALNAME_SUFFIX): |
| 236 | - $(CC) -shared -fPIC -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktape.$(SO_SONAME_SUFFIX) \ |
| 237 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fPIC -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktape.$(SO_SONAME_SUFFIX) \ |
| 238 | -o $@ $(DUKTAPE_SRCDIR)/duktape.c |
| 239 | |
| 240 | libduktaped.$(SO_REALNAME_SUFFIX): |
| 241 | - $(CC) -shared -fPIC -g -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktaped.$(SO_SONAME_SUFFIX) \ |
| 242 | + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fPIC -g -Wall -Wextra -Os -Wl,$(LD_SONAME_ARG),libduktaped.$(SO_SONAME_SUFFIX) \ |
| 243 | -o $@ $(DUKTAPE_SRCDIR)/duktape.c |
| 244 | |
| 245 | +duktape.pc: |
| 246 | + sed -e "s|@PREFIX@|$(INSTALL_PREFIX)|" \ |
| 247 | + -e "s|@LIBDIR@|$(LIBDIR)|" \ |
| 248 | + -e "s|@VERSION@|$(DUK_VERSION_FORMATTED)|" \ |
| 249 | + duktape.pc.in \ |
| 250 | + > duktape.pc |
| 251 | + |
| 252 | # Symlinks depend on platform conventions. |
| 253 | .PHONY: install |
| 254 | -install: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) |
| 255 | - mkdir -p $(INSTALL_PREFIX)/lib/ |
| 256 | - cp $+ $(INSTALL_PREFIX)/lib/ |
| 257 | - rm -f $(INSTALL_PREFIX)/lib/libduktape.so $(INSTALL_PREFIX)/lib/libduktape.$(SO_SONAME_SUFFIX) |
| 258 | - ln -s libduktape.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktape.so |
| 259 | - ln -s libduktape.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktape.$(SO_SONAME_SUFFIX) |
| 260 | - rm -f $(INSTALL_PREFIX)/lib/libduktaped.so $(INSTALL_PREFIX)/lib/libduktaped.$(SO_SONAME_SUFFIX) |
| 261 | - ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktaped.so |
| 262 | - ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(INSTALL_PREFIX)/lib/libduktaped.$(SO_SONAME_SUFFIX) |
| 263 | - mkdir -p $(INSTALL_PREFIX)/include/ |
| 264 | - cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(INSTALL_PREFIX)/include/ |
| 265 | +install: libduktape.$(SO_REALNAME_SUFFIX) libduktaped.$(SO_REALNAME_SUFFIX) duktape.pc |
| 266 | + mkdir -p $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/pkgconfig |
| 267 | + cp $+ $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/ |
| 268 | + rm -f $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.so $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.$(SO_SONAME_SUFFIX) |
| 269 | + ln -s libduktape.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.so |
| 270 | + ln -s libduktape.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktape.$(SO_SONAME_SUFFIX) |
| 271 | + rm -f $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.so $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.$(SO_SONAME_SUFFIX) |
| 272 | + ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.so |
| 273 | + ln -s libduktaped.$(SO_REALNAME_SUFFIX) $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/libduktaped.$(SO_SONAME_SUFFIX) |
| 274 | + mv $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/duktape.pc $(DESTDIR)$(INSTALL_PREFIX)$(LIBDIR)/pkgconfig/ |
| 275 | + mkdir -p $(DESTDIR)$(INSTALL_PREFIX)/include/ |
| 276 | + cp $(DUKTAPE_SRCDIR)/duktape.h $(DUKTAPE_SRCDIR)/duk_config.h $(DESTDIR)$(INSTALL_PREFIX)/include/ |
| 277 | |
| 278 | CCOPTS = -I./examples/cmdline |
| 279 | duk: |
| 280 | - $(CC) $(CCOPTS) -I$(INSTALL_PREFIX)/include -L$(INSTALL_PREFIX)/lib -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm |
| 281 | + $(CC) $(CCOPTS) -I$(INSTALL_PREFIX)/include -L$(INSTALL_PREFIX)$(LIBDIR) -Wall -Wextra -Os -o $@ ./examples/cmdline/duk_cmdline.c -lduktape -lm |
| 282 | diff --git a/duktape.pc.in b/duktape.pc.in |
| 283 | new file mode 100644 |
| 284 | index 00000000..0985c67e |
| 285 | --- /dev/null |
| 286 | +++ b/duktape.pc.in |
| 287 | @@ -0,0 +1,10 @@ |
| 288 | +prefix=@PREFIX@ |
| 289 | +exec_prefix=${prefix} |
| 290 | +libdir=${prefix}@LIBDIR@ |
| 291 | +includedir=${prefix}/include |
| 292 | + |
| 293 | +Name: duktape |
| 294 | +Description: Embeddable Javascript engine |
| 295 | +Version: @VERSION@ |
| 296 | +Libs: -L${libdir} -lduktape |
| 297 | +Cflags: -I${includedir} |