blob: 5e181dd71dfbb8ea785e5cd959f0a0c3785ecebf [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 Lundbladeb9702452021-03-08 21:02:57 -08003# Copyright (c) 2018-2021, 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 Lundblade926ccfc2024-12-05 20:34:55 -080027QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_main_decode.o src/qcbor_spiffy_decode.o src/qcbor_number_decode.o src/qcbor_tag_decode.o src/ieee754.o src/qcbor_err_to_str.o
Laurence Lundblade781fd822018-10-01 09:37:52 -070028
Michael Eckel9c42c202020-03-04 18:26:11 +010029TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o \
30 test/qcbor_decode_tests.o test/run_tests.o \
Laurence Lundblade721b56e2024-10-22 03:02:04 -070031 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 +010032
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070033.PHONY: all so install uninstall clean warn
Michael Eckel9c42c202020-03-04 18:26:11 +010034
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070035all: qcbortest libqcbor.a
Laurence Lundblade02990fa2020-03-27 09:51:58 -070036
37so: libqcbor.so
Laurence Lundblade781fd822018-10-01 09:37:52 -070038
Laurence Lundblade2c978832018-12-13 01:10:21 -080039qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o
Norbert KamiƄski6bbc4ed2020-11-27 02:44:04 +010040 $(CC) -o $@ $^ libqcbor.a $(LIBS)
Laurence Lundblade74d265c2018-09-19 10:21:00 -070041
Laurence Lundbladec9d3dcf2018-12-19 18:11:36 -080042libqcbor.a: $(QCBOR_OBJ)
Laurence Lundblade2c978832018-12-13 01:10:21 -080043 ar -r $@ $^
Laurence Lundbladec2b14572018-11-01 13:07:49 +070044
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070045# run "make warn" as a handy way to compile with the warning flags
46# used in the QCBOR release process. See CFLAGS above.
47warn:
Laurence Lundblade5d83b9b2024-06-29 11:19:39 -070048 make CMD_LINE="$(CMD_LINE) -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual"
Laurence Lundbladeb0e70332022-09-07 11:55:09 -070049
Laurence Lundbladeb9702452021-03-08 21:02:57 -080050
Laurence Lundblade02990fa2020-03-27 09:51:58 -070051# The shared library is not made by default because of platform
52# variability For example MacOS and Linux behave differently and some
53# IoT OS's don't support them at all.
Michael Eckel7e8effa2020-03-09 18:19:17 +010054libqcbor.so: $(QCBOR_OBJ)
Laurence Lundblade02990fa2020-03-27 09:51:58 -070055 $(CC) -shared $^ $(CFLAGS) -o $@
Michael Eckel7e8effa2020-03-09 18:19:17 +010056
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080057PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h \
58 inc/qcbor/qcbor_private.h \
59 inc/qcbor/qcbor_common.h \
60 inc/qcbor/qcbor_encode.h \
61 inc/qcbor/qcbor_main_decode.h \
62 inc/qcbor/qcbor_spiffy_decode.h \
63 inc/qcbor/qcbor_tag_decode.h \
64 inc/qcbor/qcbor_number_decode.h
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080065
Michael Eckel9c42c202020-03-04 18:26:11 +010066src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080067
68src/qcbor_encode.o: inc/qcbor/UsefulBuf.h \
69 inc/qcbor/qcbor_private.h \
70 inc/qcbor/qcbor_common.h \
71 inc/qcbor/qcbor_encode.h \
72 src/ieee754.h
73
74src/qcbor_main_decode.o: inc/qcbor/UsefulBuf.h \
75 inc/qcbor/qcbor_private.h \
76 inc/qcbor/qcbor_common.h \
77 inc/qcbor/qcbor_main_decode.h \
78 inc/qcbor/qcbor_spiffy_decode.h \
79 src/decode_nesting.h \
80 src/ieee754.h
81
Laurence Lundblade33ed26f2024-11-24 10:26:43 -080082src/tag_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_tag_decode.h
83src/number_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_tag_decode.h src/ieee754.h src/decode_private.h
Michael Eckel9c42c202020-03-04 18:26:11 +010084src/iee754.o: src/ieee754.h
Laurence Lundblade02990fa2020-03-27 09:51:58 -070085src/qcbor_err_to_str.o: inc/qcbor/qcbor_common.h
Laurence Lundblade781fd822018-10-01 09:37:52 -070086
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070087example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade41e96ca2022-04-09 10:37:39 -060088ub-example.o: $(PUBLIC_INTERFACE)
Laurence Lundblade721b56e2024-10-22 03:02:04 -070089tag-examples.o: $(PUBLIC_INTERFACE)
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070090
Laurence Lundblade1d85d522020-06-22 13:24:59 -070091test/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 +010092test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor/UsefulBuf.h
Michael Eckel7e8effa2020-03-09 18:19:17 +010093test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE)
Michael Eckel9c42c202020-03-04 18:26:11 +010094test/qcbor_decode_tests.o: test/qcbor_decode_tests.h $(PUBLIC_INTERFACE)
95test/float_tests.o: test/float_tests.h test/half_to_double_from_rfc7049.h $(PUBLIC_INTERFACE)
96test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
Laurence Lundblade781fd822018-10-01 09:37:52 -070097
Michael Eckel9c42c202020-03-04 18:26:11 +010098cmd_line_main.o: test/run_tests.h $(PUBLIC_INTERFACE)
Laurence Lundblade74d265c2018-09-19 10:21:00 -070099
Laurence Lundbladec2b14572018-11-01 13:07:49 +0700100
Michael Eckel5c531332020-03-02 01:35:30 +0100101ifeq ($(PREFIX),)
102 PREFIX := /usr/local
103endif
104
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700105install: libqcbor.a $(PUBLIC_INTERFACE)
Michael Eckel5c531332020-03-02 01:35:30 +0100106 install -d $(DESTDIR)$(PREFIX)/lib/
107 install -m 644 libqcbor.a $(DESTDIR)$(PREFIX)/lib/
108 install -d $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel7e8effa2020-03-09 18:19:17 +0100109 install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800110 install -m 644 inc/qcbor/qcbor_private.h $(DESTDIR)$(PREFIX)/include/qcbor
111 install -m 644 inc/qcbor/qcbor_common.h $(DESTDIR)$(PREFIX)/include/qcbor
112 install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade67257dc2020-07-27 03:33:37 -0700113 install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -0800114 install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel5c531332020-03-02 01:35:30 +0100115 install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor
116
Laurence Lundblade02990fa2020-03-27 09:51:58 -0700117install_so: libqcbor.so
118 install -m 755 libqcbor.so $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1.0.0
119 ln -sf libqcbor.so.1 $(DESTDIR)$(PREFIX)/lib/libqcbor.so
120 ln -sf libqcbor.so.1.0.0 $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1
121
Michael Eckel7e8effa2020-03-09 18:19:17 +0100122uninstall: libqcbor.a $(PUBLIC_INTERFACE)
123 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/*
124 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/
125 $(RM) $(addprefix $(DESTDIR)$(PREFIX)/lib/, \
126 libqcbor.a libqcbor.so libqcbor.so.1 libqcbor.so.1.0.0)
127
Laurence Lundblade74d265c2018-09-19 10:21:00 -0700128clean:
Laurence Lundbladecb31ed32020-07-26 04:18:37 -0700129 rm -f $(QCBOR_OBJ) $(TEST_OBJ) libqcbor.a cmd_line_main.o libqcbor.a libqcbor.so qcbormin qcbortest