Debian Codegraph @

src/makefile

raw
1 # luasocket src/makefile
2 #
3 # Definitions in this section can be overriden on the command line or in the
4 # environment.
5 #
6 # These are equivalent:
7 #
8 # export PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw
9 # make
10 #
11 # and
12 #
13 # make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw
14
15 # PLAT: linux macosx win32 win64 mingw
16 # platform to build for
17 PLAT?=linux
18
19 # LUAV: 5.1 5.2 5.3 5.4
20 # lua version to build against
21 LUAV?=5.1
22
23 # MYCFLAGS: to be set by user if needed
24 MYCFLAGS?=
25
26 # MYLDFLAGS: to be set by user if needed
27 MYLDFLAGS?=
28
29 # DEBUG: NODEBUG DEBUG
30 # debug mode causes luasocket to collect and returns timing information useful
31 # for testing and debugging luasocket itself
32 DEBUG?=NODEBUG
33
34 # where lua headers are found for macosx builds
35 # LUAINC_macosx:
36 # /opt/local/include
37 LUAINC_macosx_base?=/opt/local/include
38 LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) $(LUAINC_macosx_base)/lua$(LUAV) $(LUAINC_macosx_base)/lua-$(LUAV)
39
40 # FIXME default should this default to fink or to macports?
41 # What happens when more than one Lua version is installed?
42 LUAPREFIX_macosx?=/opt/local
43 CDIR_macosx?=lib/lua/$(LUAV)
44 LDIR_macosx?=share/lua/$(LUAV)
45
46 # LUAINC_linux:
47 # /usr/include/lua$(LUAV)
48 # /usr/local/include
49 # /usr/local/include/lua$(LUAV)
50 # where lua headers are found for linux builds
51 LUAINC_linux_base?=/usr/include
52 LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) $(LUAINC_linux_base)/lua$(LUAV)
53 LUAPREFIX_linux?=/usr/local
54 CDIR_linux?=lib/lua/$(LUAV)
55 LDIR_linux?=share/lua/$(LUAV)
56
57 # LUAINC_freebsd:
58 # /usr/local/include/lua$(LUAV)
59 # where lua headers are found for freebsd builds
60 LUAINC_freebsd_base?=/usr/local/include/
61 LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua/$(LUAV) $(LUAINC_freebsd_base)/lua$(LUAV)
62 LUAPREFIX_freebsd?=/usr/local/
63 CDIR_freebsd?=lib/lua/$(LUAV)
64 LDIR_freebsd?=share/lua/$(LUAV)
65
66 # where lua headers are found for mingw builds
67 # LUAINC_mingw:
68 # /opt/local/include
69 LUAINC_mingw_base?=/usr/include
70 LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) $(LUAINC_mingw_base)/lua$(LUAV)
71 LUALIB_mingw_base?=/usr/bin
72 LUALIB_mingw?=$(LUALIB_mingw_base)/lua/$(LUAV)/lua$(subst .,,$(LUAV)).dll
73 LUAPREFIX_mingw?=/usr
74 CDIR_mingw?=lua/$(LUAV)
75 LDIR_mingw?=lua/$(LUAV)/lua
76
77
78 # LUAINC_win32:
79 # LUALIB_win32:
80 # where lua headers and libraries are found for win32 builds
81 LUAPREFIX_win32?=
82 LUAINC_win32?=$(LUAPREFIX_win32)/include/lua/$(LUAV) $(LUAPREFIX_win32)/include/lua$(LUAV)
83 PLATFORM_win32?=Release
84 CDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32)
85 LDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32)/lua
86 LUALIB_win32?=$(LUAPREFIX_win32)/lib/lua/$(LUAV)/$(PLATFORM_win32)
87 LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib
88
89 # LUAINC_win64:
90 # LUALIB_win64:
91 # where lua headers and libraries are found for win64 builds
92 LUAPREFIX_win64?=
93 LUAINC_win64?=$(LUAPREFIX_win64)/include/lua/$(LUAV) $(LUAPREFIX_win64)/include/lua$(LUAV)
94 PLATFORM_win64?=x64/Release
95 CDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64)
96 LDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64)/lua
97 LUALIB_win64?=$(LUAPREFIX_win64)/lib/lua/$(LUAV)/$(PLATFORM_win64)
98 LUALIBNAME_win64?=lua$(subst .,,$(LUAV)).lib
99
100
101 # LUAINC_solaris:
102 LUAINC_solaris_base?=/usr/include
103 LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV) $(LUAINC_solaris_base)/lua$(LUAV)
104 LUAPREFIX_solaris?=/usr/local
105 CDIR_solaris?=lib/lua/$(LUAV)
106 LDIR_solaris?=share/lua/$(LUAV)
107
108 # prefix: /usr/local /usr /opt/local /sw
109 # the top of the default install tree
110 prefix?=$(LUAPREFIX_$(PLAT))
111
112 CDIR?=$(CDIR_$(PLAT))
113 LDIR?=$(LDIR_$(PLAT))
114
115 # DESTDIR: (no default)
116 # used by package managers to install into a temporary destination
117 DESTDIR?=
118
119 #------
120 # Definitions below can be overridden on the make command line, but
121 # shouldn't have to be.
122
123
124 #------
125 # Install directories
126 #
127
128 INSTALL_DIR=install -d
129 INSTALL_DATA=install -m644
130 INSTALL_EXEC=install
131 INSTALL_TOP=$(DESTDIR)$(prefix)
132
133 INSTALL_TOP_LDIR=$(INSTALL_TOP)/$(LDIR)
134 INSTALL_TOP_CDIR=$(INSTALL_TOP)/$(CDIR)
135
136 INSTALL_SOCKET_LDIR=$(INSTALL_TOP_LDIR)/socket
137 INSTALL_SOCKET_CDIR=$(INSTALL_TOP_CDIR)/socket
138 INSTALL_MIME_LDIR=$(INSTALL_TOP_LDIR)/mime
139 INSTALL_MIME_CDIR=$(INSTALL_TOP_CDIR)/mime
140
141 print:
142 @echo PLAT=$(PLAT)
143 @echo LUAV=$(LUAV)
144 @echo DEBUG=$(DEBUG)
145 @echo prefix=$(prefix)
146 @echo LUAINC_$(PLAT)=$(LUAINC_$(PLAT))
147 @echo LUALIB_$(PLAT)=$(LUALIB_$(PLAT))
148 @echo INSTALL_TOP_CDIR=$(INSTALL_TOP_CDIR)
149 @echo INSTALL_TOP_LDIR=$(INSTALL_TOP_LDIR)
150 @echo CFLAGS=$(CFLAGS)
151 @echo LDFLAGS=$(LDFLAGS)
152
153 #------
154 # Supported platforms
155 #
156 PLATS= macosx linux win32 win64 mingw solaris
157
158 #------
159 # Compiler and linker settings
160 # for Mac OS X
161 SO_macosx=so
162 O_macosx=o
163 CC_macosx=gcc
164 DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN
165 CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common
166 LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o
167 LD_macosx=gcc
168 SOCKET_macosx=usocket.o
169
170 #------
171 # Compiler and linker settings
172 # for Linux
173 SO_linux=so
174 O_linux=o
175 CC_linux=gcc
176 DEF_linux=-DLUASOCKET_$(DEBUG)
177 CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
178 -Wimplicit -O2 -ggdb3 -fpic
179 LDFLAGS_linux=-O -shared -fpic -o
180 LD_linux=gcc
181 SOCKET_linux=usocket.o
182
183 #------
184 # Compiler and linker settings
185 # for FreeBSD
186 SO_freebsd=so
187 O_freebsd=o
188 CC_freebsd=gcc
189 DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN
190 CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
191 -Wimplicit -O2 -ggdb3 -fpic
192 LDFLAGS_freebsd=-O -shared -fpic -o
193 LD_freebsd=gcc
194 SOCKET_freebsd=usocket.o
195
196 #------
197 # Compiler and linker settings
198 # for Solaris
199 SO_solaris=so
200 O_solaris=o
201 CC_solaris=gcc
202 DEF_solaris=-DLUASOCKET_$(DEBUG)
203 CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \
204 -Wimplicit -O2 -ggdb3 -fpic
205 LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o
206 LD_solaris=gcc
207 SOCKET_solaris=usocket.o
208
209 #------
210 # Compiler and linker settings
211 # for MingW
212 SO_mingw=dll
213 O_mingw=o
214 CC_mingw=gcc
215 DEF_mingw= -DLUASOCKET_$(DEBUG) \
216 -DWINVER=0x0501
217 CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common
218 LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
219 LD_mingw=gcc
220 SOCKET_mingw=wsocket.o
221
222
223 #------
224 # Compiler and linker settings
225 # for Win32
226 SO_win32=dll
227 O_win32=obj
228 CC_win32=cl
229 DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \
230 //D "_CRT_SECURE_NO_WARNINGS" \
231 //D "_WINDLL" \
232 //D "LUASOCKET_$(DEBUG)"
233 CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo
234 LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \
235 //MANIFEST //MANIFESTFILE:"intermediate.manifest" \
236 /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \
237 //SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \
238 //MACHINE:X86 /LIBPATH:"$(LUALIB)" \
239 $(LUALIBNAME_win32) ws2_32.lib //OUT:
240
241 LD_win32=cl
242 SOCKET_win32=wsocket.obj
243
244 #------
245 # Compiler and linker settings
246 # for Win64
247 SO_win64=dll
248 O_win64=obj
249 CC_win64=cl
250 DEF_win64= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \
251 //D "_CRT_SECURE_NO_WARNINGS" \
252 //D "_WINDLL" \
253 //D "LUASOCKET_$(DEBUG)"
254 CFLAGS_win64=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo
255 LDFLAGS_win64= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \
256 //MANIFEST //MANIFESTFILE:"intermediate.manifest" \
257 /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \
258 //SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \
259 /LIBPATH:"$(LUALIB)" \
260 $(LUALIBNAME_win64) ws2_32.lib //OUT:
261
262 LD_win64=cl
263 SOCKET_win64=wsocket.obj
264
265 .SUFFIXES: .obj
266
267 .c.obj:
268 $(CC) $(CFLAGS) //Fo"$@" //c $<
269
270 #------
271 # Output file names
272 #
273 SO=$(SO_$(PLAT))
274 O=$(O_$(PLAT))
275 SOCKET_V=3.0.0
276 MIME_V=1.0.3
277 SOCKET_SO=socket-$(SOCKET_V).$(SO)
278 MIME_SO=mime-$(MIME_V).$(SO)
279 UNIX_SO=unix.$(SO)
280 SERIAL_SO=serial.$(SO)
281 SOCKET=$(SOCKET_$(PLAT))
282
283 #------
284 # Settings selected for platform
285 #
286 CC=$(CC_$(PLAT))
287 DEF=$(DEF_$(PLAT))
288 CFLAGS=$(MYCFLAGS) $(CFLAGS_$(PLAT))
289 LDFLAGS=$(MYLDFLAGS) $(LDFLAGS_$(PLAT))
290 LD=$(LD_$(PLAT))
291 LUAINC= $(LUAINC_$(PLAT))
292 LUALIB= $(LUALIB_$(PLAT))
293
294 #------
295 # Modules belonging to socket-core
296 #
297 SOCKET_OBJS= \
298 luasocket.$(O) \
299 timeout.$(O) \
300 buffer.$(O) \
301 io.$(O) \
302 auxiliar.$(O) \
303 compat.$(O) \
304 options.$(O) \
305 inet.$(O) \
306 $(SOCKET) \
307 except.$(O) \
308 select.$(O) \
309 tcp.$(O) \
310 udp.$(O)
311
312 #------
313 # Modules belonging mime-core
314 #
315 MIME_OBJS= \
316 mime.$(O) \
317 compat.$(O)
318
319 #------
320 # Modules belonging unix (local domain sockets)
321 #
322 UNIX_OBJS=\
323 buffer.$(O) \
324 auxiliar.$(O) \
325 options.$(O) \
326 timeout.$(O) \
327 io.$(O) \
328 usocket.$(O) \
329 unixstream.$(O) \
330 unixdgram.$(O) \
331 compat.$(O) \
332 unix.$(O)
333
334 #------
335 # Modules belonging to serial (device streams)
336 #
337 SERIAL_OBJS=\
338 buffer.$(O) \
339 compat.$(O) \
340 auxiliar.$(O) \
341 options.$(O) \
342 timeout.$(O) \
343 io.$(O) \
344 usocket.$(O) \
345 serial.$(O)
346
347 #------
348 # Files to install
349 #
350 TO_SOCKET_LDIR= \
351 http.lua \
352 url.lua \
353 tp.lua \
354 ftp.lua \
355 headers.lua \
356 smtp.lua
357
358 TO_TOP_LDIR= \
359 ltn12.lua \
360 socket.lua \
361 mime.lua
362
363 #------
364 # Targets
365 #
366 default: $(PLAT)
367
368
369 freebsd:
370 $(MAKE) all-unix PLAT=freebsd
371
372 macosx:
373 $(MAKE) all-unix PLAT=macosx
374
375 win32:
376 $(MAKE) all PLAT=win32
377
378 win64:
379 $(MAKE) all PLAT=win64
380
381 linux:
382 $(MAKE) all-unix PLAT=linux
383
384 mingw:
385 $(MAKE) all PLAT=mingw
386
387 solaris:
388 $(MAKE) all-unix PLAT=solaris
389
390 none:
391 @echo "Please run"
392 @echo " make PLATFORM"
393 @echo "where PLATFORM is one of these:"
394 @echo " $(PLATS)"
395
396 all: $(SOCKET_SO) $(MIME_SO)
397
398 $(SOCKET_SO): $(SOCKET_OBJS)
399 $(LD) $(SOCKET_OBJS) $(LDFLAGS)$@
400
401 $(MIME_SO): $(MIME_OBJS)
402 $(LD) $(MIME_OBJS) $(LDFLAGS)$@
403
404 all-unix: all $(UNIX_SO) $(SERIAL_SO)
405
406 $(UNIX_SO): $(UNIX_OBJS)
407 $(LD) $(UNIX_OBJS) $(LDFLAGS)$@
408
409 $(SERIAL_SO): $(SERIAL_OBJS)
410 $(LD) $(SERIAL_OBJS) $(LDFLAGS)$@
411
412 install:
413 $(INSTALL_DIR) $(INSTALL_TOP_LDIR)
414 $(INSTALL_DATA) $(TO_TOP_LDIR) $(INSTALL_TOP_LDIR)
415 $(INSTALL_DIR) $(INSTALL_SOCKET_LDIR)
416 $(INSTALL_DATA) $(TO_SOCKET_LDIR) $(INSTALL_SOCKET_LDIR)
417 $(INSTALL_DIR) $(INSTALL_SOCKET_CDIR)
418 $(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_CDIR)/core.$(SO)
419 $(INSTALL_DIR) $(INSTALL_MIME_CDIR)
420 $(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_CDIR)/core.$(SO)
421
422 install-unix: install
423 $(INSTALL_EXEC) $(UNIX_SO) $(INSTALL_SOCKET_CDIR)/$(UNIX_SO)
424 $(INSTALL_EXEC) $(SERIAL_SO) $(INSTALL_SOCKET_CDIR)/$(SERIAL_SO)
425
426 local:
427 $(MAKE) install INSTALL_TOP_CDIR=.. INSTALL_TOP_LDIR=..
428
429 clean:
430 rm -f $(SOCKET_SO) $(SOCKET_OBJS) $(SERIAL_OBJS)
431 rm -f $(MIME_SO) $(UNIX_SO) $(SERIAL_SO) $(MIME_OBJS) $(UNIX_OBJS)
432
433 .PHONY: all $(PLATS) default clean echo none
434
435 #------
436 # List of dependencies
437 #
438 compat.$(O): compat.c compat.h
439 auxiliar.$(O): auxiliar.c auxiliar.h
440 buffer.$(O): buffer.c buffer.h io.h timeout.h
441 except.$(O): except.c except.h
442 inet.$(O): inet.c inet.h socket.h io.h timeout.h usocket.h
443 io.$(O): io.c io.h timeout.h
444 luasocket.$(O): luasocket.c luasocket.h auxiliar.h except.h \
445 timeout.h buffer.h io.h inet.h socket.h usocket.h tcp.h \
446 udp.h select.h
447 mime.$(O): mime.c mime.h
448 options.$(O): options.c auxiliar.h options.h socket.h io.h \
449 timeout.h usocket.h inet.h
450 select.$(O): select.c socket.h io.h timeout.h usocket.h select.h
451 serial.$(O): serial.c auxiliar.h socket.h io.h timeout.h usocket.h \
452 options.h unix.h buffer.h
453 tcp.$(O): tcp.c auxiliar.h socket.h io.h timeout.h usocket.h \
454 inet.h options.h tcp.h buffer.h
455 timeout.$(O): timeout.c auxiliar.h timeout.h
456 udp.$(O): udp.c auxiliar.h socket.h io.h timeout.h usocket.h \
457 inet.h options.h udp.h
458 unix.$(O): unix.c auxiliar.h socket.h io.h timeout.h usocket.h \
459 options.h unix.h buffer.h
460 usocket.$(O): usocket.c socket.h io.h timeout.h usocket.h
461 wsocket.$(O): wsocket.c socket.h io.h timeout.h usocket.h