2 print(string.format('%s %s %s\n', '# Makefile generated by', _VERSION, 'from Makefile.lua.\n'))
4 local opts = {
5 LUA = '@LUA@',
6 LUA_MAJOR = '@LUA_MAJOR@',
7 LUA_MINOR = '@LUA_MINOR@',
8 LUA_HAVE_COMPAT51 = '@LUA_HAVE_COMPAT51@',
9 LUA_RRD_LANGPREF = '@LUA_RRD_LANGPREF@',
10 LUA_CFLAGS = '@LUA_CFLAGS@',
11 LUA_LFLAGS = '@LUA_LFLAGS@',
12 LUA_SRCS = '@LUA_SRCS@',
13 LUA_OBJS = '@LUA_OBJS@',
14 LUA_INSTALL_CMOD = '@LUA_INSTALL_CMOD@',
15 CC = '@CC@',
16 }
18 -- doesn't preserve key order, but it's OK
19 for k, v in pairs(opts) do
20 print(string.format('%s=%s', k, v))
21 end
23 local lua_ver = opts['LUA_MAJOR'] .. '.' .. opts['LUA_MINOR']
25 print([[
27 T= rrd
28 # Version
29 LIB_VERSION=0.0.9
31 # OS dependent
32 LIB_EXT= .so
34 LIBNAME= $T-$(LIB_VERSION)$(LIB_EXT)
36 RRD_CFLAGS=-I../../src
37 RRD_LIB_DIR=-L../../src/.libs -lrrd
39 # Set shared object options to what your platform requires
40 # For Solaris - tested with 2.6, gcc 2.95.3 20010315 and Solaris ld:
41 # LIB_OPTION= -G -dy
42 # For GNU ld:
43 LIB_OPTION= -shared -dy
45 # Choose the PIC option
46 # safest, works on most systems
47 PIC=-fPIC
48 # probably faster, but may not work on your system
49 #PIC=-fpic
51 # Compilation directives
52 OPTIONS= -O3 -Wall $(PIC) -fomit-frame-pointer -pedantic-errors -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings
53 LIBS= $(RRD_LIB_DIR) $(LUA_LFLAGS) -lm
54 CFLAGS= $(OPTIONS) $(LUA_CFLAGS) $(RRD_CFLAGS) -DLIB_VERSION=\"$(LIB_VERSION)\" -DLUA$(LUA_MAJOR)$(LUA_MINOR) -D$(LUA_HAVE_COMPAT51)
56 all: $(LIBNAME)
58 lib: $(LIBNAME)
60 *.o: *.c
62 $(LIBNAME): $(LUA_OBJS)
63 $(CC) $(CFLAGS) $(LIB_OPTION) $(LUA_OBJS) $(LIBS) -o $(LIBNAME)
65 install: $(LIBNAME)
66 mkdir -p $(LUA_INSTALL_CMOD)
67 cp $(LIBNAME) $(LUA_INSTALL_CMOD)
68 #strip $(LUA_INSTALL_CMOD)/$(LIBNAME)
69 (cd $(LUA_INSTALL_CMOD) ; rm -f $T$(LIB_EXT) ; ln -fs $(LIBNAME) $T$(LIB_EXT))]])
70 if lua_ver == '5.0' and opts['LUA_HAVE_COMPAT51'] ~= 'HAVE_COMPAT51' then
71 print([[
72 mkdir -p $(LUA_RRD_LANGPREF)/5.0
73 cp compat-5.1r5/compat-5.1.lua $(LUA_RRD_LANGPREF)/5.0
74 ]])
75 end
77 print([[
79 test.lua: $(LIBNAME) test.lua.bottom
80 @echo "-- Created by Makefile." > test.lua
81 @echo "-- Test script adapted from the one in the Ruby binding." > test.lua
82 @echo >> test.lua]])
83 if lua_ver == '5.0' then
84 print([[
85 @echo "--- compat-5.1.lua is only required for Lua 5.0 ----------" >> test.lua]])
87 if opts['LUA_HAVE_COMPAT51'] ~= 'HAVE_COMPAT51' then
88 print([[
89 @echo "original_LUA_PATH = LUA_PATH" >> test.lua
90 @echo "-- try only compat-5.1.lua installed with RRDtool package" >> test.lua
91 @echo "LUA_PATH = '$(LUA_RRD_LANGPREF)/5.0/?.lua'" >> test.lua]])
92 end
93 print([[
94 @echo "local r = pcall(require, 'compat-5.1')" >> test.lua
95 @echo "if not r then" >> test.lua
96 @echo " print('** compat-5.1.lua not found')" >> test.lua
97 @echo " os.exit(1)" >> test.lua
98 @echo "end" >> test.lua]])
100 if opts['LUA_HAVE_COMPAT51'] ~= 'HAVE_COMPAT51' then
101 print([[
102 @echo "LUA_PATH = original_LUA_PATH" >> test.lua
103 @echo "original_LUA_PATH = nil" >> test.lua]])
104 end
105 print([[
106 @echo "----------------------------------------------------------" >> test.lua
107 @echo >> test.lua]])
108 end
109 if opts['LUA_RRD_LANGPREF'] .. '/' .. lua_ver == opts['LUA_INSTALL_CMOD'] then
110 print([[
111 @echo "package.cpath = '$(LUA_INSTALL_CMOD)/?.so;' .. package.cpath" >> test.lua]])
112 end
113 print([[
114 @cat test.lua.bottom >> test.lua
116 test: test.lua
117 $(LUA) test.lua
119 clean:
120 rm -f $(LIBNAME) $(LUA_OBJS) test.lua *.so *.rrd *.xml *.png *~
121 ]])