blob: b6649931610d08b34e8f116cbf7b4f26ee920348 [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 Lundblade06350ea2020-01-27 19:32:40 -08003# Copyright (c) 2018-2020, 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 -080010CC=cc
Laurence Lundblade02990fa2020-03-27 09:51:58 -070011#CC=/usr/local/bin/gcc-9
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080012
akil53a69812020-11-25 05:24:10 +040013LIBS=-lm
Laurence Lundblade46360ec2020-10-21 13:18:33 -070014CFLAGS=$(CMD_LINE) -I inc -I test -Os -fPIC
Laurence Lundbladef19f4da2020-03-01 17:41:53 -080015
Laurence Lundblade02990fa2020-03-27 09:51:58 -070016# The following are used before a release of QCBOR help to make sure
17# the code compiles and runs in the most strict environments, but not
18# all compilers support them so they are not turned on.
Laurence Lundbladee6bcef12020-04-01 10:56:27 -070019#CFLAGS=-I inc -I test -Os -fpic -Wall -pedantic-errors -Wextra -Wshadow -Wparentheses -Wconversion -xc -std=c99
Laurence Lundblade74d265c2018-09-19 10:21:00 -070020
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080021
Michael Eckel6e030772020-03-27 02:20:00 +010022QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_decode.o src/ieee754.o src/qcbor_err_to_str.o
Laurence Lundblade781fd822018-10-01 09:37:52 -070023
Michael Eckel9c42c202020-03-04 18:26:11 +010024TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o \
25 test/qcbor_decode_tests.o test/run_tests.o \
Laurence Lundblade1818e632020-07-26 04:14:08 -070026 test/float_tests.o test/half_to_double_from_rfc7049.o example.o
Michael Eckel9c42c202020-03-04 18:26:11 +010027
Laurence Lundblade02990fa2020-03-27 09:51:58 -070028.PHONY: all so install uninstall clean
Michael Eckel9c42c202020-03-04 18:26:11 +010029
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070030all: qcbortest libqcbor.a
Laurence Lundblade02990fa2020-03-27 09:51:58 -070031
32so: libqcbor.so
Laurence Lundblade781fd822018-10-01 09:37:52 -070033
Laurence Lundblade2c978832018-12-13 01:10:21 -080034qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o
akil53a69812020-11-25 05:24:10 +040035 $(CC) -o $@ $(LIBS) $^ libqcbor.a
Laurence Lundblade74d265c2018-09-19 10:21:00 -070036
Laurence Lundbladec9d3dcf2018-12-19 18:11:36 -080037libqcbor.a: $(QCBOR_OBJ)
Laurence Lundblade2c978832018-12-13 01:10:21 -080038 ar -r $@ $^
Laurence Lundbladec2b14572018-11-01 13:07:49 +070039
Laurence Lundblade02990fa2020-03-27 09:51:58 -070040# The shared library is not made by default because of platform
41# variability For example MacOS and Linux behave differently and some
42# IoT OS's don't support them at all.
Michael Eckel7e8effa2020-03-09 18:19:17 +010043libqcbor.so: $(QCBOR_OBJ)
Laurence Lundblade02990fa2020-03-27 09:51:58 -070044 $(CC) -shared $^ $(CFLAGS) -o $@
Michael Eckel7e8effa2020-03-09 18:19:17 +010045
Laurence Lundblade67257dc2020-07-27 03:33:37 -070046PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_encode.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_spiffy_decode.h
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080047
Michael Eckel9c42c202020-03-04 18:26:11 +010048src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
Laurence Lundblade67257dc2020-07-27 03:33:37 -070049src/qcbor_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_spiffy_decode.h src/ieee754.h
50src/qcbor_encode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_encode.h src/ieee754.h
Michael Eckel9c42c202020-03-04 18:26:11 +010051src/iee754.o: src/ieee754.h
Laurence Lundblade02990fa2020-03-27 09:51:58 -070052src/qcbor_err_to_str.o: inc/qcbor/qcbor_common.h
Laurence Lundblade781fd822018-10-01 09:37:52 -070053
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070054example.o: $(PUBLIC_INTERFACE)
55
Laurence Lundblade1d85d522020-06-22 13:24:59 -070056test/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 +010057test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor/UsefulBuf.h
Michael Eckel7e8effa2020-03-09 18:19:17 +010058test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE)
Michael Eckel9c42c202020-03-04 18:26:11 +010059test/qcbor_decode_tests.o: test/qcbor_decode_tests.h $(PUBLIC_INTERFACE)
60test/float_tests.o: test/float_tests.h test/half_to_double_from_rfc7049.h $(PUBLIC_INTERFACE)
61test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
Laurence Lundblade781fd822018-10-01 09:37:52 -070062
Michael Eckel9c42c202020-03-04 18:26:11 +010063cmd_line_main.o: test/run_tests.h $(PUBLIC_INTERFACE)
Laurence Lundblade74d265c2018-09-19 10:21:00 -070064
Laurence Lundbladec2b14572018-11-01 13:07:49 +070065
Michael Eckel5c531332020-03-02 01:35:30 +010066ifeq ($(PREFIX),)
67 PREFIX := /usr/local
68endif
69
Laurence Lundblade02990fa2020-03-27 09:51:58 -070070install: libqcbor.a $(PUBLIC_INTERFACE)
Michael Eckel5c531332020-03-02 01:35:30 +010071 install -d $(DESTDIR)$(PREFIX)/lib/
72 install -m 644 libqcbor.a $(DESTDIR)$(PREFIX)/lib/
73 install -d $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel7e8effa2020-03-09 18:19:17 +010074 install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080075 install -m 644 inc/qcbor/qcbor_private.h $(DESTDIR)$(PREFIX)/include/qcbor
76 install -m 644 inc/qcbor/qcbor_common.h $(DESTDIR)$(PREFIX)/include/qcbor
77 install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade67257dc2020-07-27 03:33:37 -070078 install -m 644 inc/qcbor/qcbor_spiffy_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
Laurence Lundblade844bb5c2020-03-01 17:27:25 -080079 install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
Michael Eckel5c531332020-03-02 01:35:30 +010080 install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor
81
Laurence Lundblade02990fa2020-03-27 09:51:58 -070082install_so: libqcbor.so
83 install -m 755 libqcbor.so $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1.0.0
84 ln -sf libqcbor.so.1 $(DESTDIR)$(PREFIX)/lib/libqcbor.so
85 ln -sf libqcbor.so.1.0.0 $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1
86
Michael Eckel7e8effa2020-03-09 18:19:17 +010087uninstall: libqcbor.a $(PUBLIC_INTERFACE)
88 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/*
89 $(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/
90 $(RM) $(addprefix $(DESTDIR)$(PREFIX)/lib/, \
91 libqcbor.a libqcbor.so libqcbor.so.1 libqcbor.so.1.0.0)
92
Laurence Lundblade74d265c2018-09-19 10:21:00 -070093clean:
Laurence Lundbladecb31ed32020-07-26 04:18:37 -070094 rm -f $(QCBOR_OBJ) $(TEST_OBJ) libqcbor.a cmd_line_main.o libqcbor.a libqcbor.so qcbormin qcbortest