Laurence Lundblade | 01168ef | 2019-01-21 17:05:47 -0800 | [diff] [blame] | 1 | # Makefile -- UNIX-style make for qcbor as a lib and command line test |
Laurence Lundblade | df1c1cf | 2019-01-17 11:55:05 -0800 | [diff] [blame] | 2 | # |
Laurence Lundblade | d687d32 | 2025-07-21 23:39:27 +0200 | [diff] [blame] | 3 | # Copyright (c) 2018-2025, Laurence Lundblade. All rights reserved. |
Laurence Lundblade | df1c1cf | 2019-01-17 11:55:05 -0800 | [diff] [blame] | 4 | # |
Laurence Lundblade | 01168ef | 2019-01-21 17:05:47 -0800 | [diff] [blame] | 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | # See BSD-3-Clause license in README.md |
| 8 | # |
| 9 | |
Laurence Lundblade | 844bb5c | 2020-03-01 17:27:25 -0800 | [diff] [blame] | 10 | |
Laurence Lundblade | b970245 | 2021-03-08 21:02:57 -0800 | [diff] [blame] | 11 | # The math library is needed for floating-point support. To |
| 12 | # avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE |
akil | 53a6981 | 2020-11-25 05:24:10 +0400 | [diff] [blame] | 13 | LIBS=-lm |
Laurence Lundblade | f19f4da | 2020-03-01 17:41:53 -0800 | [diff] [blame] | 14 | |
Laurence Lundblade | b970245 | 2021-03-08 21:02:57 -0800 | [diff] [blame] | 15 | |
| 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 Lundblade | c5a342f | 2021-05-17 01:17:06 -0700 | [diff] [blame] | 18 | # 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 Lundblade | b970245 | 2021-03-08 21:02:57 -0800 | [diff] [blame] | 20 | # used on the stringent build script that is in |
| 21 | # https://github.com/laurencelundblade/qdv. This script is used |
Laurence Lundblade | b0e7033 | 2022-09-07 11:55:09 -0700 | [diff] [blame] | 22 | # before pushes to master (though not yet through an automated build |
| 23 | # process). See "warn:" below. |
Laurence Lundblade | b970245 | 2021-03-08 21:02:57 -0800 | [diff] [blame] | 24 | CFLAGS=$(CMD_LINE) -I inc -I test -Os -fPIC |
Laurence Lundblade | 74d265c | 2018-09-19 10:21:00 -0700 | [diff] [blame] | 25 | |
Laurence Lundblade | 844bb5c | 2020-03-01 17:27:25 -0800 | [diff] [blame] | 26 | |
Laurence Lundblade | 7596eef | 2024-12-21 10:08:32 -0700 | [diff] [blame] | 27 | QCBOR_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 Lundblade | 781fd82 | 2018-10-01 09:37:52 -0700 | [diff] [blame] | 36 | |
Laurence Lundblade | 2117bbf | 2024-12-30 22:56:41 -0500 | [diff] [blame] | 37 | TEST_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 Eckel | 9c42c20 | 2020-03-04 18:26:11 +0100 | [diff] [blame] | 46 | |
Laurence Lundblade | d687d32 | 2025-07-21 23:39:27 +0200 | [diff] [blame] | 47 | COV_FILES=test/*.gcno src/*.gcno test/*.gcda src/*.gcda *.gcno *.gcda *.gcov |
| 48 | |
Laurence Lundblade | b0e7033 | 2022-09-07 11:55:09 -0700 | [diff] [blame] | 49 | .PHONY: all so install uninstall clean warn |
Michael Eckel | 9c42c20 | 2020-03-04 18:26:11 +0100 | [diff] [blame] | 50 | |
Laurence Lundblade | cb31ed3 | 2020-07-26 04:18:37 -0700 | [diff] [blame] | 51 | all: qcbortest libqcbor.a |
Laurence Lundblade | 02990fa | 2020-03-27 09:51:58 -0700 | [diff] [blame] | 52 | |
| 53 | so: libqcbor.so |
Laurence Lundblade | 781fd82 | 2018-10-01 09:37:52 -0700 | [diff] [blame] | 54 | |
Laurence Lundblade | 2c97883 | 2018-12-13 01:10:21 -0800 | [diff] [blame] | 55 | qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o |
Norbert KamiĆski | 6bbc4ed | 2020-11-27 02:44:04 +0100 | [diff] [blame] | 56 | $(CC) -o $@ $^ libqcbor.a $(LIBS) |
Laurence Lundblade | 74d265c | 2018-09-19 10:21:00 -0700 | [diff] [blame] | 57 | |
Laurence Lundblade | d687d32 | 2025-07-21 23:39:27 +0200 | [diff] [blame] | 58 | qcborcov: $(QCBOR_OBJ) $(TEST_OBJ) cmd_line_main.o |
| 59 | $(CC) -fprofile-arcs -ftest-coverage -o $@ $^ $(LIBS) |
| 60 | |
Laurence Lundblade | c9d3dcf | 2018-12-19 18:11:36 -0800 | [diff] [blame] | 61 | libqcbor.a: $(QCBOR_OBJ) |
Laurence Lundblade | 2c97883 | 2018-12-13 01:10:21 -0800 | [diff] [blame] | 62 | ar -r $@ $^ |
Laurence Lundblade | c2b1457 | 2018-11-01 13:07:49 +0700 | [diff] [blame] | 63 | |
Laurence Lundblade | b0e7033 | 2022-09-07 11:55:09 -0700 | [diff] [blame] | 64 | # run "make warn" as a handy way to compile with the warning flags |
| 65 | # used in the QCBOR release process. See CFLAGS above. |
| 66 | warn: |
Laurence Lundblade | 5d83b9b | 2024-06-29 11:19:39 -0700 | [diff] [blame] | 67 | make CMD_LINE="$(CMD_LINE) -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual" |
Laurence Lundblade | b0e7033 | 2022-09-07 11:55:09 -0700 | [diff] [blame] | 68 | |
Laurence Lundblade | d687d32 | 2025-07-21 23:39:27 +0200 | [diff] [blame] | 69 | # run "make coverage" to build for gcov test coverage tool |
| 70 | coverage: |
| 71 | make CMD_LINE="$(CMD_LINE) -fprofile-arcs -ftest-coverage" qcborcov |
| 72 | |
Laurence Lundblade | b970245 | 2021-03-08 21:02:57 -0800 | [diff] [blame] | 73 | |
Laurence Lundblade | 02990fa | 2020-03-27 09:51:58 -0700 | [diff] [blame] | 74 | # The shared library is not made by default because of platform |
| 75 | # variability For example MacOS and Linux behave differently and some |
| 76 | # IoT OS's don't support them at all. |
Michael Eckel | 7e8effa | 2020-03-09 18:19:17 +0100 | [diff] [blame] | 77 | libqcbor.so: $(QCBOR_OBJ) |
Laurence Lundblade | 02990fa | 2020-03-27 09:51:58 -0700 | [diff] [blame] | 78 | $(CC) -shared $^ $(CFLAGS) -o $@ |
Michael Eckel | 7e8effa | 2020-03-09 18:19:17 +0100 | [diff] [blame] | 79 | |
Laurence Lundblade | 926ccfc | 2024-12-05 20:34:55 -0800 | [diff] [blame] | 80 | PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h \ |
| 81 | inc/qcbor/qcbor_private.h \ |
| 82 | inc/qcbor/qcbor_common.h \ |
Laurence Lundblade | 2117bbf | 2024-12-30 22:56:41 -0500 | [diff] [blame] | 83 | inc/qcbor/qcbor_main_encode.h \ |
| 84 | inc/qcbor/qcbor_number_encode.h \ |
| 85 | inc/qcbor/qcbor_tag_encode.h \ |
Laurence Lundblade | cf49acc | 2024-12-08 20:48:31 -0700 | [diff] [blame] | 86 | inc/qcbor/qcbor_decode.h \ |
Laurence Lundblade | 926ccfc | 2024-12-05 20:34:55 -0800 | [diff] [blame] | 87 | inc/qcbor/qcbor_main_decode.h \ |
| 88 | inc/qcbor/qcbor_spiffy_decode.h \ |
| 89 | inc/qcbor/qcbor_tag_decode.h \ |
| 90 | inc/qcbor/qcbor_number_decode.h |
Laurence Lundblade | 844bb5c | 2020-03-01 17:27:25 -0800 | [diff] [blame] | 91 | |
Michael Eckel | 9c42c20 | 2020-03-04 18:26:11 +0100 | [diff] [blame] | 92 | src/UsefulBuf.o: inc/qcbor/UsefulBuf.h |
Laurence Lundblade | 926ccfc | 2024-12-05 20:34:55 -0800 | [diff] [blame] | 93 | |
Laurence Lundblade | 2117bbf | 2024-12-30 22:56:41 -0500 | [diff] [blame] | 94 | src/qcbor_main_encode.o: inc/qcbor/UsefulBuf.h \ |
| 95 | inc/qcbor/qcbor_private.h \ |
| 96 | inc/qcbor/qcbor_common.h \ |
| 97 | inc/qcbor/qcbor_main_encode.h |
| 98 | |
| 99 | src/qcbor_tag_encode.o: inc/qcbor/UsefulBuf.h \ |
| 100 | inc/qcbor/qcbor_private.h \ |
| 101 | inc/qcbor/qcbor_common.h \ |
| 102 | inc/qcbor/qcbor_main_encode.h \ |
| 103 | inc/qcbor/qcbor_number_encode.h \ |
| 104 | inc/qcbor/qcbor_tag_encode.h \ |
| 105 | src/ieee754.h |
Laurence Lundblade | 926ccfc | 2024-12-05 20:34:55 -0800 | [diff] [blame] | 106 | |
| 107 | src/qcbor_main_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 \ |
Laurence Lundblade | cf49acc | 2024-12-08 20:48:31 -0700 | [diff] [blame] | 112 | inc/qcbor/qcbor_tag_decode.h \ |
Laurence Lundblade | 926ccfc | 2024-12-05 20:34:55 -0800 | [diff] [blame] | 113 | src/decode_nesting.h \ |
| 114 | src/ieee754.h |
| 115 | |
Laurence Lundblade | cf49acc | 2024-12-08 20:48:31 -0700 | [diff] [blame] | 116 | src/qcbor_tag_decode.o: inc/qcbor/UsefulBuf.h \ |
| 117 | inc/qcbor/qcbor_private.h \ |
| 118 | inc/qcbor/qcbor_common.h \ |
| 119 | inc/qcbor/qcbor_main_decode.h \ |
| 120 | inc/qcbor/qcbor_spiffy_decode.h \ |
| 121 | src/decode_nesting.h \ |
| 122 | inc/qcbor/qcbor_tag_decode.h |
| 123 | |
Laurence Lundblade | 2117bbf | 2024-12-30 22:56:41 -0500 | [diff] [blame] | 124 | src/qcbor_spiffy_decode.o: inc/qcbor/UsefulBuf.h \ |
| 125 | inc/qcbor/qcbor_private.h \ |
| 126 | inc/qcbor/qcbor_common.h \ |
| 127 | inc/qcbor/qcbor_main_decode.h \ |
| 128 | inc/qcbor/qcbor_spiffy_decode.h \ |
| 129 | src/decode_nesting.h \ |
| 130 | inc/qcbor/qcbor_tag_decode.h |
| 131 | |
Laurence Lundblade | cf49acc | 2024-12-08 20:48:31 -0700 | [diff] [blame] | 132 | src/qcbor_number_decode.o: inc/qcbor/UsefulBuf.h \ |
| 133 | inc/qcbor/qcbor_private.h \ |
| 134 | inc/qcbor/qcbor_common.h \ |
| 135 | inc/qcbor/qcbor_main_decode.h \ |
| 136 | inc/qcbor/qcbor_tag_decode.h \ |
| 137 | inc/qcbor/qcbor_spiffy_decode.h \ |
| 138 | inc/qcbor/qcbor_number_decode.h \ |
| 139 | src/ieee754.h |
| 140 | |
| 141 | src/iee754.o: src/ieee754.h \ |
| 142 | inc/qcbor/qcbor_common.h |
| 143 | |
Laurence Lundblade | 02990fa | 2020-03-27 09:51:58 -0700 | [diff] [blame] | 144 | src/qcbor_err_to_str.o: inc/qcbor/qcbor_common.h |
Laurence Lundblade | 781fd82 | 2018-10-01 09:37:52 -0700 | [diff] [blame] | 145 | |
Laurence Lundblade | cb31ed3 | 2020-07-26 04:18:37 -0700 | [diff] [blame] | 146 | example.o: $(PUBLIC_INTERFACE) |
Laurence Lundblade | 41e96ca | 2022-04-09 10:37:39 -0600 | [diff] [blame] | 147 | ub-example.o: $(PUBLIC_INTERFACE) |
Laurence Lundblade | 721b56e | 2024-10-22 03:02:04 -0700 | [diff] [blame] | 148 | tag-examples.o: $(PUBLIC_INTERFACE) |
Laurence Lundblade | cb31ed3 | 2020-07-26 04:18:37 -0700 | [diff] [blame] | 149 | |
Laurence Lundblade | 1d85d52 | 2020-06-22 13:24:59 -0700 | [diff] [blame] | 150 | test/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 Eckel | 9c42c20 | 2020-03-04 18:26:11 +0100 | [diff] [blame] | 151 | test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor/UsefulBuf.h |
Michael Eckel | 7e8effa | 2020-03-09 18:19:17 +0100 | [diff] [blame] | 152 | test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE) |
Michael Eckel | 9c42c20 | 2020-03-04 18:26:11 +0100 | [diff] [blame] | 153 | test/qcbor_decode_tests.o: test/qcbor_decode_tests.h $(PUBLIC_INTERFACE) |
| 154 | test/float_tests.o: test/float_tests.h test/half_to_double_from_rfc7049.h $(PUBLIC_INTERFACE) |
| 155 | test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h |
Laurence Lundblade | 781fd82 | 2018-10-01 09:37:52 -0700 | [diff] [blame] | 156 | |
Michael Eckel | 9c42c20 | 2020-03-04 18:26:11 +0100 | [diff] [blame] | 157 | cmd_line_main.o: test/run_tests.h $(PUBLIC_INTERFACE) |
Laurence Lundblade | 74d265c | 2018-09-19 10:21:00 -0700 | [diff] [blame] | 158 | |
Laurence Lundblade | c2b1457 | 2018-11-01 13:07:49 +0700 | [diff] [blame] | 159 | |
Michael Eckel | 5c53133 | 2020-03-02 01:35:30 +0100 | [diff] [blame] | 160 | ifeq ($(PREFIX),) |
| 161 | PREFIX := /usr/local |
| 162 | endif |
| 163 | |
Laurence Lundblade | 02990fa | 2020-03-27 09:51:58 -0700 | [diff] [blame] | 164 | install: libqcbor.a $(PUBLIC_INTERFACE) |
Michael Eckel | 5c53133 | 2020-03-02 01:35:30 +0100 | [diff] [blame] | 165 | install -d $(DESTDIR)$(PREFIX)/lib/ |
| 166 | install -m 644 libqcbor.a $(DESTDIR)$(PREFIX)/lib/ |
| 167 | install -d $(DESTDIR)$(PREFIX)/include/qcbor |
Michael Eckel | 7e8effa | 2020-03-09 18:19:17 +0100 | [diff] [blame] | 168 | install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor |
Laurence Lundblade | 844bb5c | 2020-03-01 17:27:25 -0800 | [diff] [blame] | 169 | install -m 644 inc/qcbor/qcbor_private.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 170 | install -m 644 inc/qcbor/qcbor_common.h $(DESTDIR)$(PREFIX)/include/qcbor |
Laurence Lundblade | 2117bbf | 2024-12-30 22:56:41 -0500 | [diff] [blame] | 171 | install -m 644 inc/qcbor/qcbor_main_decode.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 172 | install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 173 | install -m 644 inc/qcbor/qcbor_number_decode.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 174 | install -m 644 inc/qcbor/qcbor_tag_decode.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 175 | install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor |
Laurence Lundblade | 844bb5c | 2020-03-01 17:27:25 -0800 | [diff] [blame] | 176 | install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor |
Laurence Lundblade | 67257dc | 2020-07-27 03:33:37 -0700 | [diff] [blame] | 177 | install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor |
Laurence Lundblade | 2117bbf | 2024-12-30 22:56:41 -0500 | [diff] [blame] | 178 | install -m 644 inc/qcbor/qcbor_main_encode.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 179 | install -m 644 inc/qcbor/qcbor_number_encode.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 180 | install -m 644 inc/qcbor/qcbor_tag_encode.h $(DESTDIR)$(PREFIX)/include/qcbor |
Laurence Lundblade | 844bb5c | 2020-03-01 17:27:25 -0800 | [diff] [blame] | 181 | install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor |
Michael Eckel | 5c53133 | 2020-03-02 01:35:30 +0100 | [diff] [blame] | 182 | install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor |
| 183 | |
Laurence Lundblade | 02990fa | 2020-03-27 09:51:58 -0700 | [diff] [blame] | 184 | install_so: libqcbor.so |
| 185 | install -m 755 libqcbor.so $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1.0.0 |
| 186 | ln -sf libqcbor.so.1 $(DESTDIR)$(PREFIX)/lib/libqcbor.so |
| 187 | ln -sf libqcbor.so.1.0.0 $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1 |
| 188 | |
Michael Eckel | 7e8effa | 2020-03-09 18:19:17 +0100 | [diff] [blame] | 189 | uninstall: libqcbor.a $(PUBLIC_INTERFACE) |
| 190 | $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/* |
| 191 | $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/ |
| 192 | $(RM) $(addprefix $(DESTDIR)$(PREFIX)/lib/, \ |
| 193 | libqcbor.a libqcbor.so libqcbor.so.1 libqcbor.so.1.0.0) |
| 194 | |
Laurence Lundblade | 74d265c | 2018-09-19 10:21:00 -0700 | [diff] [blame] | 195 | clean: |
Laurence Lundblade | d687d32 | 2025-07-21 23:39:27 +0200 | [diff] [blame] | 196 | rm -f $(QCBOR_OBJ) $(TEST_OBJ) $(COV_FILES) libqcbor.a cmd_line_main.o libqcbor.a libqcbor.so qcbormin qcbortest |