From 83aa7e523150e5986a12866a68910bb3e65f9c6a Mon Sep 17 00:00:00 2001 From: Johannes Schriewer Date: Tue, 31 Jul 2018 17:41:46 +0200 Subject: [PATCH] Build header file from template, create 'dist' target --- .gitignore | 2 ++ Makefile.linux | 26 +++++++++++++++++++++++--- src/{mqtt.h => mqtt.h.in} | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) rename src/{mqtt.h => mqtt.h.in} (97%) diff --git a/.gitignore b/.gitignore index f6aa3a1..160d993 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ *.gcov coverage/ *.test +cmake-build-debug/ +.idea/ diff --git a/Makefile.linux b/Makefile.linux index 4e134be..ad7acbc 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -6,6 +6,9 @@ COVERAGE_FILES=$(SRCS:%.c=%.gcno) $(SRCS:%.c=%.gcda) TARGET=libmqtt.a DEBUG_TARGET=libmqtt-debug.a +MAJOR_VERSION=0 +MINOR_VERSION=1 + PLATFORM_FLAGS= AR=ar @@ -30,16 +33,31 @@ coverage: mkdir -p coverage genhtml -o coverage lcov.info +dist: $(TARGET) + mkdir -p dist/include + mkdir -p dist/lib + cp libmqtt.a dist/lib + cp src/mqtt.h dist/include + (cd dist && tar czvf ../libmqtt-$(MAJOR_VERSION).$(MINOR_VERSION).tar.gz .) + +src/mqtt.h: src/mqtt.h.in + sed \ + -e 's/@LIBMQTT_VERSION_MAJOR@/'$(MAJOR_VERSION)'/' \ + -e 's/@LIBMQTT_VERSION_MINOR@/'$(MINOR_VERSION)'/' \ + -e 's/@LIBMQTT_BUILD_DATE@/"'`date +%Y-%m-%d_%H-%M-%S`'"/' \ + src/mqtt.h.in >src/mqtt.h + + $(TARGET): $(OBJS) $(AR) -cr $(TARGET) $(OBJS) $(DEBUG_TARGET): $(DEBUG_OBJS) $(AR) -cr $(DEBUG_TARGET) $(DEBUG_OBJS) -%.do: %.c +%.do: %.c src/mqtt.h $(CC) $(CFLAGS) $(DEBUG_FLAGS) -o $@ -c $< -%.o: %.c +%.o: %.c src/mqtt.h $(CC) $(CFLAGS) -o $@ -c $< mqtt.o: mqtt.h @@ -52,5 +70,7 @@ clean: rm -f *.gcov rm -rf docs/ rm -rf coverage/ + rm -rf dist/ + rm -f libmqtt-$(MAJOR_VERSION).$(MINOR_VERSION).tar.gz -.PHONY: coverage test +.PHONY: coverage test src/mqtt.h diff --git a/src/mqtt.h b/src/mqtt.h.in similarity index 97% rename from src/mqtt.h rename to src/mqtt.h.in index e51d12d..ecb4713 100644 --- a/src/mqtt.h +++ b/src/mqtt.h.in @@ -11,6 +11,9 @@ # define MQTT_CLIENT 1 #endif +#define LIBMQTT_VERSION_MAJOR @LIBMQTT_VERSION_MAJOR@ +#define LIBMQTT_VERSION_MINOR @LIBMQTT_VERSION_MINOR@ +#define LIBMQTT_BUILD_DATE @LIBMQTT_BUILD_DATE@ #include #include