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