1#******************************************************************************* 2# Copyright (c) 2009, 2014 IBM Corp. 3# 4# All rights reserved. This program and the accompanying materials 5# are made available under the terms of the Eclipse Public License v1.0 6# and Eclipse Distribution License v1.0 which accompany this distribution. 7# 8# The Eclipse Public License is available at 9# http://www.eclipse.org/legal/epl-v10.html 10# and the Eclipse Distribution License is available at 11# http://www.eclipse.org/org/documents/edl-v10.php. 12# 13# Contributors: 14# Xiang Rong - 442039 Add makefile to Embedded C client 15#*******************************************************************************/ 16 17# Note: on OS X you should install XCode and the associated command-line tools 18 19SHELL = /bin/sh 20.PHONY: clean, mkdir, install, uninstall, html 21 22# assume this is normally run in the main Paho directory 23ifndef srcdir 24 srcdir = MQTTPacket/src 25endif 26 27ifndef blddir 28 blddir = build/output 29endif 30 31ifndef prefix 32 prefix = /usr/local 33endif 34 35ifndef exec_prefix 36 exec_prefix = ${prefix} 37endif 38 39bindir = $(exec_prefix)/bin 40includedir = $(prefix)/include 41libdir = $(exec_prefix)/lib 42 43SOURCE_FILES_C = $(srcdir)/*.c 44 45HEADERS = $(srcdir)/*.h 46 47 48SAMPLE_FILES_C = pub0sub1 qos0pub 49SYNC_SAMPLES = ${addprefix ${blddir}/samples/,${SAMPLE_FILES_C}} 50 51 52TEST_FILES_C = test1 53SYNC_TESTS = ${addprefix ${blddir}/test/,${TEST_FILES_C}} 54 55 56# The names of libraries to be built 57MQTT_EMBED_LIB_C = paho-embed-mqtt3c 58 59 60# determine current platform 61ifeq ($(OS),Windows_NT) 62 OSTYPE = $(OS) 63else 64 OSTYPE = $(shell uname -s) 65 MACHINETYPE = $(shell uname -m) 66endif 67 68ifeq ($(OSTYPE),Linux) 69 70CC ?= gcc 71 72ifndef INSTALL 73INSTALL = install 74endif 75INSTALL_PROGRAM = $(INSTALL) 76INSTALL_DATA = $(INSTALL) -m 644 77 78MAJOR_VERSION = 1 79MINOR_VERSION = 0 80VERSION = ${MAJOR_VERSION}.${MINOR_VERSION} 81 82EMBED_MQTTLIB_C_TARGET = ${blddir}/lib${MQTT_EMBED_LIB_C}.so.${VERSION} 83 84 85CCFLAGS_SO = -g -fPIC -Os -Wall -fvisibility=hidden -DLINUX_SO 86FLAGS_EXE = -I ${srcdir} -L ${blddir} 87 88LDFLAGS_C = -shared -Wl,-soname,lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} 89 90all: build 91 92build: | mkdir ${EMBED_MQTTLIB_C_TARGET} ${SYNC_SAMPLES} ${SYNC_TESTS} 93 94clean: 95 rm -rf ${blddir}/* 96 97mkdir: 98 -mkdir -p ${blddir}/samples 99 -mkdir -p ${blddir}/test 100 101${SYNC_TESTS}: ${blddir}/test/%: ${srcdir}/../test/%.c 102 ${CC} -g -o ${blddir}/test/${basename ${+F}} $< -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE} 103 104 105${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/../samples/%.c ${srcdir}/../samples/transport.o 106 ${CC} -o $@ $^ -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE} 107 108 109 110${EMBED_MQTTLIB_C_TARGET}: ${SOURCE_FILES_C} ${HEADERS_C} 111 ${CC} ${CCFLAGS_SO} -o $@ ${SOURCE_FILES_C} ${LDFLAGS_C} 112 -ln -s lib$(MQTT_EMBED_LIB_C).so.${VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} 113 -ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so 114 115 116strip_options: 117 $(eval INSTALL_OPTS := -s) 118 119install-strip: build strip_options install 120 121install: build 122 $(INSTALL_DATA) ${INSTALL_OPTS} ${EMBED_MQTTLIB_C_TARGET} $(DESTDIR)${libdir} 123 124 125 /sbin/ldconfig $(DESTDIR)${libdir} 126 ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so 127 128 129uninstall: 130 rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so.${VERSION} 131 132 /sbin/ldconfig $(DESTDIR)${libdir} 133 rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so 134 135 136html: 137 138ARDUINO_LIB_FILES = MQTTClient/src/*.h MQTTClient/src/arduino/*.h $(srcdir)/* 139ARDUINO_SAMPLES = MQTTClient/samples/arduino/* 140LEGAL_FILES = edl-v10 epl-v10 notice.html about.html CONTRIBUTING.md README.md library.properties 141 142arduino: mkdir 143 -mkdir -p ${blddir}/arduino/MQTTClient/examples 144 -mkdir -p ${blddir}/arduino/MQTTClient/src 145 cp $(ARDUINO_LIB_FILES) ${blddir}/arduino/MQTTClient/src 146 cp $(LEGAL_FILES) ${blddir}/arduino/MQTTClient 147 cp -R $(ARDUINO_SAMPLES) ${blddir}/arduino/MQTTClient/examples 148 cd ${blddir}/arduino && zip -r arduino MQTTClient 149 150endif 151 152 153 154ifeq ($(OSTYPE),Darwin) 155 156CC ?= gcc 157 158ifndef INSTALL 159INSTALL = install 160endif 161INSTALL_PROGRAM = $(INSTALL) 162INSTALL_DATA = $(INSTALL) -m 644 163 164MAJOR_VERSION = 1 165MINOR_VERSION = 0 166VERSION = ${MAJOR_VERSION}.${MINOR_VERSION} 167 168EMBED_MQTTLIB_C_TARGET = ${blddir}/lib${MQTT_EMBED_LIB_C}.so.${VERSION} 169 170 171CCFLAGS_SO = -g -fPIC -Os -Wall -fvisibility=hidden -Wno-deprecated-declarations -DUSE_NAMED_SEMAPHORES 172FLAGS_EXE = -I ${srcdir} -L ${blddir} 173 174LDFLAGS_C = -shared -Wl,-install_name,lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} 175 176all: build 177 178build: | mkdir ${EMBED_MQTTLIB_C_TARGET} ${SYNC_SAMPLES} ${SYNC_TESTS} 179 180clean: 181 rm -rf ${blddir}/* 182 183mkdir: 184 -mkdir -p ${blddir}/samples 185 -mkdir -p ${blddir}/test 186 187${SYNC_TESTS}: ${blddir}/test/%: ${srcdir}/../test/%.c 188 ${CC} -g -o ${blddir}/test/${basename ${+F}} $< -l${MQTT_EMBED_LIB_C} ${FLAGS_EXE} 189 190${SYNC_SAMPLES}: ${blddir}/samples/%: ${srcdir}/../samples/%.c 191 ${CC} -o ${blddir}/samples/${basename ${+F}} $< ${FLAGS_EXE} -l${MQTT_EMBED_LIB_C} 192 193${EMBED_MQTTLIB_C_TARGET}: ${SOURCE_FILES_C} ${HEADERS_C} 194 ${CC} ${CCFLAGS_SO} -o $@ ${SOURCE_FILES_C} ${LDFLAGS_C} 195 -ln -s lib$(MQTT_EMBED_LIB_C).so.${VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} 196 -ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} ${blddir}/lib$(MQTT_EMBED_LIB_C).so 197 198 199strip_options: 200 $(eval INSTALL_OPTS := -s) 201 202install-strip: build strip_options install 203 204install: build 205 $(INSTALL_DATA) ${INSTALL_OPTS} ${EMBED_MQTTLIB_C_TARGET} $(DESTDIR)${libdir} 206 207 /sbin/ldconfig $(DESTDIR)${libdir} 208 ln -s lib$(MQTT_EMBED_LIB_C).so.${MAJOR_VERSION} $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so 209 210 211uninstall: 212 rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so.${VERSION} 213 /sbin/ldconfig $(DESTDIR)${libdir} 214 rm $(DESTDIR)${libdir}/lib$(MQTT_EMBED_LIB_C).so 215 216 217html: 218 219 220endif 221