66a0e5a2e71a963ed6aae45051cf9e5fd4f9f5dc
[project/luci.git] / libs / lmo / standalone.mk
1 LUAC = luac
2 LUAC_OPTIONS = -s
3 LUA_TARGET ?= source
4
5 LUA_MODULEDIR = /usr/local/share/lua/5.1
6 LUA_LIBRARYDIR = /usr/local/lib/lua/5.1
7
8 OS ?= $(shell uname)
9
10 LUA_SHLIBS = $(shell pkg-config --silence-errors --libs lua5.1 || pkg-config --silence-errors --libs lua-5.1 || pkg-config --silence-errors --libs lua)
11 LUA_LIBS = $(if $(LUA_SHLIBS),$(LUA_SHLIBS),$(firstword $(wildcard /usr/lib/liblua.a /usr/local/lib/liblua.a /opt/local/lib/liblua.a)))
12 LUA_CFLAGS = $(shell pkg-config --silence-errors --cflags lua5.1 || pkg-config --silence-errors --cflags lua-5.1 || pkg-config --silence-errors --cflags lua)
13
14 CC = gcc
15 AR = ar
16 RANLIB = ranlib
17 CFLAGS = -O2
18 FPIC = -fPIC
19 EXTRA_CFLAGS = --std=gnu99
20 WFLAGS = -Wall -Werror -pedantic
21 CPPFLAGS =
22 COMPILE = $(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(WFLAGS)
23 ifeq ($(OS),Darwin)
24 SHLIB_FLAGS = -bundle -undefined dynamic_lookup
25 else
26 SHLIB_FLAGS = -shared
27 endif
28 LINK = $(CC) $(LDFLAGS)
29
30 .PHONY: all build compile luacompile luasource clean luaclean
31
32 all: build
33
34 build: luabuild gccbuild
35
36 luabuild: lua$(LUA_TARGET)
37
38 gccbuild: compile
39 compile:
40
41 clean: luaclean
42
43 luasource:
44 mkdir -p dist$(LUA_MODULEDIR)
45 cp -pR root/* dist 2>/dev/null || true
46 cp -pR lua/* dist$(LUA_MODULEDIR) 2>/dev/null || true
47 for i in $$(find dist -name .svn); do rm -rf $$i || true; done
48
49 luastrip: luasource
50 for i in $$(find dist -type f -name '*.lua'); do perl -e 'undef $$/; open( F, "< $$ARGV[0]" ) || die $$!; $$src = <F>; close F; $$src =~ s/--\[\[.*?\]\](--)?//gs; $$src =~ s/^\s*--.*?\n//gm; open( F, "> $$ARGV[0]" ) || die $$!; print F $$src; close F' $$i; done
51
52 luacompile: luasource
53 for i in $$(find dist -name *.lua -not -name debug.lua); do $(LUAC) $(LUAC_OPTIONS) -o $$i $$i; done
54
55 luaclean:
56 rm -rf dist