blob: 206c44040265ad00b0dae8e236f05ea56993fe58 [file] [log] [blame]
Laurence Lundblade01168ef2019-01-21 17:05:47 -08001# Makefile -- UNIX-style make for qcbor as a lib and command line test
Laurence Lundbladedf1c1cf2019-01-17 11:55:05 -08002#
Laurence Lundblade7596eef2024-12-21 10:08:32 -07003# Copyright (c) 2018-2024, Laurence Lundblade. All rights reserved.
Laurence Lundbladedf1c1cf2019-01-17 11:55:05 -08004#
Laurence Lundblade01168ef2019-01-21 17:05:47 -08005# SPDX-License-Identifier: BSD-3-Clause
6#
7# See BSD-3-Clause license in README.md
8#
9
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080010
Laurence Lundbladeb9702452021-03-08 21:02:57 -080011# The math library is needed for floating-point support. To
12# avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE
akil53a69812020-11-25 05:24:10 +040013LIBS=-lm
Laurence Lundbladef19f4da2020-03-01 17:41:53 -080014
Laurence Lundbladeb9702452021-03-08 21:02:57 -080015
16# The QCBOR makefile uses a minimum of compiler flags so that it will
17# work out-of-the-box with a wide variety of compilers. For example,
Laurence Lundbladec5a342f2021-05-17 01:17:06 -070018# some compilers error out on some of the warnings flags gcc supports.
19# The $(CMD_LINE) variable allows passing in extra flags. This is
Laurence Lundbladeb9702452021-03-08 21:02:57 -080020# used on the stringent build script that is in
21# https://github.com/laurencelundblade/qdv. This script is used
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070022# before pushes to master (though not yet through an automated build
23# process). See "warn:" below.
Laurence Lundbladeb9702452021-03-08 21:02:57 -080024CFLAGS=$(CMD_LINE) -I inc -I test -Os -fPIC
Laurence Lundblade74d265c2018-09-19 10:21:00 -070025
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080026
Laurence Lundblade7596eef2024-12-21 10:08:32 -070027QCBOR_OBJ=src/UsefulBuf.o \
28 src/qcbor_main_encode.o \
29 src/qcbor_number_encode.o \
30 src/qcbor_main_decode.o \
31 src/qcbor_spiffy_decode.o \
32 src/qcbor_number_decode.o \
33 src/qcbor_tag_decode.o \
34 src/ieee754.o \
35 src/qcbor_err_to_str.o
Laurence Lundblade781fd822018-10-01 09:37:52 -070036
Laurence Lundblade2117bbf2024-12-30 22:56:41 -050037TEST_OBJ=test/UsefulBuf_Tests.o \
38 test/qcbor_encode_tests.o \
39 test/qcbor_decode_tests.o \
40 test/run_tests.o \
41 test/float_tests.o \
42 test/half_to_double_from_rfc7049.o \
43 example.o \
44 tag-examples.o \
45 ub-example.o
Michael Eckel9c42c202020-03-04 18:26:11 +010046
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070047.PHONY: all so install uninstall clean warn
Michael Eckel9c42c202020-03-04 18:26:11 +010048
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070049all: qcbortest libqcbor.a
Laurence Lundblade02990fa2020-03-27 09:51:58 -070050
51so: libqcbor.so
Laurence Lundblade781fd822018-10-01 09:37:52 -070052
Laurence Lundblade2c978832018-12-13 01:10:21 -080053qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o
Norbert KamiƄski6bbc4ed2020-11-27 02:44:04 +010054 $(CC) -o $@ $^ libqcbor.a $(LIBS)
Laurence Lundblade74d265c2018-09-19 10:21:00 -070055
Laurence Lundbladec9d3dcf2018-12-19 18:11:36 -080056libqcbor.a: $(QCBOR_OBJ)
Laurence Lundblade2c978832018-12-13 01:10:21 -080057 ar -r $@ $^
Laurence Lundbladec2b14572018-11-01 13:07:49 +070058
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070059# run "make warn" as a handy way to compile with the warning flags
60# used in the QCBOR release process. See CFLAGS above.
61warn:
Laurence Lundblade5d83b9b2024-06-29 11:19:39 -070062 make CMD_LINE="$(CMD_LINE) -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual"
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070063
Laurence Lundbladeb9702452021-03-08 21:02:57 -080064
Laurence Lundblade02990fa2020-03-27 09:51:58 -070065# The shared library is not made by default because of platform
66# variability For example MacOS and Linux behave differently and some
67# IoT OS's don't support them at all.
Michael Eckel7e8effa2020-03-09 18:19:17 +010068libqcbor.so: $(QCBOR_OBJ)
Laurence Lundblade02990fa2020-03-27 09:51:58 -070069 $(CC) -shared $^ $(CFLAGS) -o $@
Michael Eckel7e8effa2020-03-09 18:19:17 +010070
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080071PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h \
72 inc/qcbor/qcbor_private.h \
73 inc/qcbor/qcbor_common.h \
Laurence Lundblade2117bbf2024-12-30 22:56:41 -050074 inc/qcbor/qcbor_main_encode.h \
75 inc/qcbor/qcbor_number_encode.h \
76 inc/qcbor/qcbor_tag_encode.h \
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070077 inc/qcbor/qcbor_decode.h \
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080078 inc/qcbor/qcbor_main_decode.h \
79 inc/qcbor/qcbor_spiffy_decode.h \
80 inc/qcbor/qcbor_tag_decode.h \
81 inc/qcbor/qcbor_number_decode.h
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080082
Michael Eckel9c42c202020-03-04 18:26:11 +010083src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080084
Laurence Lundblade2117bbf2024-12-30 22:56:41 -050085src/qcbor_main_encode.o: inc/qcbor/UsefulBuf.h \
86 inc/qcbor/qcbor_private.h \
87 inc/qcbor/qcbor_common.h \
88 inc/qcbor/qcbor_main_encode.h
89
90src/qcbor_tag_encode.o: inc/qcbor/UsefulBuf.h \
91 inc/qcbor/qcbor_private.h \
92 inc/qcbor/qcbor_common.h \
93 inc/qcbor/qcbor_main_encode.h \
94 inc/qcbor/qcbor_number_encode.h \
95 inc/qcbor/qcbor_tag_encode.h \
96 src/ieee754.h
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080097
98src/qcbor_main_decode.o: inc/qcbor/UsefulBuf.h \
99 inc/qcbor/qcbor_private.h \
100 inc/qcbor/qcbor_common.h \
101 inc/qcbor/qcbor_main_decode.h \
102 inc/qcbor/qcbor_spiffy_decode.h \
Laurence Lundbladecf49acc2024-12-08 20:48:31 -0700103 inc/qcbor/qcbor_tag_decode.h \
Laurence Lundblade926ccfc2024-12-05 20:34:55 -0800104 src/decode_nesting.h \
105 src/ieee754.h
106
Laurence Lundbladecf49acc2024-12-08 20:48:31 -0700107src/qcbor_tag_decode.o: inc/qcbor/UsefulBuf.h \
108 inc/qcbor/qcbor_private.h \
109 inc/qcbor/qcbor_common.h \
110 inc/qcbor/qcbor_main_decode.h \
111 inc/qcbor/qcbor_spiffy_decode.h \
112 src/decode_nesting.h \
113 inc/qcbor/qcbor_tag_decode.h
114
Laurence Lundblade2117bbf2024-12-30 22:56:41 -0500115src/qcbor_spiffy_decode.o: inc/qcbor/UsefulBuf.h \
116 inc/qcbor/qcbor_private.h \
117 inc/qcbor/qcbor_common.h \
118 inc/qcbor/qcbor_main_decode.h \
119 inc/qcbor/qcbor_spiffy_decode.h \
120 src/decode_nesting.h \
121 inc/qcbor/qcbor_tag_decode.h
122
Laurence Lundbladecf49acc2024-12-08 20:48:31 -0700123src/qcbor_number_decode.o: inc/qcbor/UsefulBuf.h \
124 inc/qcbor/qcbor_private.h \
125 inc/qcbor/qcbor_common.h \
126 inc/qcbor/qcbor_main_decode.h \
127 inc/qcbor/qcbor_tag_decode.h \
128 inc/qcbor/qcbor_spiffy_decode.h \
129 inc/qcbor/qcbor_number_decode.h \
130 src/ieee754.h
131
132src/iee754.o: src/ieee754.h \
133 inc/qcbor/qcbor_common.h
134
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700135src/qcbor_err_to_str.o: inc/qcbor/qcbor_common.h
Laurence Lundblade781fd822018-10-01 09:37:52 -0700136
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700137example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade41e96ca2022-04-09 10:37:39 -0600138ub-example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade721b56e2024-10-22 03:02:04 -0700139tag-examples.o: $(PUBLIC_INTERFACE)
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700140
Laurence Lundblade1d85d522020-06-22 13:24:59 -0700141test/run_tests.o: test/UsefulBuf_Tests.h test/float_tests.h test/run_tests.h test/qcbor_encode_tests.h test/qcbor_decode_tests.h inc/qcbor/qcbor_private.h
Michael Eckel9c42c202020-03-04 18:26:11 +0100142test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor/UsefulBuf.h
Michael Eckel7e8effa2020-03-09 18:19:17 +0100143test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE)
Michael Eckel9c42c202020-03-04 18:26:11 +0100144test/qcbor_decode_tests.o: test/qcbor_decode_tests.h $(PUBLIC_INTERFACE)
145test/float_tests.o: test/float_tests.h test/half_to_double_from_rfc7049.h $(PUBLIC_INTERFACE)
146test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
Laurence Lundblade781fd822018-10-01 09:37:52 -0700147
Michael Eckel9c42c202020-03-04 18:26:11 +0100148cmd_line_main.o: test/run_tests.h $(PUBLIC_INTERFACE)
Laurence Lundblade74d265c2018-09-19 10:21:00 -0700149
Laurence Lundbladec2b14572018-11-01 13:07:49 +0700150
Michael Eckel5c531332020-03-02 01:35:30 +0100151ifeq ($(PREFIX),)
152 PREFIX := /usr/local
153endif
154
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700155install: libqcbor.a $(PUBLIC_INTERFACE)
Michael Eckel5c531332020-03-02 01:35:30 +0100156 install -d $(DESTDIR)$(PREFIX)/lib/
157 install -m 644 libqcbor.a $(DESTDIR)$(PREFIX)/lib/
158 install -d $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel7e8effa2020-03-09 18:19:17 +0100159 install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800160 install -m 644 inc/qcbor/qcbor_private.h $(DESTDIR)$(PREFIX)/include/qcbor
161 install -m 644 inc/qcbor/qcbor_common.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade2117bbf2024-12-30 22:56:41 -0500162 install -m 644 inc/qcbor/qcbor_main_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
163 install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
164 install -m 644 inc/qcbor/qcbor_number_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
165 install -m 644 inc/qcbor/qcbor_tag_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
166 install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800167 install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade67257dc2020-07-27 03:33:37 -0700168 install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade2117bbf2024-12-30 22:56:41 -0500169 install -m 644 inc/qcbor/qcbor_main_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
170 install -m 644 inc/qcbor/qcbor_number_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
171 install -m 644 inc/qcbor/qcbor_tag_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800172 install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel5c531332020-03-02 01:35:30 +0100173 install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor
174
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700175install_so: libqcbor.so
176 install -m 755 libqcbor.so $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1.0.0
177 ln -sf libqcbor.so.1 $(DESTDIR)$(PREFIX)/lib/libqcbor.so
178 ln -sf libqcbor.so.1.0.0 $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1
179
Michael Eckel7e8effa2020-03-09 18:19:17 +0100180uninstall: libqcbor.a $(PUBLIC_INTERFACE)
181 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/*
182 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/
183 $(RM) $(addprefix $(DESTDIR)$(PREFIX)/lib/, \
184 libqcbor.a libqcbor.so libqcbor.so.1 libqcbor.so.1.0.0)
185
Laurence Lundblade74d265c2018-09-19 10:21:00 -0700186clean:
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700187 rm -f $(QCBOR_OBJ) $(TEST_OBJ) libqcbor.a cmd_line_main.o libqcbor.a libqcbor.so qcbormin qcbortest