xref: /unit/auto/make (revision 1710:e598cd15bd91)
1
2# Copyright (C) Igor Sysoev
3# Copyright (C) Valentin V. Bartenev
4# Copyright (C) NGINX, Inc.
5
6. auto/cc/deps
7
8$echo "creating $NXT_MAKEFILE"
9
10mkdir -p $NXT_BUILD_DIR/src \
11         $NXT_BUILD_DIR/src/test
12
13
14cat << END > $NXT_MAKEFILE
15
16CC =			$CC
17AR =			$AR
18
19CFLAGS = 		$NXT_CFLAGS $NXT_CC_OPT $CFLAGS
20
21NXT_EXEC_LINK =		$NXT_EXEC_LINK $NXT_LD_OPT
22NXT_SHARED_LOCAL_LINK =	$NXT_SHARED_LOCAL_LINK $NXT_LD_OPT
23NXT_MODULE_LINK =	$NXT_MODULE_LINK
24
25all: $NXT_DAEMON
26
27.PHONY: $NXT_DAEMON
28$NXT_DAEMON: $NXT_BUILD_DIR/$NXT_DAEMON
29
30END
31
32
33# The include paths list.
34
35$echo -n "NXT_LIB_INCS =" >> $NXT_MAKEFILE
36
37for nxt_inc in src $NXT_BUILD_DIR
38do
39    $echo -n " -I $nxt_inc" >> $NXT_MAKEFILE
40done
41
42$echo >> $NXT_MAKEFILE
43$echo >> $NXT_MAKEFILE
44
45
46# Library object files list.
47
48$echo "NXT_LIB_OBJS = \\" >> $NXT_MAKEFILE
49
50for nxt_src in $NXT_LIB_SRCS
51do
52    nxt_obj=${nxt_src%.c}.o
53    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
54done
55
56$echo >> $NXT_MAKEFILE
57
58$echo "NXT_LIB_UNIT_OBJS = \\" >> $NXT_MAKEFILE
59$echo "	$NXT_BUILD_DIR/src/nxt_lvlhsh.o \\" >> $NXT_MAKEFILE
60$echo "	$NXT_BUILD_DIR/src/nxt_murmur_hash.o \\" >> $NXT_MAKEFILE
61$echo "	$NXT_BUILD_DIR/src/nxt_websocket.o \\" >> $NXT_MAKEFILE
62
63for nxt_src in $NXT_LIB_UNIT_SRCS
64do
65    nxt_obj=${nxt_src%.c}.o
66    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
67done
68
69$echo >> $NXT_MAKEFILE
70
71
72# The version file.
73
74cat << END >> $NXT_MAKEFILE
75
76include version
77
78$NXT_VERSION_H: version
79	$echo '#define NXT_VERSION "\$(NXT_VERSION)"' > $NXT_VERSION_H
80	$echo '#define NXT_VERNUM  \$(NXT_VERNUM)' >> $NXT_VERSION_H
81
82END
83
84
85# Shared and static library.
86
87cat << END >> $NXT_MAKEFILE
88
89libnxt:	$NXT_BUILD_DIR/$NXT_LIB_SHARED $NXT_BUILD_DIR/$NXT_LIB_STATIC
90
91$NXT_BUILD_DIR/$NXT_LIB_SHARED:	\$(NXT_LIB_OBJS)
92	\$(NXT_SHARED_LOCAL_LINK) -o $NXT_BUILD_DIR/$NXT_LIB_SHARED \\
93		\$(NXT_LIB_OBJS) \\
94		$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
95
96$NXT_BUILD_DIR/$NXT_LIB_STATIC:	\$(NXT_LIB_OBJS)
97	$NXT_STATIC_LINK $NXT_BUILD_DIR/$NXT_LIB_STATIC \\
98		\$(NXT_LIB_OBJS)
99
100$NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC:	\$(NXT_LIB_UNIT_OBJS)
101	$NXT_STATIC_LINK $NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC \\
102		\$(NXT_LIB_UNIT_OBJS)
103
104END
105
106
107# Object files.
108
109for nxt_src in $NXT_LIB_SRCS $NXT_TEST_SRCS $NXT_LIB_UNIT_SRCS \
110               src/test/nxt_unit_app_test.c \
111               src/test/nxt_unit_websocket_chat.c \
112               src/test/nxt_unit_websocket_echo.c
113do
114    nxt_obj=${nxt_src%.c}.o
115    nxt_dep=${nxt_src%.c}.dep
116    nxt_dep_flags=`nxt_gen_dep_flags`
117    nxt_dep_post=`nxt_gen_dep_post`
118    cat << END >> $NXT_MAKEFILE
119
120$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
121	\$(CC) -c \$(CFLAGS) \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
122	-o $NXT_BUILD_DIR/$nxt_obj \\
123	$nxt_dep_flags \\
124	$nxt_src
125	$nxt_dep_post
126
127-include $NXT_BUILD_DIR/$nxt_dep
128
129END
130
131done
132
133nxt_src=src/test/nxt_cq_test.c
134nxt_obj=src/test/nxt_ncq_test.o
135nxt_dep=src/test/nxt_ncq_test.dep
136nxt_dep_flags=`nxt_gen_dep_flags`
137nxt_dep_post=`nxt_gen_dep_post`
138cat << END >> $NXT_MAKEFILE
139
140$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
141	\$(CC) -c \$(CFLAGS) -DNXT_NCQ_TEST=1 \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
142	-o $NXT_BUILD_DIR/$nxt_obj \\
143	$nxt_dep_flags \\
144	$nxt_src
145	$nxt_dep_post
146
147-include $NXT_BUILD_DIR/$nxt_dep
148
149END
150
151nxt_src=src/test/nxt_cq_test.c
152nxt_obj=src/test/nxt_vbcq_test.o
153nxt_dep=src/test/nxt_vbcq_test.dep
154nxt_dep_flags=`nxt_gen_dep_flags`
155nxt_dep_post=`nxt_gen_dep_post`
156cat << END >> $NXT_MAKEFILE
157
158$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
159	\$(CC) -c \$(CFLAGS) -DNXT_NCQ_TEST=0 \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
160	-o $NXT_BUILD_DIR/$nxt_obj \\
161	$nxt_dep_flags \\
162	$nxt_src
163	$nxt_dep_post
164
165-include $NXT_BUILD_DIR/$nxt_dep
166
167END
168
169$echo >> $NXT_MAKEFILE
170
171
172if [ $NXT_TESTS = YES ]; then
173
174    # Test object files list.
175
176    $echo "NXT_TEST_OBJS = \\" >> $NXT_MAKEFILE
177
178    for nxt_src in $NXT_TEST_SRCS
179    do
180        nxt_obj=${nxt_src%.c}.o
181        $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
182    done
183
184    # Test executables.
185
186    cat << END >> $NXT_MAKEFILE
187
188.PHONY: tests
189tests:		$NXT_BUILD_DIR/tests $NXT_BUILD_DIR/utf8_file_name_test \\
190			$NXT_BUILD_DIR/ncq_test \\
191			$NXT_BUILD_DIR/vbcq_test \\
192			$NXT_BUILD_DIR/unit_app_test $NXT_BUILD_DIR/unit_websocket_chat \\
193			$NXT_BUILD_DIR/unit_websocket_echo
194
195$NXT_BUILD_DIR/tests: \$(NXT_TEST_OBJS) \\
196			$NXT_BUILD_DIR/$NXT_LIB_STATIC
197	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/tests \\
198		\$(CFLAGS) \$(NXT_TEST_OBJS) \\
199		$NXT_BUILD_DIR/$NXT_LIB_STATIC \\
200		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
201
202$NXT_BUILD_DIR/utf8_file_name_test: $NXT_LIB_UTF8_FILE_NAME_TEST_SRCS \\
203			$NXT_BUILD_DIR/$NXT_LIB_STATIC
204	\$(CC) \$(CFLAGS) \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
205		-o $NXT_BUILD_DIR/utf8_file_name_test \\
206		$NXT_LIB_UTF8_FILE_NAME_TEST_SRCS \\
207		$NXT_BUILD_DIR/$NXT_LIB_STATIC \\
208		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
209
210$NXT_BUILD_DIR/ncq_test: $NXT_BUILD_DIR/src/test/nxt_ncq_test.o \\
211			$NXT_BUILD_DIR/$NXT_LIB_STATIC
212	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/ncq_test \\
213		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_ncq_test.o \\
214		$NXT_BUILD_DIR/$NXT_LIB_STATIC \\
215		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
216
217$NXT_BUILD_DIR/vbcq_test: $NXT_BUILD_DIR/src/test/nxt_vbcq_test.o \\
218			$NXT_BUILD_DIR/$NXT_LIB_STATIC
219	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/vbcq_test \\
220		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_vbcq_test.o \\
221		$NXT_BUILD_DIR/$NXT_LIB_STATIC \\
222		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
223
224$NXT_BUILD_DIR/unit_app_test: $NXT_BUILD_DIR/src/test/nxt_unit_app_test.o \\
225		$NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC
226	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/unit_app_test \\
227		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_unit_app_test.o \\
228		$NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC \\
229		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
230
231$NXT_BUILD_DIR/unit_websocket_chat: \\
232		$NXT_BUILD_DIR/src/test/nxt_unit_websocket_chat.o \\
233		$NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC
234	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/unit_websocket_chat \\
235		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_unit_websocket_chat.o \\
236		$NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC \\
237		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
238
239$NXT_BUILD_DIR/unit_websocket_echo: \\
240		$NXT_BUILD_DIR/src/test/nxt_unit_websocket_echo.o \\
241		$NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC
242	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/unit_websocket_echo \\
243		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_unit_websocket_echo.o \\
244		$NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC \\
245		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
246
247END
248
249else
250
251    cat << END >> $NXT_MAKEFILE
252
253.PHONY: tests
254tests:
255	@(echo; \\
256	  echo "error: to make tests you need to configure --tests option."; \\
257	  echo; \\
258	  exit 1)
259
260END
261
262fi
263
264
265NXT_MAKE_INCS="src $NXT_BUILD_DIR"
266NXT_MAKE_SRCS="$NXT_SRCS"
267
268
269# The include paths list.
270
271$echo -n "NXT_INCS =" >> $NXT_MAKEFILE
272
273for nxt_inc in $NXT_MAKE_INCS
274do
275    $echo -n " -I $nxt_inc" >> $NXT_MAKEFILE
276done
277
278$echo >> $NXT_MAKEFILE
279$echo >> $NXT_MAKEFILE
280
281
282# Object files list.
283
284$echo "NXT_OBJS = \\" >> $NXT_MAKEFILE
285
286for nxt_src in $NXT_MAKE_SRCS
287do
288    nxt_obj=${nxt_src%.c}.o
289    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
290done
291
292$echo >> $NXT_MAKEFILE
293
294
295# unit executable.
296
297cat << END >> $NXT_MAKEFILE
298
299$NXT_BUILD_DIR/$NXT_DAEMON:	$NXT_BUILD_DIR/$NXT_LIB_STATIC \\
300				\$(NXT_OBJS)
301	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/$NXT_DAEMON \$(CFLAGS) \\
302		\$(NXT_OBJS) $NXT_BUILD_DIR/$NXT_LIB_STATIC \\
303		$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS
304
305END
306
307
308# unit object files.
309
310for nxt_src in $NXT_MAKE_SRCS
311do
312    nxt_obj=${nxt_src%.c}.o
313    nxt_dep=${nxt_src%.c}.dep
314    nxt_dep_flags=`nxt_gen_dep_flags`
315    nxt_dep_post=`nxt_gen_dep_post`
316    cat << END >> $NXT_MAKEFILE
317
318$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
319	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) \\
320		$NXT_LIB_AUX_CFLAGS \\
321		-o $NXT_BUILD_DIR/$nxt_obj \\
322		$nxt_dep_flags \\
323		$nxt_src
324	$nxt_dep_post
325
326-include $NXT_BUILD_DIR/$nxt_dep
327
328END
329
330done
331
332
333# install
334
335cat << END >> $NXT_MAKEFILE
336
337.PHONY: install ${NXT_DAEMON}-install install-check
338
339install: ${NXT_DAEMON}-install
340
341install-check:
342	@test -n "\$(DESTDIR)$NXT_PREFIX" \\
343	|| (echo; \\
344	    echo "error: to make install you need either"; \\
345	    echo "    to configure --prefix option"; \\
346	    echo "    or to set DESTDIR environment variable."; \\
347	    echo; \\
348	    exit 1)
349
350${NXT_DAEMON}-install: $NXT_DAEMON install-check
351	install -d \$(DESTDIR)$NXT_SBINDIR
352	install -p $NXT_BUILD_DIR/$NXT_DAEMON \$(DESTDIR)$NXT_SBINDIR/
353	install -d \$(DESTDIR)$NXT_STATE
354
355
356.PHONY: uninstall ${NXT_DAEMON}-uninstall
357
358uninstall: ${NXT_DAEMON}-uninstall
359
360${NXT_DAEMON}-uninstall:
361	rm -f \$(DESTDIR)$NXT_SBINDIR/$NXT_DAEMON
362	@rmdir -p \$(DESTDIR)$NXT_SBINDIR 2>/dev/null || true
363
364END
365
366cat << END >> $NXT_MAKEFILE
367
368.PHONY: libunit-install libunit-uninstall
369
370libunit-install: $NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC
371	install -d \$(DESTDIR)$NXT_LIBDIR
372	install -p -m u=rw,go=r $NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC \
373		\$(DESTDIR)$NXT_LIBDIR/
374	install -d \$(DESTDIR)$NXT_INCDIR
375	install -p -m u=rw,go=r src/nxt_unit.h \
376		src/nxt_unit_field.h \
377		src/nxt_unit_request.h \
378		src/nxt_unit_response.h \
379		src/nxt_unit_sptr.h \
380		src/nxt_unit_typedefs.h \
381		src/nxt_unit_websocket.h \
382		$NXT_BUILD_DIR/nxt_auto_config.h \
383		$NXT_BUILD_DIR/nxt_version.h \
384		src/nxt_websocket_header.h \
385		\$(DESTDIR)$NXT_INCDIR/
386
387libunit-uninstall:
388	rm -f \$(DESTDIR)$NXT_LIBDIR/$NXT_LIB_UNIT_STATIC
389	@rmdir -p \$(DESTDIR)$NXT_LIBDIR 2>/dev/null || true
390	rm -f \$(DESTDIR)$NXT_INCDIR/nxt_unit.h \
391		\$(DESTDIR)$NXT_INCDIR/nxt_unit_field.h \
392		\$(DESTDIR)$NXT_INCDIR/nxt_unit_request.h \
393		\$(DESTDIR)$NXT_INCDIR/nxt_unit_response.h \
394		\$(DESTDIR)$NXT_INCDIR/nxt_unit_sptr.h \
395		\$(DESTDIR)$NXT_INCDIR/nxt_unit_typedefs.h \
396		\$(DESTDIR)$NXT_INCDIR/nxt_unit_websocket.h \
397		\$(DESTDIR)$NXT_INCDIR/nxt_auto_config.h \
398		\$(DESTDIR)$NXT_INCDIR/nxt_version.h \
399		\$(DESTDIR)$NXT_INCDIR/nxt_websocket_header.h
400	@rmdir -p \$(DESTDIR)$NXT_INCDIR 2>/dev/null || true
401
402END
403
404# Makefile.
405# *.dSYM is MacOSX Clang debug information.
406
407cat << END > Makefile
408
409include $NXT_MAKEFILE
410
411.PHONY: clean
412clean:
413		rm -rf $NXT_BUILD_DIR *.dSYM Makefile
414
415END
416