blob: 81e178a7a77ff9f786a26fbadbe6809d0aa1090d [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 Lundbladed687d322025-07-21 23:39:27 +02003# Copyright (c) 2018-2025, 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 Lundbladed687d322025-07-21 23:39:27 +020047COV_FILES=test/*.gcno src/*.gcno test/*.gcda src/*.gcda *.gcno *.gcda *.gcov
48
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070049.PHONY: all so install uninstall clean warn
Michael Eckel9c42c202020-03-04 18:26:11 +010050
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070051all: qcbortest libqcbor.a
Laurence Lundblade02990fa2020-03-27 09:51:58 -070052
53so: libqcbor.so
Laurence Lundblade781fd822018-10-01 09:37:52 -070054
Laurence Lundblade2c978832018-12-13 01:10:21 -080055qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o
Norbert KamiƄski6bbc4ed2020-11-27 02:44:04 +010056 $(CC) -o $@ $^ libqcbor.a $(LIBS)
Laurence Lundblade74d265c2018-09-19 10:21:00 -070057
Laurence Lundbladed687d322025-07-21 23:39:27 +020058qcborcov: $(QCBOR_OBJ) $(TEST_OBJ) cmd_line_main.o
59 $(CC) -fprofile-arcs -ftest-coverage -o $@ $^ $(LIBS)
60
Laurence Lundbladec9d3dcf2018-12-19 18:11:36 -080061libqcbor.a: $(QCBOR_OBJ)
Laurence Lundblade2c978832018-12-13 01:10:21 -080062 ar -r $@ $^
Laurence Lundbladec2b14572018-11-01 13:07:49 +070063
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070064# run "make warn" as a handy way to compile with the warning flags
65# used in the QCBOR release process. See CFLAGS above.
66warn:
Laurence Lundblade5d83b9b2024-06-29 11:19:39 -070067 make CMD_LINE="$(CMD_LINE) -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual"
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070068
Laurence Lundbladed687d322025-07-21 23:39:27 +020069# run "make coverage" to build for gcov test coverage tool
70coverage:
71 make CMD_LINE="$(CMD_LINE) -fprofile-arcs -ftest-coverage" qcborcov
72
Laurence Lundbladeb9702452021-03-08 21:02:57 -080073
Laurence Lundblade02990fa2020-03-27 09:51:58 -070074# 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 Eckel7e8effa2020-03-09 18:19:17 +010077libqcbor.so: $(QCBOR_OBJ)
Laurence Lundblade02990fa2020-03-27 09:51:58 -070078 $(CC) -shared $^ $(CFLAGS) -o $@
Michael Eckel7e8effa2020-03-09 18:19:17 +010079
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080080PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h \
81 inc/qcbor/qcbor_private.h \
82 inc/qcbor/qcbor_common.h \
Laurence Lundblade2117bbf2024-12-30 22:56:41 -050083 inc/qcbor/qcbor_main_encode.h \
84 inc/qcbor/qcbor_number_encode.h \
85 inc/qcbor/qcbor_tag_encode.h \
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070086 inc/qcbor/qcbor_decode.h \
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080087 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 Lundblade844bb5c2020-03-01 17:27:25 -080091
Michael Eckel9c42c202020-03-04 18:26:11 +010092src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080093
Laurence Lundblade2117bbf2024-12-30 22:56:41 -050094src/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
99src/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 Lundblade926ccfc2024-12-05 20:34:55 -0800106
107src/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 Lundbladecf49acc2024-12-08 20:48:31 -0700112 inc/qcbor/qcbor_tag_decode.h \
Laurence Lundblade926ccfc2024-12-05 20:34:55 -0800113 src/decode_nesting.h \
114 src/ieee754.h
115
Laurence Lundbladecf49acc2024-12-08 20:48:31 -0700116src/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 Lundblade2117bbf2024-12-30 22:56:41 -0500124src/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 Lundbladecf49acc2024-12-08 20:48:31 -0700132src/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
141src/iee754.o: src/ieee754.h \
142 inc/qcbor/qcbor_common.h
143
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700144src/qcbor_err_to_str.o: inc/qcbor/qcbor_common.h
Laurence Lundblade781fd822018-10-01 09:37:52 -0700145
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700146example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade41e96ca2022-04-09 10:37:39 -0600147ub-example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade721b56e2024-10-22 03:02:04 -0700148tag-examples.o: $(PUBLIC_INTERFACE)
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700149
Laurence Lundblade1d85d522020-06-22 13:24:59 -0700150test/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 +0100151test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor/UsefulBuf.h
Michael Eckel7e8effa2020-03-09 18:19:17 +0100152test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE)
Michael Eckel9c42c202020-03-04 18:26:11 +0100153test/qcbor_decode_tests.o: test/qcbor_decode_tests.h $(PUBLIC_INTERFACE)
154test/float_tests.o: test/float_tests.h test/half_to_double_from_rfc7049.h $(PUBLIC_INTERFACE)
155test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
Laurence Lundblade781fd822018-10-01 09:37:52 -0700156
Michael Eckel9c42c202020-03-04 18:26:11 +0100157cmd_line_main.o: test/run_tests.h $(PUBLIC_INTERFACE)
Laurence Lundblade74d265c2018-09-19 10:21:00 -0700158
Laurence Lundbladec2b14572018-11-01 13:07:49 +0700159
Michael Eckel5c531332020-03-02 01:35:30 +0100160ifeq ($(PREFIX),)
161 PREFIX := /usr/local
162endif
163
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700164install: libqcbor.a $(PUBLIC_INTERFACE)
Michael Eckel5c531332020-03-02 01:35:30 +0100165 install -d $(DESTDIR)$(PREFIX)/lib/
166 install -m 644 libqcbor.a $(DESTDIR)$(PREFIX)/lib/
167 install -d $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel7e8effa2020-03-09 18:19:17 +0100168 install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800169 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 Lundblade2117bbf2024-12-30 22:56:41 -0500171 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 Lundblade844bb5c2020-03-01 17:27:25 -0800176 install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade67257dc2020-07-27 03:33:37 -0700177 install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade2117bbf2024-12-30 22:56:41 -0500178 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 Lundblade844bb5c2020-03-01 17:27:25 -0800181 install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel5c531332020-03-02 01:35:30 +0100182 install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor
183
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700184install_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 Eckel7e8effa2020-03-09 18:19:17 +0100189uninstall: 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 Lundblade74d265c2018-09-19 10:21:00 -0700195clean:
Laurence Lundbladed687d322025-07-21 23:39:27 +0200196 rm -f $(QCBOR_OBJ) $(TEST_OBJ) $(COV_FILES) libqcbor.a cmd_line_main.o libqcbor.a libqcbor.so qcbormin qcbortest