From f89fb30058a7d2d6a896ace242fc612bfe4e2c34 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Sun, 1 May 2011 19:51:55 +0930 Subject: Add build and package support - Add Makefile and RPM spec file - Add cjson.version variable --- Makefile | 31 +++++++++++++++++++++++++++++++ lua-cjson.spec | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ lua_cjson.c | 4 ++++ 3 files changed, 83 insertions(+) create mode 100644 Makefile create mode 100644 lua-cjson.spec diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..14d5a06 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +CJSON_VERSION = 1.0 +LUA_VERSION = 5.1 + +PREFIX ?= /usr/local +LUA_INCLUDE_DIR ?= $(PREFIX)/include +LUA_LIB_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION) + +#CFLAGS ?= -g -Wall -pedantic -fno-inline +CFLAGS ?= -g -O2 -Wall -pedantic +override CFLAGS += -fpic -I$(LUA_INCLUDE_DIR) -DVERSION=\"$(CJSON_VERSION)\" +LDFLAGS += -shared -lm + +INSTALL ?= install + +.PHONY: all clean install package + +all: cjson.so + +cjson.so: lua_cjson.o strbuf.o + $(CC) $(LDFLAGS) -o $@ $^ + +install: + $(INSTALL) -d $(DESTDIR)/$(LUA_LIB_DIR) + $(INSTALL) cjson.so $(DESTDIR)/$(LUA_LIB_DIR) + +clean: + rm -f *.o *.so + +package: + git archive --prefix="lua-cjson-$(CJSON_VERSION)/" master | \ + gzip -9 > "lua-cjson-$(CJSON_VERSION).tar.gz" diff --git a/lua-cjson.spec b/lua-cjson.spec new file mode 100644 index 0000000..d5eb0c2 --- /dev/null +++ b/lua-cjson.spec @@ -0,0 +1,48 @@ +%define luaver 5.1 +%define lualibdir %{_libdir}/lua/%{luaver} + +Name: lua-cjson +Version: 1.0 +Release: 1%{?dist} +Summary: JSON support for the Lua language + +Group: Development/Libraries +License: MIT +URL: http://www.kyne.com.au/~mark/software/lua-cjson/ +Source0: http://www.kyne.com.au/~mark/software/lua-cjson/lua-cjson-%{version}.tar.gz +BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) + +BuildRequires: lua >= %{luaver}, lua-devel >= %{luaver} +Requires: lua >= %{luaver} + +%description +CJSON provides fast JSON parsing and encoding functions for Lua. It +allows a Lua application to quickly serialise a data structure to +JSON, or deserialise from JSON to Lua. + +%prep +%setup -q + + +%build +make %{?_smp_mflags} CFLAGS="%{optflags}" LUA_INCLUDE_DIR="%{_includedir}" + + +%install +rm -rf "$RPM_BUILD_ROOT" +make install DESTDIR="$RPM_BUILD_ROOT" LUA_LIB_DIR="%{lualibdir}" + + +%clean +rm -rf "$RPM_BUILD_ROOT" + + +%files +%defattr(-,root,root,-) +%doc LICENSE rfc4627.txt +%{lualibdir}/* + + +%changelog +* Sun May 1 2011 Mark Pulford - 1.0-1 +- Initial package diff --git a/lua_cjson.c b/lua_cjson.c index aaf476d..2cef3a8 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -1004,6 +1004,10 @@ int luaopen_cjson(lua_State *l) lua_pushlightuserdata(l, NULL); lua_setfield(l, -2, "null"); + /* Set cjson.version */ + lua_pushliteral(l, VERSION); + lua_setfield(l, -2, "version"); + /* Return cjson table */ return 1; } -- cgit v1.2.3-55-g6feb