3 exec_prefix = $(prefix)
4 bindir = $(exec_prefix)/bin
5 libdir = $(exec_prefix)/lib
6 includedir = $(prefix)/include
7 pkgconfigdir = $(libdir)/pkgconfig
10 LDFLAGS_GCSECTIONS = -Wl,--gc-sections
11 LDFLAGS = $(if $(gc_sections-pass),$(LDFLAGS_GCSECTIONS))
13 GIT_ARCHIVE = git archive --prefix="$(PACKAGE)/" -9
15 INSTALL_DATA = $(INSTALL) -m 644
16 INSTALL_PROGRAM = $(INSTALL) -m 755
23 TINYCBOR_HEADERS = src/cbor.h src/cborjson.h
25 src/cborerrorstrings.c \
27 src/cborencoder_close_container_checked.c \
29 src/cborparser_dup_string.c \
33 CBORDUMP_SOURCES = tools/cbordump/cbordump.c
35 INSTALL_TARGETS += $(bindir)/cbordump
36 INSTALL_TARGETS += $(libdir)/libtinycbor.a
37 INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
38 INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)
41 MAKEFILE := $(lastword $(MAKEFILE_LIST))
42 SRCDIR := $(dir $(MAKEFILE))
43 VPATH = $(SRCDIR):$(SRCDIR)/src
46 GIT_DIR := $(strip $(shell git -C $(SRCDIR). rev-parse --git-dir 2> /dev/null))
48 VERSION = $(shell cat $(SRCDIR)VERSION)
51 VERSION := $(shell git -C $(SRCDIR). describe --tags | cut -c2-)
53 test -n "`git -C $(SRCDIR). diff --name-only HEAD`" && \
56 PACKAGE = tinycbor-$(VERSION)
58 # Check that QMAKE is Qt 5
59 ifeq ($(origin QMAKE),file)
60 check_qmake = $(strip $(shell $(1) -query QT_VERSION 2>/dev/null | cut -b1))
61 ifneq ($(call check_qmake,$(QMAKE)),5)
63 ifneq ($(call check_qmake,$(QMAKE)),5)
65 ifneq ($(call check_qmake,$(QMAKE)),5)
66 QMAKE := @echo >&2 $(MAKEFILE): Cannot find a Qt 5 qmake; false
74 # if open_memstream is unavailable on the system, try to implement our own
75 # version using funopen or fopencookie
76 ifeq ($(open_memstream-pass),)
77 ifeq ($(funopen-pass)$(fopencookie-pass),)
78 CFLAGS += -DWITHOUT_OPEN_MEMSTREAM
79 $(warning warning: funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!)
81 TINYCBOR_SOURCES += src/open_memstream.c
85 # json2cbor depends on an external library (cJSON)
86 ifneq ($(cjson-pass)$(system-cjson-pass),)
87 JSON2CBOR_SOURCES = tools/json2cbor/json2cbor.c
88 INSTALL_TARGETS += $(bindir)/json2cbor
89 ifeq ($(system-cjson-pass),1)
90 LDFLAGS_CJSON = -lcJSON
92 JSON2CBOR_SOURCES += src/cjson/cJSON.c
93 json2cbor_CCFLAGS = -I$(SRCDIR)src/cjson
98 all: .config lib/libtinycbor.a bin/cbordump tinycbor.pc
99 all: $(if $(JSON2CBOR_SOURCES),bin/json2cbor)
100 check: tests/Makefile | lib/libtinycbor.a
101 $(MAKE) -C tests check
102 silentcheck: | lib/libtinycbor.a
103 TESTARGS=-silent $(MAKE) -f $(MAKEFILE) -s check
105 .config: Makefile.configure
106 $(MAKE) -f $(SRCDIR)Makefile.configure OUT='>&9' configure 9> $@
111 lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o) | lib
114 bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) lib/libtinycbor.a | bin
115 $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lm
117 bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) lib/libtinycbor.a | bin
118 $(CC) -o $@ $(LDFLAGS) $(LDFLAGS_CJSON) $^ $(LDLIBS) -lm
120 tinycbor.pc: tinycbor.pc.in
122 -e 's,@prefix@,$(prefix),' \
123 -e 's,@exec_prefix@,$(exec_prefix),' \
124 -e 's,@libdir@,$(libdir),' \
125 -e 's,@includedir@,$(includedir),' \
126 -e 's,@version@,$(VERSION),'
128 tests/Makefile: tests/tests.pro
129 $(QMAKE) $(QMAKEFLAGS) -o $@ $<
131 $(PACKAGE).tar.gz: | .git
132 GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=tar.gz -o "$(PACKAGE).tar.gz" HEAD
133 $(PACKAGE).zip: | .git
134 GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=zip -o "$(PACKAGE).zip" HEAD
136 $(DESTDIR)$(libdir)/%: lib/%
138 $(INSTALL_DATA) $< $@
139 $(DESTDIR)$(bindir)/%: bin/%
141 $(INSTALL_PROGRAM) $< $@
142 $(DESTDIR)$(pkgconfigdir)/%: %
144 $(INSTALL_DATA) $< $@
145 $(DESTDIR)$(includedir)/tinycbor/%: src/%
147 $(INSTALL_DATA) $< $@
150 $(MAKE) -f $(MAKEFILE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
152 install: $(INSTALL_TARGETS:%=$(DESTDIR)%)
154 $(RM) $(INSTALL_TARGETS:%=$(DESTDIR)%)
157 $(RM) $(TINYCBOR_SOURCES:.c=.o)
158 $(RM) $(CBORDUMP_SOURCES:.c=.o)
163 $(RM) lib/libtinycbor.a
165 test -e tests/Makefile && $(MAKE) -C tests clean || :
168 test -e tests/Makefile && $(MAKE) -C tests distclean || :
171 cd $(SRCDIR)src && VERSION=$(VERSION) doxygen $(SRCDIR)/../Doxyfile
173 dist: $(PACKAGE).tar.gz $(PACKAGE).zip
175 -$(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck
176 GIT_DIR=$(SRCDIR).git git archive --prefix=tinycbor-distcheck/ --format=tar HEAD | tar -xf - -C $${TMPDIR-/tmp}
177 cd $${TMPDIR-/tmp}/tinycbor-distcheck && $(MAKE) silentcheck
178 $(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck
181 $(MAKE) -f $(MAKEFILE) distcheck
183 git -C $(SRCDIR). show HEAD:VERSION | \
184 perl -l -n -e '@_ = split /\./; print "$$_[0]." . ($$_[1] + 1)' > $(SRCDIR)VERSION
186 echo "$(VERSION)" > VERSION
188 if test -n "`git diff VERSION`"; then \
189 git -C $(SRCDIR). commit -s -m "Update version number" VERSION; \
191 { echo "TinyCBOR release `cat $(SRCDIR)VERSION`"; \
193 echo '# Write something nice about this release here'; \
194 tmpl=`git -C $(SRCDIR). config --get commit.template` && \
196 echo '# Commit log:'; \
197 git -C $(SRCDIR). shortlog -e --no-merges HEAD --not `git -C $(SRCDIR). tag` | sed 's,^,# ,'; \
198 echo '# Header diff:'; \
199 git -C $(SRCDIR). diff HEAD --not `git -C $(SRCDIR). tag` -- 'src/*.h' ':!*_p.h' | sed 's,^,# ,'; \
200 } > $(SRCDIR).git/TAG_EDITMSG
201 @`git -C $(SRCDIR). var GIT_EDITOR` $(SRCDIR).git/TAG_EDITMSG
202 git -C $(SRCDIR). tag -a -F $(SRCDIR).git/TAG_EDITMSG $(GITTAGFLAGS) v`cat $(SRCDIR)VERSION`
204 .PHONY: all check silentcheck configure install uninstall
205 .PHONY: mostlyclean clean distclean
206 .PHONY: docs dist distcheck release
209 cflags := $(CPPFLAGS) -I$(SRCDIR)src
210 cflags += -DTINYCBOR_VERSION=\"$(VERSION)$(DIRTYSRC)\"
211 cflags += -std=c99 $(CFLAGS)
213 @test -d $(@D) || $(MKDIR) $(@D)
214 $(CC) $(cflags) $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $<