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