1 -- min version
2 local min_major, min_minor = 5, 1
3 local major, minor = string.match(_VERSION, 'Lua (%d+)\.(%d*)')
5 if (tonumber(major) < min_major or
6 tonumber(major) == min_major and tonumber(minor) < min_minor) then
7 error(string.format(
8 '\n\n*** Lua rrdtool module requires Lua %d.%d or greater. ***\n',
9 min_major, min_minor))
10 os.exit(1)
11 end
12 local lua_version = major .. '.' .. minor
14 local options = arg[1]
15 if options then
16 io.write(string.gsub(options, ' (%S-=)', '\n%1'), '\n\n')
17 end
19 io.stdout:write([[
20 T= rrd
21 # Version
22 LIB_VERSION=0.0.8
23 LUA_VERSION=]],major, '.',minor,[[
26 # set lua include, lib and C installation dirs
27 PKG_CONFIG=$(firstword $(shell which pkg-config))
28 ifeq (pkg-config,$(findstring pkg-config,$(PKG_CONFIG)))
29 LUA_LIBDIR=$(shell pkg-config --variable=INSTALL_CMOD lua$(LUA_VERSION))
30 ifeq (,$(LUA_LIBDIR))
31 $(warning *** couldn't find lua$(LUA_VERSION).pc)
32 else
33 LUA_CFLAGS=$(shell pkg-config --cflags lua$(LUA_VERSION) 2>/dev/null)
34 LUA_LFLAGS=$(shell pkg-config --libs lua$(LUA_VERSION) 2>/dev/null)
35 endif
36 else
37 $(warning couldn't find pkg-config)
38 endif
40 ifeq (,$(LUA_LIBDIR))
41 $(warning *** setting Lua dirs to defaults in src package)
42 LUA_CFLAGS=-I/usr/local/include -I/usr/local/include/lua
43 LUA_LFLAGS=-L/usr/local/lib/lua/$(LUA_VERSION) -llua
44 LUA_LIBDIR=/usr/local/lib/lua/$(LUA_VERSION)
45 endif
47 ]])
49 -- overwrite global LUA_LIBDIR if default lib is set
50 if lib then
51 io.stdout:write([[
52 # override LUA_LIBDIR for site install
53 LUA_LIBDIR=]],lib,[[/$(LUA_VERSION)
54 ]])
55 end
57 io.stdout:write([[
59 # OS dependent
60 LIB_EXT= .so
62 # if this "autoconf" doesn't work for you, set LIB_OPTION for shared
63 # object manually.
64 LD=$(shell ld -V -o /dev/null 2>&1)
65 ifneq (,$(findstring Solaris,$(LD)))
66 # Solaris - tested with 2.6, gcc 2.95.3 20010315 and Solaris ld
67 LIB_OPTION= -G -dy
68 else
69 ifneq (,$(findstring GNU,$(LD)))
70 # GNU ld
71 LIB_OPTION= -shared -dy
72 else
73 $(error couldn't identify your ld. Please set the shared option manually)
74 endif
75 endif
77 RRD_CFLAGS=-I../../src/
78 RRD_LIB_DIR=-L../../src/.libs -lrrd
80 # Choose the PIC option
81 # safest, works on most systems
82 PIC=-fPIC
83 # probably faster, but may not work on your system
84 #PIC=-fpic
86 # Compilation directives
87 OPTIONS= -O3 -Wall ${PIC} -fomit-frame-pointer -pedantic-errors -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings
88 LIBS= $(RRD_LIB_DIR) $(LUA_LFLAGS) -lm
89 CFLAGS= $(OPTIONS) $(LUA_CFLAGS) $(RRD_CFLAGS) -DLIB_VERSION=\"$(LIB_VERSION)\"
90 #CC= gcc
92 LIBNAME= $T-$(LIB_VERSION)$(LIB_EXT)
94 SRCS= rrdlua.c
95 OBJS= rrdlua.o
97 all: $(LIBNAME)
99 lib: $(LIBNAME)
101 *.o: *.c
103 $(LIBNAME): $(OBJS)
104 $(CC) $(CFLAGS) $(LIB_OPTION) $(OBJS) $(LIBS) -o $(LIBNAME)
106 install: $(LIBNAME)
107 mkdir -p $(LUA_LIBDIR)
108 cp $(LIBNAME) $(LUA_LIBDIR)
109 strip $(LUA_LIBDIR)/$(LIBNAME)
110 (cd $(LUA_LIBDIR) ; rm -f $T$(LIB_EXT) ; ln -fs $(LIBNAME) $T$(LIB_EXT))
111 $(POD2MAN) --release=$(VERSION) --center=RRDLua --section=3 rrdlua.pod > $(PREFIX)/man/man3/rrdlua.3
113 test: $(LIBNAME)
114 ln -sf $(LIBNAME) rrd.so
115 lua test.lua
117 clean:
118 rm -f $L $(LIBNAME) $(OBJS) *.so *.rrd *.xml *.png *~
119 ]])