aboutsummaryrefslogtreecommitdiff
path: root/src/makefile
blob: 33519970c78aca441aa90d9e83e8e92e6275a90d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
PLAT = none
INSTALL_DATA=cp
INSTALL_EXEC=cp
INSTALL_TOP= /opt/local
LUAINC= $(LUAINC_$(PLAT))

#------
# Install directories
#
INSTALL_TOP_SHARE=$(INSTALL_TOP)/share/lua/5.1
INSTALL_TOP_LIB=$(INSTALL_TOP)/lib/lua/5.1
INSTALL_SOCKET_SHARE=$(INSTALL_TOP_SHARE)/socket
INSTALL_SOCKET_LIB=$(INSTALL_TOP_LIB)/socket
INSTALL_MIME_SHARE=$(INSTALL_TOP_SHARE)/mime
INSTALL_MIME_LIB=$(INSTALL_TOP_LIB)/mime

#------
# Output file names
#
EXT=so
SOCKET_V=2.0.3
MIME_V=1.0.3
SOCKET_SO=socket.$(EXT).$(SOCKET_V)
MIME_SO=mime.$(EXT).$(MIME_V)
UNIX_SO=unix.$(EXT)

#------
# Compiler and linker settings
# for Mac OS X
LUAINC_macosx= -I/opt/local/include
CC_macosx=gcc
DEF_macosx= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN \
	-DLUASOCKET_API='__attribute__((visibility("default")))' \
	-DMIME_API='__attribute__((visibility("default")))'
CFLAGS_macosx= $(LUAINC) $(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common \
	-fvisibility=hidden
LDFLAGS_macosx= -bundle -undefined dynamic_lookup
LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc

#------
# Compiler and linker settings
# for Linux
LUAINC_linux= -I/usr/local/include/lua5.1
CC_linux=gcc
DEF_linux=-DLUASOCKET_DEBUG \
	-DLUASOCKET_API='__attribute__((visibility("default")))' \
	-DMIME_API='__attribute__((visibility("default")))'
CFLAGS_linux= $(LUAINC) $(DEF) -pedantic -Wall -O2 -fpic \
	-fvisibility=hidden
LDFLAGS_linux=-O -shared -fpic
LD_linux= gcc

#------
# Settings selected for platform
#
CC=$(CC_$(PLAT))
DEF=$(DEF_$(PLAT))
CFLAGS=$(CFLAGS_$(PLAT))
LDFLAGS=$(LDFLAGS_$(PLAT))
LD=$(LD_$(PLAT))

#------
# Modules belonging to socket-core
#
SOCKET_OBJS= \
	luasocket.o \
	timeout.o \
	buffer.o \
	io.o \
    auxiliar.o \
	options.o \
	inet.o \
	usocket.o \
	except.o \
	select.o \
	tcp.o \
	udp.o

#------
# Modules belonging mime-core
#
MIME_OBJS= \
	mime.o

#------
# Modules belonging unix (local domain sockets)
#
UNIX_OBJS:=\
	buffer.o \
	auxiliar.o \
	options.o \
	timeout.o \
	io.o \
	usocket.o \
	unix.o

#------
# Files to install
#
TO_SOCKET_SHARE:= \
	http.lua \
	url.lua \
	tp.lua \
	ftp.lua \
	headers.lua \
	smtp.lua

TO_TOP_SHARE:= \
	ltn12.lua \
	socket.lua \
	mime.lua

default: $(PLAT)

macosx:
	$(MAKE) all PLAT=macosx

linux:
	$(MAKE) all PLAT=linux

none:
	@echo "Please choose a platform:"
	@echo "   $(PLATS)"

all: $(SOCKET_SO) $(MIME_SO)

$(SOCKET_SO): $(SOCKET_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(SOCKET_OBJS)

$(MIME_SO): $(MIME_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(MIME_OBJS)

$(UNIX_SO): $(UNIX_OBJS)
	$(LD) $(LDFLAGS) -o $@ $(UNIX_OBJS)

install: 
	mkdir -p $(INSTALL_TOP_SHARE)
	$(INSTALL_DATA) $(TO_TOP_SHARE) $(INSTALL_TOP_SHARE)
	mkdir -p $(INSTALL_SOCKET_SHARE)
	$(INSTALL_DATA) $(TO_SOCKET_SHARE) $(INSTALL_SOCKET_SHARE)
	mkdir -p $(INSTALL_SOCKET_LIB)
	$(INSTALL_EXEC) $(SOCKET_SO) $(INSTALL_SOCKET_LIB)/core.$(EXT)
	mkdir -p $(INSTALL_MIME_LIB)
	$(INSTALL_EXEC) $(MIME_SO) $(INSTALL_MIME_LIB)/core.$(EXT)

local:
	$(MAKE) install INSTALL_TOP_LIB=.. INSTALL_TOP_SHARE=..

clean:
	rm -f $(SOCKET_SO) $(SOCKET_OBJS)
	rm -f $(MIME_SO) $(UNIX_SO) $(MIME_OBJS) $(UNIX_OBJS)

.PHONY: all $(PLATS) default clean echo none

#------
# List of dependencies
#
auxiliar.o: auxiliar.c auxiliar.h
buffer.o: buffer.c buffer.h io.h timeout.h
except.o: except.c except.h
inet.o: inet.c inet.h socket.h io.h timeout.h usocket.h
io.o: io.c io.h timeout.h
luasocket.o: luasocket.c luasocket.h auxiliar.h except.h \
	timeout.h buffer.h io.h inet.h socket.h usocket.h tcp.h \
	udp.h select.h
mime.o: mime.c mime.h
options.o: options.c auxiliar.h options.h socket.h io.h \
	timeout.h usocket.h inet.h
select.o: select.c socket.h io.h timeout.h usocket.h select.h
tcp.o: tcp.c auxiliar.h socket.h io.h timeout.h usocket.h \
	inet.h options.h tcp.h buffer.h
timeout.o: timeout.c auxiliar.h timeout.h
udp.o: udp.c auxiliar.h socket.h io.h timeout.h usocket.h \
	inet.h options.h udp.h
unix.o: unix.c auxiliar.h socket.h io.h timeout.h usocket.h \
	options.h unix.h buffer.h
usocket.o: usocket.c socket.h io.h timeout.h usocket.h
wsocket.o: wsocket.c socket.h io.h timeout.h usocket.h