another fix (hopefully last one) to issue #10
[luasnmp.git] / rules.mk
bloba7afdd829397fdde98026539aa7ae2aadf189518
2 include ../../config
4 # System and target names
5 SYSTEM=$(shell uname -o)
6 ifeq ($(SYSTEM), Cygwin)
7 SOEXT=.dll
8 DLIB = $(MODULE)$(SOEXT)
9 DLIBV= $(DLIB)
10 else
11 SOEXT=.so
12 DLIB = $(MODULE)$(SOEXT)
13 DLIBV = $(DLIB).$(VERSION)
14 endif
15 MODL=$(MODULE).lua
16 SLIB = lib$(MODULE).a
18 # Lua
19 LUA=../..
20 LUABIN=$(LUA)/bin/lua50
21 LUAINC=$(LUA)/include
22 LUALIB=$(LUA)/lib
23 LUALUA=$(LUA)/lua
24 LUAWB=$(LUA)/doc/luawb
25 LUAUTIL=$(LUA)/utils
28 # Lua Doc - TODO
29 LUADOCHOME=$(LUAUTIL)/luadoc20
30 LUADOC20=$(LUADOCHOME)/luadoc20.lua
31 LUADOCOPTS=$(shell cat $(LUADOCHOME)/luadoc20/luadoc.config) --noindexpage
32 LUADOCBIN=$(LUABIN) -e "LUADOC_HOME='$(LUADOCHOME)'" $(LUADOC20)
34 # Lua Lint
35 LUALINT=$(LUAUTIL)/lualint/lualint
37 # Lua 5.1 package compatibility
38 LUACOMPAT=$(LUA)/modules/compat-5.1r4
39 COMPATOBJ=$(LUACOMPAT)/compat-5.1.o
40 COMPATINC=$(LUACOMPAT)
42 # Tolua stuff
43 TOLUA=$(LUA)/../tolua++-1.0.6
44 TOLUABIN=$(TOLUA)/bin/tolua++106
45 TOLUALIB=$(TOLUA)/lib
46 TOLUAINC=$(TOLUA)/include/
47 BINDC = $(MODULE)bind.c
48 BINDOBJ = $(MODULE)bind.o
49 BINDCXX = $(MODULE)bind.cpp
50 BINDH = $(MODULE)bind.h
51 BINDHPP = $(MODULE)bind.hpp
52 PKG = $(MODULE).pkg
54 # Compiler
55 ifeq ($(USE_CPLUSPLUS), yes)
56 CC = c++
57 LD = c++
58 else
59 CC = gcc
60 LD = gcc
61 endif
62 CXX = c++
63 INCS = -I$(LUAINC) -I$(TOLUAINC) -I$(LUACOMPAT)
64 CFLAGS = $(INCS) $(WARN) $(USERCFLAGS)
65 CXXFLAGS = $(INCS) $(WARN) $(USERCXXFLAGS)
66 LDFLAGS = -L$(TOLUALIB) $(USERLDFLAGS)
67 WARN = -Wall
69 # Libraries to link against
70 LIBDIR=
71 LIBS=
72 ifeq ($(USE_READLINE), yes)
73 LIBS += -lreadline -lncurses -lhistory
74 endif
75 ifeq ($(USE_TOLUA), yes)
76 LIBDIR += -L$(TOLUALIB)
77 LIBS += -ltolua++106
78 endif
80 # Installation stuff
81 INSTALL_DIR=$(INSTALL_ROOT)
82 INSTALL_SHARE=$(INSTALL_DIR)/share/lua/5.0
83 INSTALL_LIB=$(INSTALL_DIR)/lib/lua/5.0
85 # Documentation stuff
86 SUBST= $(shell cat ../luadoc20/luadoc.config)
88 # TARGETS
90 ifeq ($(LMOD), yes)
91 ifeq ($(CMOD), yes)
92 # Primary module is Lua, Secondary is C
93 mall: $(DLIBV) $(MODULE)/core$(SOEXT)
94 endif
95 else
96 # Primary module is C
97 mall: $(DLIBV) $(DLIB)
98 endif
102 ifeq ($(SYSTEM), Cygwin)
103 $(DLIB): $(OBJS) $(COMPATOBJ) $(CXXOBJS) Makefile.deps Makefile
104 $(LD) -o $@ -shared -Wl,--export-all-symbols,--output-def,$(MODULE).def,--out-implib,$(DLIB).a $(LDFLAGS) $(OBJS) $(COMPATOBJ) $(CXXOBJS) $(LIBDIR) $(LIBS) -L$(LUALIB) -llua$X -llualib$X $(USERLIBDIR) $(USERLIBS)
105 else
106 $(DLIBV): $(OBJS) $(COMPATOBJ) $(CXXOBJS) Makefile.deps Makefile
107 $(LD) -o $@ -shared $(LDFLAGS) $(OBJS) $(COMPATOBJ) $(CXXOBJS) $(LIBDIR) $(LIBS) $(USERLIBDIR) $(USERLIBS)
109 $(DLIB): $(DLIBV)
110 ln -f -s $(DLIBV) $(DLIB)
111 endif
113 $(SLIB): $(OBJS) $(CXXOBJS) Makefile Makefile.deps
114 ar rcu $(SLIB) $(OBJS) $(CXXOBJS)
115 ranlib $(SLIB)
117 $(MODULE)/core$(SOEXT): $(DLIBV)
118 mkdir -p $(MODULE)
119 cp $(DLIBV) $(MODULE)/core$(SOEXT)
121 $(BINDC) $(BINDH): $(PKG)
122 $(TOLUABIN) -1 -o $(BINDC) -H $(BINDH) $(PKG)
124 $(BINDCXX) $(BINDHPP): $(PKG)
125 $(TOLUABIN) -1 -o $(BINDCXX) -H $(BINDHPP) $(PKG)
128 # Generic rules
129 .SUFFIXES: .o .s .c .cpp .cxx .lch .lc .lua
131 .c.o:
132 $(CC) -c $(CFLAGS) -o $@ $<
134 .cxx.cpp:
135 cp $*.cxx $*.cpp
137 .cpp.o:
138 $(CXX) -c $(CXXFLAGS) -o $@ $<
140 .cpp.s:
141 $(CXX) -c -Wa,-alh,-L -dA $(CXXFLAGS) -o $@ $< > $*.L
143 .lua.lc:
144 $(LUACBIN) -o $@ $<
146 .lc.lch:
147 $(BIN2CBIN) $< > $@
149 .PHONY: install webbook clean uclean depend test testa
152 # Entries in the WEBBOOK based documentation
153 webbook:
154 mkdir -p $(LUAWB)/en/modules/$(MODULE)
155 if test -e manual.html; then cp -f manual.html $(LUAWB)/en/modules/$(MODULE); fi
156 if test -e $(MODULE).html; then cp -f $(MODULE).html $(LUAWB)/en/modules/$(MODULE); fi
157 if test -e README; then cp -f README $(LUAWB)/en/modules/$(MODULE); fi
158 if test -e README.leu; then cp -f README $(LUAWB)/en/modules/$(MODULE); fi
159 if test -e $(DOCDIR); then for i in $(DOCS); do cp -f $(DOCDIR)/$$i $(LUAWB)/en/modules/$(MODULE); done; fi
161 # Cleanup stuff
162 muclean: mclean
164 mclean:
165 rm -f $(OBJS) $(CXXOBJS) $(BINDC) $(BINDCXX) $(BINDH) $(BINDHPP) \
166 $(SLIB) $(DLIB).$(VERSION) $(DLIB) $(DLIB).a $(MODULE).def \
167 lib$(DLIB).$(VERSION) lib$(DLIB) \
168 core core.* a.out *~ Makefile.deps \
169 semantic.cache*
170 ifeq ($(LMOD), yes)
171 ifeq ($(CMOD), yes)
172 rm -rf $(MODULE)
173 endif
174 endif
177 # Dependency stuff
178 mdepend: Makefile.deps
180 ifeq ($(USE_BINDDEPEND), yes)
181 Makefile.deps: $(BINDH) $(BINDHPP) $(OBJS:.o=.c) $(CXXOBJS:.o=.cpp) $(HDRS)
182 else
183 Makefile.deps:$(OBJS:.o=.c) $(CXXOBJS:.o=.cpp) $(HDRS)
184 endif
185 rm -f Makefile.deps
186 test -z "$(CXXOBJS)" || $(CXX) -MM $(CXXFLAGS) $(CXXOBJS:.o=.cpp) >> Makefile.deps
187 test -z "$(OBJS)" || $(CC) -MM $(CFLAGS) $(OBJS:.o=.c) >> Makefile.deps
189 # Testing
190 mtest:
191 @if test -e test.lua; then \
192 $(LUABIN) -l $(MODULE) test.lua $(LOG); \
195 mtesta:
196 ifeq ($(SYSTEM), Cygwin)
197 @if test -e test.lua; then $(LUABIN) -e "LUA_LIBNAME='lib?.dll'" -l $(MODULE) test.lua; fi
198 else
199 @if test -e test.lua; then $(LUABIN) -e "LUA_LIBNAME='lib?.so'" -l $(MODULE) test.lua; fi
200 endif
203 # Documentation
204 mdoc:$(MODULE).html
206 $(MODULE).html:
207 $(LUADOCBIN) $(LUADOCOPTS) -d . $(MODULE).lua
209 mclean-doc:
210 rm -f $(MODULE).html
212 # Installation
213 minstall:
214 ifeq ($(LMOD), yes)
215 # Install <module>.lua if LMOD == yes
216 mkdir -p $(INSTALL_SHARE)
217 cp $(MODULE).lua $(INSTALL_SHARE)
218 ifeq ($(CMOD), yes)
219 # Install core.<soext> if CMOD == yes
220 mkdir -p $(INSTALL_LIB)/$(MODULE)
221 cp $(DLIBV) $(INSTALL_LIB)/$(MODULE)/core$(SOEXT)
222 endif
224 else
226 ifeq ($(SYSTEM), Cygwin)
227 # Cygwin install
228 # Install <module>.dll if LMOD != yes
229 mkdir -p $(INSTALL_LIB)
230 cp $(DLIB) $(INSTALL_LIB)
231 # if test -e $(MODULE).lua; then \
232 # mkdir -p $(INSTALL_SHARE); \
233 # cp $(MODULE).lua $(INSTALL_SHARE); \
234 # fi
235 else
236 # Linux install
237 # Install <module>.so if LMOD != yes
238 mkdir -p $(INSTALL_LIB)
239 cp $(DLIBV) $(INSTALL_LIB)/$(DLIB)
240 # if test -e $(MODULE).lua; then \
241 # mkdir -p $(INSTALL_SHARE); \
242 # cp $(MODULE).lua $(INSTALL_SHARE); \
243 # fi
244 endif
245 endif
246 # Finally, do a module private install
248 muninstall:
249 cd $(INSTALL_LIB); rm -f $(DLIB) $(SLIB)
250 cd $(INSTALL_LIB); rm -rf $(MODULE)
251 cd $(INSTALL_SHARE); rm -f $(MODULE).lua
253 show:
254 @echo "DLIB = "$(DLIB)
255 @echo "DLIBV = "$(DLIBV)
257 type:
258 ifeq ($(CMOD), yes)
259 ifeq ($(LMOD), yes)
260 @echo "C LUA"
261 else
262 @echo "C"
263 endif
264 endif
265 ifeq ($(LMOD), yes)
266 ifneq ($(CMOD), yes)
267 @echo "LUA"
268 endif
269 endif
271 ifeq ($(CMOD), yes)
272 ifneq ($(USE_DEPS), no)
273 -include Makefile.deps
274 endif
275 endif