From 284764d8e22fe46c5627b38769a3c5a7913596a1 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 11 Aug 2017 15:52:12 +0000 Subject: [PATCH] Convert build system to autotools, and enable building the shared library --- .gitignore | 28 +++++++++++++++++++++++++++ .travis.yml | 4 +++- Makefile | 41 ---------------------------------------- Makefile.am | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 12 ++++++++---- autogen.sh | 11 +++++++++++ configure.ac | 38 +++++++++++++++++++++++++++++++++++++ jsmn.pc.in | 10 ++++++++++ 8 files changed, 151 insertions(+), 46 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile create mode 100644 Makefile.am create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 jsmn.pc.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c73988b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +*~ +*.pc +*.la +*.o +libtool +ltmain.sh +missing +install-sh +depcomp +configure +config.* +*.lo +autom4te.cache +ar-lib +compile +test-driver +aclocal.m4 +Makefile +Makefile.in +.deps +*.log +.libs +ii +*.tar* +/jsondump +/simple_example +/test_* +.dirstamp diff --git a/.travis.yml b/.travis.yml index 1c8ebd32..71d05853 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: c sudo: false script: - - make test + - ./autogen.sh + - ./configure + - make all simple_example check diff --git a/Makefile b/Makefile deleted file mode 100644 index f89701fd..00000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# You can put your build options here --include config.mk - -all: libjsmn.a - -libjsmn.a: jsmn.o - $(AR) rc $@ $^ - -%.o: %.c jsmn.h - $(CC) -c $(CFLAGS) $< -o $@ - -test: test_default test_strict test_links test_strict_links -test_default: test/tests.c - $(CC) $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ -test_strict: test/tests.c - $(CC) -DJSMN_STRICT=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ -test_links: test/tests.c - $(CC) -DJSMN_PARENT_LINKS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ -test_strict_links: test/tests.c - $(CC) -DJSMN_STRICT=1 -DJSMN_PARENT_LINKS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@ - ./test/$@ - -jsmn_test.o: jsmn_test.c libjsmn.a - -simple_example: example/simple.o libjsmn.a - $(CC) $(LDFLAGS) $^ -o $@ - -jsondump: example/jsondump.o libjsmn.a - $(CC) $(LDFLAGS) $^ -o $@ - -clean: - rm -f *.o example/*.o - rm -f *.a *.so - rm -f simple_example - rm -f jsondump - -.PHONY: all clean test - diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..68c72e85 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,53 @@ +# Copyright 2017 Luke Dashjr +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the standard MIT license. See COPYING for more details. + +lib_LTLIBRARIES = libjsmn.la +libjsmn_la_SOURCES = jsmn.c +libjsmn_la_LDFLAGS = -version-info $(LIBJSMN_SO_VERSION) -no-undefined + +libjsmn_includedir = $(includedir) +libjsmn_include_HEADERS = jsmn.h + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = jsmn.pc + +dist_noinst_SCRIPTS = autogen.sh +dist_doc_DATA = LICENSE README.md + +jsondump_SOURCES = example/jsondump.c +jsondump_LDADD = libjsmn.la + +simple_example_SOURCES = example/simple.c +simple_example_LDADD = libjsmn.la + +if USE_TOOL +bin_PROGRAMS = jsondump +endif + +if NEVER_ENABLED +noinst_PROGRAMS = simple_example +endif + +TESTS = test_default test_strict test_links test_strict_links +if NEVER_ENABLED +noinst_PROGRAMS += $(TESTS) +endif + +test_default_SOURCES = test/tests.c + +test_strict_SOURCES = test/tests.c +test_strict_CPPFLAGS = -DJSMN_STRICT=1 + +test_links_SOURCES = test/tests.c +test_links_CPPFLAGS = -DJSMN_PARENT_LINKS=1 + +test_strict_links_SOURCES = test/tests.c +test_strict_links_CPPFLAGS = -DJSMN_STRICT=1 -DJSMN_PARENT_LINKS=1 + +# Compatibility with old Makefile: + +test: check + +.PHONY: test diff --git a/README.md b/README.md index e58fb280..a372efd3 100644 --- a/README.md +++ b/README.md @@ -84,14 +84,18 @@ To clone the repository you should have Git installed. Just run: $ git clone https://github.com/zserge/jsmn Repository layout is simple: jsmn.c and jsmn.h are library files, tests are in -the jsmn\_test.c, you will also find README, LICENSE and Makefile files inside. +test/tests.c; you will also find README, LICENSE and autotools build files +inside. -To build the library, run `make`. It is also recommended to run `make test`. -Let me know, if some tests fail. +To build the library, run `./configure && make`. It is also recommended to run +`make test`. Let me know if any tests fail. -If build was successful, you should get a `libjsmn.a` library. +If build was successful, you should get a `libjsmn.a` and `libjsmn.so*` +libraries in the `.libs` directory. The header file you should include is called `"jsmn.h"`. +You can install the libraries to your system by running `make install`. + API --- diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 00000000..0e2f2d14 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,11 @@ +#!/bin/sh -e +# Written by Luke Dashjr in 2012 +# This program is released under the terms of the Creative Commons "CC0 1.0 Universal" license and/or copyright waiver. + +if test -z "$srcdir"; then + srcdir=`dirname "$0"` + if test -z "$srcdir"; then + srcdir=. + fi +fi +autoreconf --force --install --verbose "$srcdir" diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..6d744458 --- /dev/null +++ b/configure.ac @@ -0,0 +1,38 @@ +dnl * Copyright 2012-2017 Luke Dashjr +dnl * +dnl * This program is free software; you can redistribute it and/or modify it +dnl * under the terms of the standard MIT license. See COPYING for more details. + +AC_INIT( + [jsmn], + [0.1.0], + [zaitsev.serge@gmail.com], + [jsmn]) +AC_CONFIG_AUX_DIR([.]) +AC_PREREQ([2.59]) +AM_INIT_AUTOMAKE([1.11 -Wall dist-xz foreign subdir-objects]) +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +AC_PROG_CC_C99 +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) +LT_INIT([]) + +# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html +AC_SUBST([LIBJSMN_SO_VERSION], [0:0:0]) + +AC_CONFIG_FILES([Makefile + jsmn.pc:jsmn.pc.in +]) + +AC_ARG_ENABLE([tool], + [AC_HELP_STRING([--disable-tool],[Compile command line jsmndump tool (default enabled)])], + [use_tool=$enableval], + [use_tool=auto]) +if test x$use_tool != xno; then + use_tool=yes +fi +AM_CONDITIONAL([USE_TOOL], [test x$use_tool = xyes]) + +AM_CONDITIONAL([NEVER_ENABLED], [false]) + +AC_OUTPUT diff --git a/jsmn.pc.in b/jsmn.pc.in new file mode 100644 index 00000000..ded084c5 --- /dev/null +++ b/jsmn.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @PACKAGE_NAME@ +Description: A minimalistic JSON parser in C. +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -ljsmn +Cflags: -I${includedir}