diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..018cf2cb --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +.tag export-subst +.gitignore export-ignore +.gitattributes export-ignore diff --git a/.gitignore b/.gitignore index efd30aa0..388dc995 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,6 @@ Makefile* *.map bin +lib +src/cjson +!Makefile diff --git a/.tag b/.tag new file mode 100644 index 00000000..6828f88d --- /dev/null +++ b/.tag @@ -0,0 +1 @@ +$Format:%H$ diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..5e675bc9 --- /dev/null +++ b/Makefile @@ -0,0 +1,157 @@ +# Variables: +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +libdir = $(exec_prefix)/lib +includedir = $(prefix)/include +pkgconfigdir = $(libdir)/pkgconfig + +CFLAGS = -Wall -Wextra +LDFLAGS = -Wl,--gc-sections + +GIT_ARCHIVE = git archive --prefix="$(PACKAGE)/" -9 +INSTALL = install +INSTALL_DATA = $(INSTALL) -m 644 +INSTALL_PROGRAM = $(INSTALL) -m 755 +QMAKE = qmake +MKDIR = mkdir -p +RMDIR = rmdir +SED = sed + +# Our sources +TINYCBOR_HEADERS = src/cbor.h src/cborjson.h +TINYCBOR_SOURCES = \ + src/cborerrorstrings.c \ + src/cborencoder.c \ + src/cborparser.c \ + src/cborpretty.c \ + src/cbortojson.c \ +# +CBORDUMP_SOURCES = tools/cbordump/cbordump.c + +INSTALL_TARGETS += $(bindir)/cbordump +INSTALL_TARGETS += $(libdir)/libtinycbor.a +INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc +INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%) + +# setup VPATH +MAKEFILE := $(lastword $(MAKEFILE_LIST)) +SRCDIR := $(dir $(MAKEFILE)) +VPATH = $(SRCDIR):$(SRCDIR)/src + +# Our version +GIT_DIR := $(strip $(shell git -C $(SRCDIR) rev-parse --git-dir 2> /dev/null)) +ifeq ($(GIT_DIR),) + VERSION = $(shell cat $(SRCDIR)VERSION) + DIRTYSRC := +else + VERSION := $(shell git -C $(SRCDIR) describe --tags | cut -c2-) + DIRTYSRC := $(shell \ + test -n `git -C $(SRCDIR) diff --name-only HEAD` && \ + echo +) +endif +PACKAGE = tinycbor-$(VERSION) + +# Check that QMAKE is Qt 5 +ifeq ($(origin QMAKE),file) + check_qmake = $(strip $(shell $(1) -query QT_VERSION 2>/dev/null | cut -b1)) + ifneq ($(call check_qmake,$(QMAKE)),5) + QMAKE := qmake -qt5 + ifneq ($(call check_qmake,$(QMAKE)),5) + QMAKE := qmake-qt5 + ifneq ($(call check_qmake,$(QMAKE)),5) + QMAKE := @echo >&2 $(MAKEFILE): Cannot find a Qt 5 qmake; false + endif + endif + endif +endif + +# Rules +all: lib/libtinycbor.a bin/cbordump tinycbor.pc +check: tests/Makefile | lib/libtinycbor.a + $(MAKE) -C tests check +silentcheck: | lib/libtinycbor.a + TESTARGS=-silent $(MAKE) -f $(MAKEFILE) -s check + +lib bin: + $(MKDIR) $@ + +lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o) | lib + $(AR) cqs $@ $^ + +bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) lib/libtinycbor.a | bin + $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) + +tinycbor.pc: tinycbor.pc.in + $(SED) > $@ < $< \ + -e 's,@prefix@,$(prefix),' \ + -e 's,@exec_prefix@,$(exec_prefix),' \ + -e 's,@libdir@,$(libdir),' \ + -e 's,@includedir@,$(includedir),' \ + -e 's,@version@,$(VERSION),' + +tests/Makefile: tests/tests.pro + $(QMAKE) -o $@ $< + +$(PACKAGE).tar.gz: | .git + GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=tar.gz -o "$(PACKAGE).tar.gz" HEAD +$(PACKAGE).zip: | .git + GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=zip -o "$(PACKAGE).zip" HEAD + +$(DESTDIR)%/: + $(INSTALL) -d $@ +$(DESTDIR)$(libdir)/%: lib/% | $(DESTDIR)$(libdir)/ + $(INSTALL_DATA) $< $@ +$(DESTDIR)$(bindir)/%: bin/% | $(DESTDIR)$(bindir)/ + $(INSTALL_PROGRAM) $< $@ +$(DESTDIR)$(pkgconfigdir)/%: % | $(DESTDIR)$(pkgconfigdir)/ + $(INSTALL_DATA) $< $@ +$(DESTDIR)$(includedir)/tinycbor/%: src/% | $(DESTDIR)$(includedir)/tinycbor/ + $(INSTALL_DATA) $< $@ + +install-strip: + $(MAKE) -f $(MAKEFILE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install + +install: $(INSTALL_TARGETS:%=$(DESTDIR)%) +uninstall: + $(RM) $(INSTALL_TARGETS:%=$(DESTDIR)%) + +mostlyclean: + $(RM) $(TINYCBOR_SOURCES:.c=.o) + $(RM) $(CBORDUMP_SOURCES:.c=.o) + +clean: mostlyclean + $(RM) bin/cbordump + $(RM) lib/libtinycbor.a + $(RM) tinycbor.pc + test -e tests/Makefile && $(MAKE) -C tests clean || : + +distclean: clean + test -e tests/Makefile && $(MAKE) -C tests distclean || : + +dist: $(PACKAGE).tar.gz $(PACKAGE).zip +distcheck: .git + -$(RM) -r $$TMPDIR/tinycbor-distcheck + GIT_DIR=$(SRCDIR).git git archive --prefix=tinycbor-distcheck/ --format=tar HEAD | tar -xf - -C $$TMPDIR + cd $$TMPDIR/tinycbor-distcheck && $(MAKE) silentcheck + $(RM) -r $$TMPDIR/tinycbor-distcheck + +release: .git + $(MAKE) -f $(MAKEFILE) distcheck + git -C $(SRCDIR) show HEAD:VERSION | \ + perl -l -n -e '@_ = split /\./; print "$$_[0]." . ($$_[1] + 1)' > $(SRCDIR)VERSION + git -C $(SRCDIR) commit -s -m "Update version number" VERSION + v=v`cat $(SRCDIR)VERSION` && git -C $(SRCDIR) tag -a -m "TinyCBOR release $$v" $(GITTAGFLAGS) $$v + $(MAKE) -f $(MAKEFILE) dist + +.PHONY: all check silentcheck install uninstall +.PHONY: mostlyclean clean distclean +.PHONY: dist distcheck release +.SECONDARY: + +cflags := $(CPPFLAGS) -I$(SRCDIR)src +cflags += -DTINYCBOR_VERSION=\"$(VERSION)$(DIRTYSRC)\" +cflags += -std=c99 $(CFLAGS) +%.o: %.c + @test -d $(@D) || $(MKDIR) $(@D) + $(CC) $(cflags) -c -o $@ $< diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..49d59571 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1 diff --git a/src/tinycbor.pro b/src/tinycbor.pro new file mode 100644 index 00000000..22ba52e2 --- /dev/null +++ b/src/tinycbor.pro @@ -0,0 +1,5 @@ +TEMPLATE = lib +CONFIG += static +DESTDIR = ../lib + +include(src.pri) diff --git a/tests/cpp/cpp.pro b/tests/cpp/cpp.pro index b24047fe..5e9e6089 100644 --- a/tests/cpp/cpp.pro +++ b/tests/cpp/cpp.pro @@ -1,6 +1,5 @@ CONFIG += testcase parallel_test c++11 QT = core testlib -include(../../src/src.pri) SOURCES = tst_cpp.cpp - +INCLUDEPATH += ../../src diff --git a/tests/encoder/encoder.pro b/tests/encoder/encoder.pro index 85acb011..1b42bd9d 100644 --- a/tests/encoder/encoder.pro +++ b/tests/encoder/encoder.pro @@ -3,4 +3,6 @@ SOURCES += tst_encoder.cpp CONFIG += testcase parallel_test c++11 QT = core testlib -include(../../src/src.pri) +INCLUDEPATH += ../../src +POST_TARGETDEPS += ../../lib/libtinycbor.a +LIBS += $$POST_TARGETDEPS diff --git a/tests/parser/parser.pro b/tests/parser/parser.pro index bce38a3e..ecc75517 100644 --- a/tests/parser/parser.pro +++ b/tests/parser/parser.pro @@ -1,7 +1,9 @@ -SOURCES += tst_parser.cpp +SOURCES += tst_parser.cpp ../../src/cborparser.c CONFIG += testcase parallel_test c++11 QT = core testlib DEFINES += CBOR_PARSER_MAX_RECURSIONS=16 -include(../../src/src.pri) +INCLUDEPATH += ../../src +POST_TARGETDEPS += ../../lib/libtinycbor.a +LIBS += $$POST_TARGETDEPS diff --git a/tinycbor.pc.in b/tinycbor.pc.in new file mode 100644 index 00000000..c3266a7d --- /dev/null +++ b/tinycbor.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: TinyCBOR +Description: A tiny CBOR encoder and decoder library +Version: @version@ +Libs: -L${libdir} -ltinycbor +Cflags: -I${includedir}/tinycbor