2016-11-14 15:52:44 +00:00
|
|
|
CJSON_OBJ = cJSON.o
|
|
|
|
UTILS_OBJ = cJSON_Utils.o
|
|
|
|
CJSON_LIBNAME = libcjson
|
|
|
|
UTILS_LIBNAME = libcjson_utils
|
|
|
|
CJSON_TEST = cJSON_test
|
|
|
|
|
2016-11-25 09:55:38 +00:00
|
|
|
CJSON_TEST_SRC = cJSON.c test.c
|
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
LDLIBS = -lm
|
|
|
|
|
2019-05-16 18:03:12 +00:00
|
|
|
LIBVERSION = 1.7.12
|
2016-11-14 15:52:44 +00:00
|
|
|
CJSON_SOVERSION = 1
|
|
|
|
UTILS_SOVERSION = 1
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2018-04-13 03:57:49 +00:00
|
|
|
CJSON_SO_LDFLAG=-Wl,-soname=$(CJSON_LIBNAME).so.$(CJSON_SOVERSION)
|
|
|
|
UTILS_SO_LDFLAG=-Wl,-soname=$(UTILS_LIBNAME).so.$(UTILS_SOVERSION)
|
|
|
|
|
2015-01-30 14:06:14 +00:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
INCLUDE_PATH ?= include/cjson
|
|
|
|
LIBRARY_PATH ?= lib
|
|
|
|
|
|
|
|
INSTALL_INCLUDE_PATH = $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH)
|
|
|
|
INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
|
|
|
|
|
|
|
|
INSTALL ?= cp -a
|
|
|
|
|
2019-05-06 19:07:06 +00:00
|
|
|
CC = gcc -std=c89
|
|
|
|
|
2017-05-03 16:07:07 +00:00
|
|
|
# validate gcc version for use fstack-protector-strong
|
|
|
|
MIN_GCC_VERSION = "4.9"
|
2018-04-29 07:20:08 +00:00
|
|
|
GCC_VERSION := "`$(CC) -dumpversion`"
|
2017-05-03 16:07:07 +00:00
|
|
|
IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
|
|
|
|
ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1"
|
|
|
|
CFLAGS += -fstack-protector-strong
|
|
|
|
else
|
|
|
|
CFLAGS += -fstack-protector
|
|
|
|
endif
|
|
|
|
|
2019-05-06 19:07:06 +00:00
|
|
|
PIC_FLAGS = -fPIC
|
2019-06-10 08:59:31 +00:00
|
|
|
R_CFLAGS = -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion -Wfloat-equal $(CFLAGS)
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
#library file extensions
|
|
|
|
SHARED = so
|
|
|
|
STATIC = a
|
2015-01-30 14:06:14 +00:00
|
|
|
|
|
|
|
## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS)
|
2016-11-14 15:52:44 +00:00
|
|
|
ifeq (Darwin, $(uname))
|
|
|
|
SHARED = dylib
|
2018-04-13 03:57:49 +00:00
|
|
|
CJSON_SO_LDFLAG = ""
|
2018-10-14 09:52:19 +00:00
|
|
|
UTILS_SO_LDFLAG = ""
|
2015-01-30 14:06:14 +00:00
|
|
|
endif
|
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
#cJSON library names
|
|
|
|
CJSON_SHARED = $(CJSON_LIBNAME).$(SHARED)
|
|
|
|
CJSON_SHARED_VERSION = $(CJSON_LIBNAME).$(SHARED).$(LIBVERSION)
|
|
|
|
CJSON_SHARED_SO = $(CJSON_LIBNAME).$(SHARED).$(CJSON_SOVERSION)
|
|
|
|
CJSON_STATIC = $(CJSON_LIBNAME).$(STATIC)
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
#cJSON_Utils library names
|
|
|
|
UTILS_SHARED = $(UTILS_LIBNAME).$(SHARED)
|
|
|
|
UTILS_SHARED_VERSION = $(UTILS_LIBNAME).$(SHARED).$(LIBVERSION)
|
|
|
|
UTILS_SHARED_SO = $(UTILS_LIBNAME).$(SHARED).$(UTILS_SOVERSION)
|
|
|
|
UTILS_STATIC = $(UTILS_LIBNAME).$(STATIC)
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
SHARED_CMD = $(CC) -shared -o
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
.PHONY: all shared static tests clean install
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
all: shared static tests
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
shared: $(CJSON_SHARED) $(UTILS_SHARED)
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
static: $(CJSON_STATIC) $(UTILS_STATIC)
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2017-08-21 08:58:49 +00:00
|
|
|
tests: $(CJSON_TEST)
|
2015-01-30 14:06:14 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
test: tests
|
|
|
|
./$(CJSON_TEST)
|
2016-02-11 12:56:54 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
.c.o:
|
2016-11-26 05:57:12 +00:00
|
|
|
$(CC) -c $(R_CFLAGS) $<
|
2016-11-14 15:52:44 +00:00
|
|
|
|
|
|
|
#tests
|
|
|
|
#cJSON
|
2016-11-25 09:55:38 +00:00
|
|
|
$(CJSON_TEST): $(CJSON_TEST_SRC) cJSON.h
|
2016-11-28 16:08:25 +00:00
|
|
|
$(CC) $(R_CFLAGS) $(CJSON_TEST_SRC) -o $@ $(LDLIBS) -I.
|
2016-11-14 15:52:44 +00:00
|
|
|
|
|
|
|
#static libraries
|
|
|
|
#cJSON
|
|
|
|
$(CJSON_STATIC): $(CJSON_OBJ)
|
|
|
|
$(AR) rcs $@ $<
|
|
|
|
#cJSON_Utils
|
|
|
|
$(UTILS_STATIC): $(UTILS_OBJ)
|
|
|
|
$(AR) rcs $@ $<
|
|
|
|
|
|
|
|
#shared libraries .so.1.0.0
|
|
|
|
#cJSON
|
|
|
|
$(CJSON_SHARED_VERSION): $(CJSON_OBJ)
|
2018-04-13 03:57:49 +00:00
|
|
|
$(CC) -shared -o $@ $< $(CJSON_SO_LDFLAG) $(LDFLAGS)
|
2016-11-14 15:52:44 +00:00
|
|
|
#cJSON_Utils
|
|
|
|
$(UTILS_SHARED_VERSION): $(UTILS_OBJ)
|
2019-11-01 03:30:14 +00:00
|
|
|
$(CC) -shared -o $@ $< $(CJSON_OBJ) $(UTILS_SO_LDFLAG) $(LDFLAGS)
|
2016-11-14 15:52:44 +00:00
|
|
|
|
|
|
|
#objects
|
|
|
|
#cJSON
|
|
|
|
$(CJSON_OBJ): cJSON.c cJSON.h
|
|
|
|
#cJSON_Utils
|
2019-07-24 12:46:41 +00:00
|
|
|
$(UTILS_OBJ): cJSON_Utils.c cJSON_Utils.h cJSON.h
|
2016-11-14 15:52:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
#links .so -> .so.1 -> .so.1.0.0
|
|
|
|
#cJSON
|
|
|
|
$(CJSON_SHARED_SO): $(CJSON_SHARED_VERSION)
|
|
|
|
ln -s $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO)
|
|
|
|
$(CJSON_SHARED): $(CJSON_SHARED_SO)
|
|
|
|
ln -s $(CJSON_SHARED_SO) $(CJSON_SHARED)
|
|
|
|
#cJSON_Utils
|
|
|
|
$(UTILS_SHARED_SO): $(UTILS_SHARED_VERSION)
|
|
|
|
ln -s $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO)
|
|
|
|
$(UTILS_SHARED): $(UTILS_SHARED_SO)
|
|
|
|
ln -s $(UTILS_SHARED_SO) $(UTILS_SHARED)
|
|
|
|
|
|
|
|
#install
|
|
|
|
#cJSON
|
|
|
|
install-cjson:
|
|
|
|
mkdir -p $(INSTALL_LIBRARY_PATH) $(INSTALL_INCLUDE_PATH)
|
|
|
|
$(INSTALL) cJSON.h $(INSTALL_INCLUDE_PATH)
|
|
|
|
$(INSTALL) $(CJSON_SHARED) $(CJSON_SHARED_SO) $(CJSON_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
|
|
|
|
#cJSON_Utils
|
|
|
|
install-utils: install-cjson
|
|
|
|
$(INSTALL) cJSON_Utils.h $(INSTALL_INCLUDE_PATH)
|
|
|
|
$(INSTALL) $(UTILS_SHARED) $(UTILS_SHARED_SO) $(UTILS_SHARED_VERSION) $(INSTALL_LIBRARY_PATH)
|
|
|
|
|
|
|
|
install: install-cjson install-utils
|
|
|
|
|
|
|
|
#uninstall
|
|
|
|
#cJSON
|
|
|
|
uninstall-cjson: uninstall-utils
|
|
|
|
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED)
|
|
|
|
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_VERSION)
|
|
|
|
$(RM) $(INSTALL_LIBRARY_PATH)/$(CJSON_SHARED_SO)
|
|
|
|
$(RM) $(INSTALL_INCLUDE_PATH)/cJSON.h
|
2019-10-29 06:21:16 +00:00
|
|
|
|
2016-11-14 15:52:44 +00:00
|
|
|
#cJSON_Utils
|
|
|
|
uninstall-utils:
|
|
|
|
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED)
|
|
|
|
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_VERSION)
|
|
|
|
$(RM) $(INSTALL_LIBRARY_PATH)/$(UTILS_SHARED_SO)
|
|
|
|
$(RM) $(INSTALL_INCLUDE_PATH)/cJSON_Utils.h
|
|
|
|
|
2019-10-29 06:21:16 +00:00
|
|
|
remove-dir:
|
|
|
|
$(if $(wildcard $(INSTALL_LIBRARY_PATH)/*.*),,rmdir $(INSTALL_LIBRARY_PATH))
|
|
|
|
$(if $(wildcard $(INSTALL_INCLUDE_PATH)/*.*),,rmdir $(INSTALL_INCLUDE_PATH))
|
|
|
|
|
|
|
|
uninstall: uninstall-utils uninstall-cjson remove-dir
|
2016-11-14 15:52:44 +00:00
|
|
|
|
|
|
|
clean:
|
|
|
|
$(RM) $(CJSON_OBJ) $(UTILS_OBJ) #delete object files
|
|
|
|
$(RM) $(CJSON_SHARED) $(CJSON_SHARED_VERSION) $(CJSON_SHARED_SO) $(CJSON_STATIC) #delete cJSON
|
|
|
|
$(RM) $(UTILS_SHARED) $(UTILS_SHARED_VERSION) $(UTILS_SHARED_SO) $(UTILS_STATIC) #delete cJSON_Utils
|
2017-08-21 08:58:49 +00:00
|
|
|
$(RM) $(CJSON_TEST) #delete test
|