1 Make the library installable. Patch copied from pull request:
3 https://github.com/nayuki/QR-Code-generator/pull/72
5 From 1625fc1665e1f83eb73c0f5670dcfda96dc0b3e4 Mon Sep 17 00:00:00 2001
6 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
7 Date: Tue, 3 Dec 2019 11:57:24 +0100
8 Subject: [PATCH 1/7] Do not append to C/XX/FLAGS but just set them if not
14 2 files changed, 2 insertions(+), 2 deletions(-)
16 diff --git a/c/Makefile b/c/Makefile
17 index fd0c367..b27449c 100644
21 # - CFLAGS: Any extra user-specified compiler flags (can be blank).
23 # Recommended compiler flags:
24 -CFLAGS += -std=c99 -O
25 +CFLAGS ?= -std=c99 -O
27 # Extra flags for diagnostics:
28 # CFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address
29 diff --git a/cpp/Makefile b/cpp/Makefile
30 index f83c512..666f976 100644
34 # - CXXFLAGS: Any extra user-specified compiler flags (can be blank).
36 # Recommended compiler flags:
37 -CXXFLAGS += -std=c++11 -O
38 +CXXFLAGS ?= -std=c++11 -O
40 # Extra flags for diagnostics:
41 # CXXFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address
43 From 2e496a0f59d5c6782c1e3e2a3ca36d0272b384f3 Mon Sep 17 00:00:00 2001
44 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
45 Date: Tue, 3 Dec 2019 11:59:59 +0100
46 Subject: [PATCH 2/7] Make use of -fPIC parameter when building'
51 2 files changed, 2 insertions(+), 2 deletions(-)
53 diff --git a/c/Makefile b/c/Makefile
54 index b27449c..bf79462 100644
57 @@ -77,7 +77,7 @@ $(LIBFILE): $(LIBOBJ)
60 %.o: %.c .deps/timestamp
61 - $(CC) $(CFLAGS) -c -o $@ -MMD -MF .deps/$*.d $<
62 + $(CC) $(CFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $<
64 # Have a place to store header dependencies automatically generated by compiler
66 diff --git a/cpp/Makefile b/cpp/Makefile
67 index 666f976..f37cf66 100644
70 @@ -73,7 +73,7 @@ $(LIBFILE): $(LIBOBJ)
73 %.o: %.cpp .deps/timestamp
74 - $(CXX) $(CXXFLAGS) -c -o $@ -MMD -MF .deps/$*.d $<
75 + $(CXX) $(CXXFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $<
77 # Have a place to store header dependencies automatically generated by compiler
80 From 29489faaa5a3b014c5c2d95ca34033df470de73c Mon Sep 17 00:00:00 2001
81 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
82 Date: Tue, 3 Dec 2019 12:07:19 +0100
83 Subject: [PATCH 3/7] Generate both shared and static libraries
86 c/Makefile | 14 ++++++++++----
87 cpp/Makefile | 14 ++++++++++----
88 2 files changed, 20 insertions(+), 8 deletions(-)
90 diff --git a/c/Makefile b/c/Makefile
91 index bf79462..38eda2d 100644
94 @@ -51,16 +51,19 @@ CFLAGS ?= -std=c99 -O
95 # ---- Targets to build ----
98 -LIBFILE = lib$(LIB).a
100 +LIBFILE = lib$(LIB).so
101 +# Bump the soname number when the ABI changes and gets incompatible
102 +SO_NAME = $(LIBFILE).1
104 MAINS = qrcodegen-demo qrcodegen-test qrcodegen-worker
107 -all: $(LIBFILE) $(MAINS)
108 +all: $(LIBFILE) $(ARFILE) $(MAINS)
110 # Delete build output
112 - rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS)
113 + rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS)
117 @@ -72,9 +75,12 @@ qrcodegen-test: qrcodegen-test.c $(LIBOBJ:%.o=%.c)
118 $(CC) $(CFLAGS) -DQRCODEGEN_TEST -o $@ $^
121 -$(LIBFILE): $(LIBOBJ)
122 +$(ARFILE): $(LIBOBJ)
125 +$(LIBFILE): $(LIBOBJ)
126 + $(CC) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^
129 %.o: %.c .deps/timestamp
130 $(CC) $(CFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $<
131 diff --git a/cpp/Makefile b/cpp/Makefile
132 index f37cf66..606cdad 100644
135 @@ -51,16 +51,19 @@ CXXFLAGS ?= -std=c++11 -O
136 # ---- Targets to build ----
139 -LIBFILE = lib$(LIB).a
140 +ARFILE = lib$(LIB).a
141 +LIBFILE = lib$(LIB).so
142 +# Bump the soname number when the ABI changes and gets incompatible
143 +SO_NAME = $(LIBFILE).1
145 MAINS = QrCodeGeneratorDemo QrCodeGeneratorWorker
148 -all: $(LIBFILE) $(MAINS)
149 +all: $(LIBFILE) $(ARFILE) $(MAINS)
151 # Delete build output
153 - rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS)
154 + rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS)
158 @@ -68,9 +71,12 @@ clean:
159 $(CXX) $(CXXFLAGS) -o $@ $< -L . -l $(LIB)
162 -$(LIBFILE): $(LIBOBJ)
163 +$(ARFILE): $(LIBOBJ)
166 +$(LIBFILE): $(LIBOBJ)
167 + $(CC) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^
170 %.o: %.cpp .deps/timestamp
171 $(CXX) $(CXXFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $<
173 From 064f38d6a8dc0a457728a47ee4ca1e927e46d5ec Mon Sep 17 00:00:00 2001
174 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
175 Date: Tue, 3 Dec 2019 12:45:34 +0100
176 Subject: [PATCH 4/7] Create install targets for C and CPP
179 c/Makefile | 26 ++++++++++++++++++++++++++
180 cpp/Makefile | 27 +++++++++++++++++++++++++++
181 2 files changed, 53 insertions(+)
183 diff --git a/c/Makefile b/c/Makefile
184 index 38eda2d..7521944 100644
187 @@ -34,6 +34,8 @@ CFLAGS ?= -std=c99 -O
188 # Extra flags for diagnostics:
189 # CFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address
191 +# Version information
194 # ---- Controlling make ----
196 @@ -55,9 +57,15 @@ ARFILE = lib$(LIB).a
197 LIBFILE = lib$(LIB).so
198 # Bump the soname number when the ABI changes and gets incompatible
199 SO_NAME = $(LIBFILE).1
200 +REAL_NAME = $(LIBFILE).$(VERSION)
201 +HEADERS = qrcodegen.h
203 MAINS = qrcodegen-demo qrcodegen-test qrcodegen-worker
205 +# define paths to install
206 +INCLUDEDIR ?= $(DESTDIR)/usr/include/qrcodegen
207 +LIBDIR ?= $(DESTDIR)/usr/lib
210 all: $(LIBFILE) $(ARFILE) $(MAINS)
212 @@ -66,6 +74,24 @@ clean:
213 rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS)
216 +install-shared: $(LIBFILE)
217 + install -d $(LIBDIR) || true
218 + install -m 0644 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
219 + rm -f $(LIBDIR)/$(SO_NAME)
220 + ln -s $(REAL_NAME) $(LIBDIR)/$(SO_NAME)
221 + rm -f $(LIBDIR)/$(LIBFILE)
222 + ln -s $(SO_NAME) $(LIBDIR)/$(LIBFILE)
224 +install-static: $(ARFILE)
225 + install -d $(LIBDIR) || true
226 + install -m 0644 $(ARFILE) $(LIBDIR)/$(ARFILE)
228 +install-header: $(HEADERS)
229 + install -d $(INCLUDEDIR) || true
230 + install -m 0644 $(HEADERS) $(INCLUDEDIR)/
232 +install: install-shared install-static install-header
236 $(CC) $(CFLAGS) -o $@ $< -L . -l $(LIB)
237 diff --git a/cpp/Makefile b/cpp/Makefile
238 index 606cdad..3271bd8 100644
241 @@ -34,6 +34,8 @@ CXXFLAGS ?= -std=c++11 -O
242 # Extra flags for diagnostics:
243 # CXXFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address
245 +# Version information
248 # ---- Controlling make ----
250 @@ -55,9 +57,16 @@ ARFILE = lib$(LIB).a
251 LIBFILE = lib$(LIB).so
252 # Bump the soname number when the ABI changes and gets incompatible
253 SO_NAME = $(LIBFILE).1
254 +REAL_NAME = $(LIBFILE).$(VERSION)
255 +HEADERS = QrCode.hpp
257 MAINS = QrCodeGeneratorDemo QrCodeGeneratorWorker
259 +# define paths to install
260 +INCLUDEDIR ?= $(DESTDIR)/usr/include/qrcodegen
261 +LIBDIR ?= $(DESTDIR)/usr/lib
265 all: $(LIBFILE) $(ARFILE) $(MAINS)
267 @@ -66,6 +75,24 @@ clean:
268 rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS)
271 +install-shared: $(LIBFILE)
272 + install -d $(LIBDIR) || true
273 + install -m 0644 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
274 + rm -f $(LIBDIR)/$(SO_NAME)
275 + ln -s $(REAL_NAME) $(LIBDIR)/$(SO_NAME)
276 + rm -f $(LIBDIR)/$(LIBFILE)
277 + ln -s $(SO_NAME) $(LIBDIR)/$(LIBFILE)
279 +install-static: $(ARFILE)
280 + install -d $(LIBDIR) || true
281 + install -m 0644 $(ARFILE) $(LIBDIR)/$(ARFILE)
283 +install-header: $(HEADERS)
284 + install -d $(INCLUDEDIR) || true
285 + install -m 0644 $(HEADERS) $(INCLUDEDIR)/
287 +install: install-shared install-static install-header
291 $(CXX) $(CXXFLAGS) -o $@ $< -L . -l $(LIB)
293 From a635ff4654f94ab26b458c46a8841543e5bc8c67 Mon Sep 17 00:00:00 2001
294 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
295 Date: Tue, 3 Dec 2019 12:50:39 +0100
296 Subject: [PATCH 5/7] Rename cpp library to qrcodegencpp to avoid conflict
300 1 file changed, 1 insertion(+), 1 deletion(-)
302 diff --git a/cpp/Makefile b/cpp/Makefile
303 index 3271bd8..42fa4ff 100644
306 @@ -52,7 +52,7 @@ VERSION = 1.5.0
308 # ---- Targets to build ----
313 LIBFILE = lib$(LIB).so
314 # Bump the soname number when the ABI changes and gets incompatible
316 From c073e7dfad6454dfd725a69c347f8272d29ea41c Mon Sep 17 00:00:00 2001
317 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
318 Date: Tue, 7 Jan 2020 09:18:59 +0100
319 Subject: [PATCH 6/7] Add PREFIX variable and few minor fixes from code review
322 c/Makefile | 9 +++++----
323 cpp/Makefile | 9 +++++----
324 2 files changed, 10 insertions(+), 8 deletions(-)
326 diff --git a/c/Makefile b/c/Makefile
327 index 7521944..874933e 100644
331 # - CFLAGS: Any extra user-specified compiler flags (can be blank).
333 # Recommended compiler flags:
334 -CFLAGS ?= -std=c99 -O
337 # Extra flags for diagnostics:
338 # CFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address
339 @@ -63,8 +63,9 @@ LIBOBJ = qrcodegen.o
340 MAINS = qrcodegen-demo qrcodegen-test qrcodegen-worker
342 # define paths to install
343 -INCLUDEDIR ?= $(DESTDIR)/usr/include/qrcodegen
344 -LIBDIR ?= $(DESTDIR)/usr/lib
345 +PREFIX ?= /usr/local
346 +INCLUDEDIR ?= $(DESTDIR)$(PREFIX)/include/qrcodegen
347 +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
350 all: $(LIBFILE) $(ARFILE) $(MAINS)
351 @@ -105,7 +106,7 @@ $(ARFILE): $(LIBOBJ)
354 $(LIBFILE): $(LIBOBJ)
355 - $(CC) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^
356 + $(CC) $(CFLAGS) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^
359 %.o: %.c .deps/timestamp
360 diff --git a/cpp/Makefile b/cpp/Makefile
361 index 42fa4ff..f8d9b7f 100644
365 # - CXXFLAGS: Any extra user-specified compiler flags (can be blank).
367 # Recommended compiler flags:
368 -CXXFLAGS ?= -std=c++11 -O
369 +CXXFLAGS += -std=c++11
371 # Extra flags for diagnostics:
372 # CXXFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address
373 @@ -63,8 +63,9 @@ LIBOBJ = QrCode.o
374 MAINS = QrCodeGeneratorDemo QrCodeGeneratorWorker
376 # define paths to install
377 -INCLUDEDIR ?= $(DESTDIR)/usr/include/qrcodegen
378 -LIBDIR ?= $(DESTDIR)/usr/lib
379 +PREFIX ?= /usr/local
380 +INCLUDEDIR ?= $(DESTDIR)$(PREFIX)/include/qrcodegen
381 +LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
385 @@ -102,7 +103,7 @@ $(ARFILE): $(LIBOBJ)
388 $(LIBFILE): $(LIBOBJ)
389 - $(CC) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^
390 + $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^
393 %.o: %.cpp .deps/timestamp
395 From b43c1de5cc874535a7f549cef437f6849528e455 Mon Sep 17 00:00:00 2001
396 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
397 Date: Tue, 7 Jan 2020 13:12:32 +0100
398 Subject: [PATCH 7/7] Install static and shared library as an executable
402 cpp/Makefile | 4 ++--
403 2 files changed, 4 insertions(+), 4 deletions(-)
405 diff --git a/c/Makefile b/c/Makefile
406 index 874933e..631cc71 100644
409 @@ -77,7 +77,7 @@ clean:
411 install-shared: $(LIBFILE)
412 install -d $(LIBDIR) || true
413 - install -m 0644 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
414 + install -m 0755 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
415 rm -f $(LIBDIR)/$(SO_NAME)
416 ln -s $(REAL_NAME) $(LIBDIR)/$(SO_NAME)
417 rm -f $(LIBDIR)/$(LIBFILE)
418 @@ -85,7 +85,7 @@ install-shared: $(LIBFILE)
420 install-static: $(ARFILE)
421 install -d $(LIBDIR) || true
422 - install -m 0644 $(ARFILE) $(LIBDIR)/$(ARFILE)
423 + install -m 0755 $(ARFILE) $(LIBDIR)/$(ARFILE)
425 install-header: $(HEADERS)
426 install -d $(INCLUDEDIR) || true
427 diff --git a/cpp/Makefile b/cpp/Makefile
428 index f8d9b7f..bbd861e 100644
431 @@ -78,7 +78,7 @@ clean:
433 install-shared: $(LIBFILE)
434 install -d $(LIBDIR) || true
435 - install -m 0644 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
436 + install -m 0755 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
437 rm -f $(LIBDIR)/$(SO_NAME)
438 ln -s $(REAL_NAME) $(LIBDIR)/$(SO_NAME)
439 rm -f $(LIBDIR)/$(LIBFILE)
440 @@ -86,7 +86,7 @@ install-shared: $(LIBFILE)
442 install-static: $(ARFILE)
443 install -d $(LIBDIR) || true
444 - install -m 0644 $(ARFILE) $(LIBDIR)/$(ARFILE)
445 + install -m 0755 $(ARFILE) $(LIBDIR)/$(ARFILE)
447 install-header: $(HEADERS)
448 install -d $(INCLUDEDIR) || true