replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / extlibs / tinycbor / tinycbor / Makefile
1 # Variables:
2 prefix = /usr/local
3 exec_prefix = $(prefix)
4 bindir = $(exec_prefix)/bin
5 libdir = $(exec_prefix)/lib
6 includedir = $(prefix)/include
7 pkgconfigdir = $(libdir)/pkgconfig
8
9 CFLAGS = -Wall -Wextra
10 LDFLAGS_GCSECTIONS = -Wl,--gc-sections
11 LDFLAGS = $(if $(gc_sections-pass),$(LDFLAGS_GCSECTIONS))
12
13 GIT_ARCHIVE = git archive --prefix="$(PACKAGE)/" -9
14 INSTALL = install
15 INSTALL_DATA = $(INSTALL) -m 644
16 INSTALL_PROGRAM = $(INSTALL) -m 755
17 QMAKE = qmake
18 MKDIR = mkdir -p
19 RMDIR = rmdir
20 SED = sed
21
22 # Our sources
23 TINYCBOR_HEADERS = src/cbor.h src/cborjson.h
24 TINYCBOR_SOURCES = \
25         src/cborerrorstrings.c \
26         src/cborencoder.c \
27         src/cborencoder_close_container_checked.c \
28         src/cborparser.c \
29         src/cborparser_dup_string.c \
30         src/cborpretty.c \
31         src/cbortojson.c \
32 #
33 CBORDUMP_SOURCES = tools/cbordump/cbordump.c
34
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/%)
39
40 # setup VPATH
41 MAKEFILE := $(lastword $(MAKEFILE_LIST))
42 SRCDIR := $(dir $(MAKEFILE))
43 VPATH = $(SRCDIR):$(SRCDIR)/src
44
45 # Our version
46 GIT_DIR := $(strip $(shell git -C $(SRCDIR). rev-parse --git-dir 2> /dev/null))
47 ifeq ($(GIT_DIR),)
48   VERSION = $(shell cat $(SRCDIR)VERSION)
49   DIRTYSRC :=
50 else
51   VERSION := $(shell git -C $(SRCDIR). describe --tags | cut -c2-)
52   DIRTYSRC := $(shell \
53         test -n "`git -C $(SRCDIR). diff --name-only HEAD`" && \
54         echo +)
55 endif
56 PACKAGE = tinycbor-$(VERSION)
57
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)
62     QMAKE := qmake -qt5
63     ifneq ($(call check_qmake,$(QMAKE)),5)
64       QMAKE := qmake-qt5
65       ifneq ($(call check_qmake,$(QMAKE)),5)
66         QMAKE := @echo >&2 $(MAKEFILE): Cannot find a Qt 5 qmake; false
67       endif
68     endif
69   endif
70 endif
71
72 -include .config
73
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!)
80   else
81     TINYCBOR_SOURCES += src/open_memstream.c
82   endif
83 endif
84
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
91   else
92     JSON2CBOR_SOURCES += src/cjson/cJSON.c
93     json2cbor_CCFLAGS = -I$(SRCDIR)src/cjson
94   endif
95 endif
96
97 # Rules
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
104 configure: .config
105 .config: Makefile.configure
106         $(MAKE) -f $(SRCDIR)Makefile.configure OUT='>&9' configure 9> $@
107
108 lib bin:
109         $(MKDIR) $@
110
111 lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o) | lib
112         $(AR) cqs $@ $^
113
114 bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) lib/libtinycbor.a | bin
115         $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lm
116
117 bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) lib/libtinycbor.a | bin
118         $(CC) -o $@ $(LDFLAGS) $(LDFLAGS_CJSON) $^ $(LDLIBS) -lm
119
120 tinycbor.pc: tinycbor.pc.in
121         $(SED) > $@ < $< \
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),'
127
128 tests/Makefile: tests/tests.pro
129         $(QMAKE) $(QMAKEFLAGS) -o $@ $<
130
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
135
136 $(DESTDIR)$(libdir)/%: lib/%
137         $(INSTALL) -d $(@D)
138         $(INSTALL_DATA) $< $@
139 $(DESTDIR)$(bindir)/%: bin/%
140         $(INSTALL) -d $(@D)
141         $(INSTALL_PROGRAM) $< $@
142 $(DESTDIR)$(pkgconfigdir)/%: %
143         $(INSTALL) -d $(@D)
144         $(INSTALL_DATA) $< $@
145 $(DESTDIR)$(includedir)/tinycbor/%: src/%
146         $(INSTALL) -d $(@D)
147         $(INSTALL_DATA) $< $@
148
149 install-strip:
150         $(MAKE) -f $(MAKEFILE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
151
152 install: $(INSTALL_TARGETS:%=$(DESTDIR)%)
153 uninstall:
154         $(RM) $(INSTALL_TARGETS:%=$(DESTDIR)%)
155
156 mostlyclean:
157         $(RM) $(TINYCBOR_SOURCES:.c=.o)
158         $(RM) $(CBORDUMP_SOURCES:.c=.o)
159
160 clean: mostlyclean
161         $(RM) bin/cbordump
162         $(RM) bin/json2cbor
163         $(RM) lib/libtinycbor.a
164         $(RM) tinycbor.pc
165         test -e tests/Makefile && $(MAKE) -C tests clean || :
166
167 distclean: clean
168         test -e tests/Makefile && $(MAKE) -C tests distclean || :
169
170 docs:
171         cd $(SRCDIR)src && VERSION=$(VERSION) doxygen $(SRCDIR)/../Doxyfile
172
173 dist: $(PACKAGE).tar.gz $(PACKAGE).zip
174 distcheck: .git
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
179
180 release: .git
181         $(MAKE) -f $(MAKEFILE) distcheck
182         git -C $(SRCDIR). show HEAD:VERSION | \
183           perl -l -n -e '@_ = split /\./; print "$$_[0]." . ($$_[1] + 1)' > $(SRCDIR)VERSION
184         git -C $(SRCDIR). commit -s -m "Update version number" VERSION
185         { echo "TinyCBOR release `cat $(SRCDIR)VERSION`"; \
186           echo; \
187           echo '# Write something nice about this release here'; \
188           tmpl=`git -C $(SRCDIR). config --get commit.template` && \
189                 cat "$$tmpl"; \
190           echo '# Commit log:'; \
191           git -C $(SRCDIR). shortlog -e --no-merges HEAD --not `git -C $(SRCDIR). tag` | sed 's,^,#   ,'; \
192           echo '# Header diff:'; \
193           git -C $(SRCDIR). diff HEAD --not `git -C $(SRCDIR). tag` -- 'src/*.h' ':!*_p.h' | sed 's,^,# ,'; \
194         } > $(SRCDIR).git/TAG_EDITMSG
195         @`git -C $(SRCDIR). var GIT_EDITOR` $(SRCDIR).git/TAG_EDITMSG
196         git -C $(SRCDIR). tag -a -F $(SRCDIR).git/TAG_EDITMSG $(GITTAGFLAGS) v`cat $(SRCDIR)VERSION`
197         $(MAKE) -f $(MAKEFILE) dist
198
199 .PHONY: all check silentcheck configure install uninstall
200 .PHONY: mostlyclean clean distclean
201 .PHONY: docs dist distcheck release
202 .SECONDARY:
203
204 cflags := $(CPPFLAGS) -I$(SRCDIR)src
205 cflags += -DTINYCBOR_VERSION=\"$(VERSION)$(DIRTYSRC)\"
206 cflags += -std=c99 $(CFLAGS)
207 %.o: %.c
208         @test -d $(@D) || $(MKDIR) $(@D)
209         $(CC) $(cflags) $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $<
210