blob: ff12907e5a7abfbf96177d8942909d07c42add33 [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
Michael Eckel9c42c202020-03-04 18:26:11 +010037TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o \
38 test/qcbor_decode_tests.o test/run_tests.o \
Laurence Lundblade721b56e2024-10-22 03:02:04 -070039 test/float_tests.o test/half_to_double_from_rfc7049.o example.o tag-examples.o ub-example.o
Michael Eckel9c42c202020-03-04 18:26:11 +010040
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070041.PHONY: all so install uninstall clean warn
Michael Eckel9c42c202020-03-04 18:26:11 +010042
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070043all: qcbortest libqcbor.a
Laurence Lundblade02990fa2020-03-27 09:51:58 -070044
45so: libqcbor.so
Laurence Lundblade781fd822018-10-01 09:37:52 -070046
Laurence Lundblade2c978832018-12-13 01:10:21 -080047qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o
Norbert KamiƄski6bbc4ed2020-11-27 02:44:04 +010048 $(CC) -o $@ $^ libqcbor.a $(LIBS)
Laurence Lundblade74d265c2018-09-19 10:21:00 -070049
Laurence Lundbladec9d3dcf2018-12-19 18:11:36 -080050libqcbor.a: $(QCBOR_OBJ)
Laurence Lundblade2c978832018-12-13 01:10:21 -080051 ar -r $@ $^
Laurence Lundbladec2b14572018-11-01 13:07:49 +070052
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070053# run "make warn" as a handy way to compile with the warning flags
54# used in the QCBOR release process. See CFLAGS above.
55warn:
Laurence Lundblade5d83b9b2024-06-29 11:19:39 -070056 make CMD_LINE="$(CMD_LINE) -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual"
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070057
Laurence Lundbladeb9702452021-03-08 21:02:57 -080058
Laurence Lundblade02990fa2020-03-27 09:51:58 -070059# The shared library is not made by default because of platform
60# variability For example MacOS and Linux behave differently and some
61# IoT OS's don't support them at all.
Michael Eckel7e8effa2020-03-09 18:19:17 +010062libqcbor.so: $(QCBOR_OBJ)
Laurence Lundblade02990fa2020-03-27 09:51:58 -070063 $(CC) -shared $^ $(CFLAGS) -o $@
Michael Eckel7e8effa2020-03-09 18:19:17 +010064
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080065PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h \
66 inc/qcbor/qcbor_private.h \
67 inc/qcbor/qcbor_common.h \
68 inc/qcbor/qcbor_encode.h \
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070069 inc/qcbor/qcbor_decode.h \
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080070 inc/qcbor/qcbor_main_decode.h \
71 inc/qcbor/qcbor_spiffy_decode.h \
72 inc/qcbor/qcbor_tag_decode.h \
73 inc/qcbor/qcbor_number_decode.h
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080074
Michael Eckel9c42c202020-03-04 18:26:11 +010075src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080076
77src/qcbor_encode.o: inc/qcbor/UsefulBuf.h \
78 inc/qcbor/qcbor_private.h \
79 inc/qcbor/qcbor_common.h \
80 inc/qcbor/qcbor_encode.h \
81 src/ieee754.h
82
83src/qcbor_main_decode.o: inc/qcbor/UsefulBuf.h \
84 inc/qcbor/qcbor_private.h \
85 inc/qcbor/qcbor_common.h \
86 inc/qcbor/qcbor_main_decode.h \
87 inc/qcbor/qcbor_spiffy_decode.h \
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070088 inc/qcbor/qcbor_tag_decode.h \
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080089 src/decode_nesting.h \
90 src/ieee754.h
91
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070092src/qcbor_tag_decode.o: inc/qcbor/UsefulBuf.h \
93 inc/qcbor/qcbor_private.h \
94 inc/qcbor/qcbor_common.h \
95 inc/qcbor/qcbor_main_decode.h \
96 inc/qcbor/qcbor_spiffy_decode.h \
97 src/decode_nesting.h \
98 inc/qcbor/qcbor_tag_decode.h
99
100src/qcbor_number_decode.o: inc/qcbor/UsefulBuf.h \
101 inc/qcbor/qcbor_private.h \
102 inc/qcbor/qcbor_common.h \
103 inc/qcbor/qcbor_main_decode.h \
104 inc/qcbor/qcbor_tag_decode.h \
105 inc/qcbor/qcbor_spiffy_decode.h \
106 inc/qcbor/qcbor_number_decode.h \
107 src/ieee754.h
108
109src/iee754.o: src/ieee754.h \
110 inc/qcbor/qcbor_common.h
111
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700112src/qcbor_err_to_str.o: inc/qcbor/qcbor_common.h
Laurence Lundblade781fd822018-10-01 09:37:52 -0700113
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700114example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade41e96ca2022-04-09 10:37:39 -0600115ub-example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade721b56e2024-10-22 03:02:04 -0700116tag-examples.o: $(PUBLIC_INTERFACE)
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700117
Laurence Lundblade1d85d522020-06-22 13:24:59 -0700118test/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 +0100119test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor/UsefulBuf.h
Michael Eckel7e8effa2020-03-09 18:19:17 +0100120test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE)
Michael Eckel9c42c202020-03-04 18:26:11 +0100121test/qcbor_decode_tests.o: test/qcbor_decode_tests.h $(PUBLIC_INTERFACE)
122test/float_tests.o: test/float_tests.h test/half_to_double_from_rfc7049.h $(PUBLIC_INTERFACE)
123test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
Laurence Lundblade781fd822018-10-01 09:37:52 -0700124
Michael Eckel9c42c202020-03-04 18:26:11 +0100125cmd_line_main.o: test/run_tests.h $(PUBLIC_INTERFACE)
Laurence Lundblade74d265c2018-09-19 10:21:00 -0700126
Laurence Lundbladec2b14572018-11-01 13:07:49 +0700127
Michael Eckel5c531332020-03-02 01:35:30 +0100128ifeq ($(PREFIX),)
129 PREFIX := /usr/local
130endif
131
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700132install: libqcbor.a $(PUBLIC_INTERFACE)
Michael Eckel5c531332020-03-02 01:35:30 +0100133 install -d $(DESTDIR)$(PREFIX)/lib/
134 install -m 644 libqcbor.a $(DESTDIR)$(PREFIX)/lib/
135 install -d $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel7e8effa2020-03-09 18:19:17 +0100136 install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800137 install -m 644 inc/qcbor/qcbor_private.h $(DESTDIR)$(PREFIX)/include/qcbor
138 install -m 644 inc/qcbor/qcbor_common.h $(DESTDIR)$(PREFIX)/include/qcbor
139 install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade67257dc2020-07-27 03:33:37 -0700140 install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800141 install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel5c531332020-03-02 01:35:30 +0100142 install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor
143
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700144install_so: libqcbor.so
145 install -m 755 libqcbor.so $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1.0.0
146 ln -sf libqcbor.so.1 $(DESTDIR)$(PREFIX)/lib/libqcbor.so
147 ln -sf libqcbor.so.1.0.0 $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1
148
Michael Eckel7e8effa2020-03-09 18:19:17 +0100149uninstall: libqcbor.a $(PUBLIC_INTERFACE)
150 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/*
151 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/
152 $(RM) $(addprefix $(DESTDIR)$(PREFIX)/lib/, \
153 libqcbor.a libqcbor.so libqcbor.so.1 libqcbor.so.1.0.0)
154
Laurence Lundblade74d265c2018-09-19 10:21:00 -0700155clean:
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700156 rm -f $(QCBOR_OBJ) $(TEST_OBJ) libqcbor.a cmd_line_main.o libqcbor.a libqcbor.so qcbormin qcbortest