summaryrefslogtreecommitdiffhomepage
path: root/auto/make
blob: 183e95c7538d91a2108de4655292db72586b61f5 (plain) (blame)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586

# Copyright (C) Igor Sysoev
# Copyright (C) Valentin V. Bartenev
# Copyright (C) NGINX, Inc.

. auto/cc/deps

$echo "creating $NXT_MAKEFILE"

cat << END > $NXT_MAKEFILE

# Pretty print compiler etc actions...
PP_CC		:= @echo '  CC    '
PP_AR		:= @echo '  AR    '
PP_LD		:= @echo '  LD    '
PP_VER		:= @echo '  VER   '
PP_SED		:= @echo '  SED   '

CC =			$CC
AR =			$AR

EXTRA_CFLAGS =
CFLAGS = 		$NXT_CFLAGS $NXT_CC_OPT $CFLAGS \$(EXTRA_CFLAGS)
RUST_FLAGS =
NXT_OTEL_LIB_LOC =

NXT_EXEC_LINK =		$NXT_EXEC_LINK $NXT_LD_OPT
NXT_SHARED_LOCAL_LINK =	$NXT_SHARED_LOCAL_LINK $NXT_LD_OPT
NXT_MODULE_LINK =	$NXT_MODULE_LINK

all: $NXT_DAEMON manpage

.PHONY: $NXT_DAEMON manpage
$NXT_DAEMON: $NXT_BUILD_DIR/sbin/$NXT_DAEMON
manpage: $NXT_BUILD_DIR/share/man/man8/unitd.8

END


NXT_OS=$(uname -s)
NXT_GNU_MAKE=$(make --version | grep GNU || true)

# Requires GNU make. On OpenIndiana at least we have to use gmake
if [ -n "$NXT_GNU_MAKE" ] || [ $NXT_OS = "SunOS" ]; then

	cat << END >> $NXT_MAKEFILE
# By default compiler etc output is hidden, use
#   make V=1 ...
# to show it.
V := 0

v := @
ifeq (\$V,1)
        v :=
endif

# Optionally enable debugging builds with
#   make D=1 ...
# -g is always used, this just changes the optimisation level.
# On GCC this would be -Og, however according to the clang(1)
# man page, -O0 'generates the most debuggable code'.
D := 0

ifeq (\$D,1)
        CFLAGS += -O0
        RUST_FLAGS += --debug
else
        RUST_FLAGS += --release
endif

# Optionally disable -Werror with
#   make E=0 ...
E := 1

ifeq (\$E,0)
        CFLAGS += -Wno-error
endif

END

fi

# potentially set otel lib location
if [ $NXT_OTEL = YES ]; then
cat << END >> $NXT_MAKEFILE

ifeq (\$D,1)
	NXT_OTEL_LIB_LOC = $NXT_OTEL_LIB_DIR/target/debug/libotel.a
else
	NXT_OTEL_LIB_LOC = $NXT_OTEL_LIB_DIR/target/release/libotel.a
endif

END
fi

# The include paths list.

$echo -n "NXT_LIB_INCS =" >> $NXT_MAKEFILE

for nxt_inc in src $NXT_BUILD_DIR/include
do
    $echo -n " -I $nxt_inc" >> $NXT_MAKEFILE
done

$echo >> $NXT_MAKEFILE
$echo >> $NXT_MAKEFILE


# Library object files list.

$echo "NXT_LIB_OBJS = \\" >> $NXT_MAKEFILE

for nxt_src in $NXT_LIB_SRCS
do
    nxt_obj=${nxt_src%.c}.o
    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
done

$echo >> $NXT_MAKEFILE

$echo "NXT_LIB_UNIT_OBJS = \\" >> $NXT_MAKEFILE
$echo "	$NXT_BUILD_DIR/src/nxt_lvlhsh.o \\" >> $NXT_MAKEFILE
$echo "	$NXT_BUILD_DIR/src/nxt_murmur_hash.o \\" >> $NXT_MAKEFILE
$echo "	$NXT_BUILD_DIR/src/nxt_socket_msg.o \\" >> $NXT_MAKEFILE
$echo "	$NXT_BUILD_DIR/src/nxt_websocket.o \\" >> $NXT_MAKEFILE

for nxt_src in $NXT_LIB_UNIT_SRCS
do
    nxt_obj=${nxt_src%.c}.o
    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
done

$echo >> $NXT_MAKEFILE


# The version file.

cat << END >> $NXT_MAKEFILE

include version

$NXT_VERSION_H: version
	\$(PP_VER) \$@ \(NXT_VERSION\)
	\$(v)$echo '#define NXT_VERSION "\$(NXT_VERSION)"' > $NXT_VERSION_H
	\$(PP_VER) \$@ \(NXT_VERNUM\)
	\$(v)$echo '#define NXT_VERNUM  \$(NXT_VERNUM)' >> $NXT_VERSION_H

END


# Shared and static library.

cat << END >> $NXT_MAKEFILE

libnxt:	$NXT_BUILD_DIR/lib/$NXT_LIB_SHARED $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC

$NXT_BUILD_DIR/lib/$NXT_LIB_SHARED: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_LOC)
	\$(PP_LD) \$@
	\$(v)\$(NXT_SHARED_LOCAL_LINK) -o \$@ \$(NXT_LIB_OBJS) \\
		$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_LOC)

$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC: \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_LOC)
	\$(PP_AR) \$@
	\$(v)$NXT_STATIC_LINK \$@ \$(NXT_LIB_OBJS) \$(NXT_OTEL_LIB_LOC)

$NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC: \$(NXT_LIB_UNIT_OBJS) \\
		$NXT_BUILD_DIR/share/pkgconfig/unit.pc \\
		$NXT_BUILD_DIR/share/pkgconfig/unit-uninstalled.pc
	\$(PP_AR) \$@
	\$(v)$NXT_STATIC_LINK \$@ \$(NXT_LIB_UNIT_OBJS)

END


# Object files.

for nxt_src in $NXT_LIB_SRCS $NXT_TEST_SRCS $NXT_FUZZ_SRCS $NXT_LIB_UNIT_SRCS \
               src/test/nxt_unit_app_test.c \
               src/test/nxt_unit_websocket_chat.c \
               src/test/nxt_unit_websocket_echo.c
do
    nxt_obj=${nxt_src%.c}.o
    nxt_dep=${nxt_src%.c}.dep
    nxt_dep_flags=`nxt_gen_dep_flags`
    nxt_dep_post=`nxt_gen_dep_post`
    cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
	\$(PP_CC) \$@
	\$(v)\$(CC) -c \$(CFLAGS) \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
	-o $NXT_BUILD_DIR/$nxt_obj \\
	$nxt_dep_flags \\
	$nxt_src
	$nxt_dep_post

-include $NXT_BUILD_DIR/$nxt_dep

END

done

nxt_src=src/test/nxt_cq_test.c
nxt_obj=src/test/nxt_ncq_test.o
nxt_dep=src/test/nxt_ncq_test.dep
nxt_dep_flags=`nxt_gen_dep_flags`
nxt_dep_post=`nxt_gen_dep_post`
cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
	\$(PP_CC) \$@
	\$(v)\$(CC) -c \$(CFLAGS) -DNXT_NCQ_TEST=1 \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
	-o $NXT_BUILD_DIR/$nxt_obj \\
	$nxt_dep_flags \\
	$nxt_src
	$nxt_dep_post

-include $NXT_BUILD_DIR/$nxt_dep

END

nxt_src=src/test/nxt_cq_test.c
nxt_obj=src/test/nxt_vbcq_test.o
nxt_dep=src/test/nxt_vbcq_test.dep
nxt_dep_flags=`nxt_gen_dep_flags`
nxt_dep_post=`nxt_gen_dep_post`
cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
	\$(PP_CC) \$@
	\$(v)\$(CC) -c \$(CFLAGS) -DNXT_NCQ_TEST=0 \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
	-o $NXT_BUILD_DIR/$nxt_obj \\
	$nxt_dep_flags \\
	$nxt_src
	$nxt_dep_post

-include $NXT_BUILD_DIR/$nxt_dep

END

$echo >> $NXT_MAKEFILE


if [ $NXT_TESTS = YES ]; then

    # Test object files list.

    $echo "NXT_TEST_OBJS = \\" >> $NXT_MAKEFILE

    for nxt_src in $NXT_TEST_SRCS
    do
        nxt_obj=${nxt_src%.c}.o
        $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
    done

    # Test executables.

    cat << END >> $NXT_MAKEFILE

.PHONY: tests
tests:		$NXT_BUILD_DIR/tests $NXT_BUILD_DIR/utf8_file_name_test \\
			$NXT_BUILD_DIR/ncq_test \\
			$NXT_BUILD_DIR/vbcq_test \\
			$NXT_BUILD_DIR/unit_app_test $NXT_BUILD_DIR/unit_websocket_chat \\
			$NXT_BUILD_DIR/unit_websocket_echo

$NXT_BUILD_DIR/tests: \$(NXT_TEST_OBJS) \\
			$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC
	\$(PP_LD) \$@
	\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/tests \\
		\$(CFLAGS) \$(NXT_TEST_OBJS) \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

$NXT_BUILD_DIR/utf8_file_name_test: $NXT_LIB_UTF8_FILE_NAME_TEST_SRCS \\
			$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC
	\$(PP_LD) \$@
	\$(v)\$(CC) \$(CFLAGS) \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
		-o $NXT_BUILD_DIR/utf8_file_name_test \\
		$NXT_LIB_UTF8_FILE_NAME_TEST_SRCS \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

$NXT_BUILD_DIR/ncq_test: $NXT_BUILD_DIR/src/test/nxt_ncq_test.o \\
			$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC
	\$(PP_LD) \$@
	\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/ncq_test \\
		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_ncq_test.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

$NXT_BUILD_DIR/vbcq_test: $NXT_BUILD_DIR/src/test/nxt_vbcq_test.o \\
			$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC
	\$(PP_LD) \$@
	\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/vbcq_test \\
		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_vbcq_test.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

$NXT_BUILD_DIR/unit_app_test: $NXT_BUILD_DIR/src/test/nxt_unit_app_test.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC
	\$(PP_LD) \$@
	\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/unit_app_test \\
		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_unit_app_test.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

$NXT_BUILD_DIR/unit_websocket_chat: \\
		$NXT_BUILD_DIR/src/test/nxt_unit_websocket_chat.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC
	\$(PP_LD) \$@
	\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/unit_websocket_chat \\
		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_unit_websocket_chat.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

$NXT_BUILD_DIR/unit_websocket_echo: \\
		$NXT_BUILD_DIR/src/test/nxt_unit_websocket_echo.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC
	\$(PP_LD) \$@
	\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/unit_websocket_echo \\
		\$(CFLAGS) $NXT_BUILD_DIR/src/test/nxt_unit_websocket_echo.o \\
		$NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

END

else

    cat << END >> $NXT_MAKEFILE

.PHONY: tests
tests:
	@(echo; \\
	  echo "error: to make tests you need to configure --tests option."; \\
	  echo; \\
	  exit 1)

END

fi


NXT_MAKE_INCS="src $NXT_BUILD_DIR/include"
NXT_MAKE_SRCS="$NXT_SRCS"


# The include paths list.

$echo -n "NXT_INCS =" >> $NXT_MAKEFILE

for nxt_inc in $NXT_MAKE_INCS
do
    $echo -n " -I $nxt_inc" >> $NXT_MAKEFILE
done

$echo >> $NXT_MAKEFILE
$echo >> $NXT_MAKEFILE


# Object files list.

$echo "NXT_OBJS = \\" >> $NXT_MAKEFILE

for nxt_src in $NXT_MAKE_SRCS
do
    nxt_obj=${nxt_src%.c}.o
    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
done

$echo >> $NXT_MAKEFILE


# unit executable.

cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/sbin/$NXT_DAEMON:	$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\
				\$(NXT_OBJS) \$(NXT_OTEL_LIB_LOC)
	\$(PP_LD) \$@
	\$(v)\$(NXT_EXEC_LINK) -o \$@ \$(CFLAGS) \\
		\$(NXT_OBJS) $NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\
		$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \$(NXT_OTEL_LIB_LOC)

END


# unitd man page

cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/share/man/man8/unitd.8: docs/man/man8/unitd.8.in \\
				$NXT_BUILD_DIR/include/nxt_auto_config.h
	\$(PP_SED) \$@
	\$(v)sed -e "s|%%ERROR_LOG_PATH%%|$NXT_LOG|" \\
		-e "s|%%PID_PATH%%|$NXT_PID|" \\
		-e "s|%%SOCKET_PATH%%|$NXT_CONTROL|" \\
		< docs/man/man8/unitd.8.in > \$@

END


# unit object files.

for nxt_src in $NXT_MAKE_SRCS
do
    nxt_obj=${nxt_src%.c}.o
    nxt_dep=${nxt_src%.c}.dep
    nxt_dep_flags=`nxt_gen_dep_flags`
    nxt_dep_post=`nxt_gen_dep_post`
    cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$nxt_obj:	$nxt_src $NXT_VERSION_H
	\$(PP_CC) \$@
	\$(v)\$(CC) -c \$(CFLAGS) \$(NXT_INCS) \\
		$NXT_LIB_AUX_CFLAGS \\
		-o $NXT_BUILD_DIR/$nxt_obj \\
		$nxt_dep_flags \\
		$nxt_src
	$nxt_dep_post

-include $NXT_BUILD_DIR/$nxt_dep

END

done


# install

cat << END >> $NXT_MAKEFILE

.PHONY: install ${NXT_DAEMON}-install install-check manpage-install

install: ${NXT_DAEMON}-install manpage-install

install-check:
	@test -n "\$(DESTDIR)$NXT_PREFIX" \\
	|| (echo; \\
	    echo "error: to make install you need either"; \\
	    echo "    to configure --prefix option"; \\
	    echo "    or to set DESTDIR environment variable."; \\
	    echo; \\
	    exit 1)

${NXT_DAEMON}-install: $NXT_DAEMON install-check
	test -d \$(DESTDIR)$NXT_SBINDIR \
		|| install -d \$(DESTDIR)$NXT_SBINDIR
	install -p $NXT_BUILD_DIR/sbin/$NXT_DAEMON \$(DESTDIR)$NXT_SBINDIR/
	test -d \$(DESTDIR)$NXT_STATEDIR \
		|| install -d \$(DESTDIR)$NXT_STATEDIR
	test -d \$(DESTDIR)$NXT_LOGDIR \
		|| install -d \$(DESTDIR)$NXT_LOGDIR

manpage-install: manpage install-check
	test -d \$(DESTDIR)$NXT_MANDIR/man8 \
		|| install -d \$(DESTDIR)$NXT_MANDIR/man8
	install -p -m644 $NXT_BUILD_DIR/share/man/man8/unitd.8 \
		\$(DESTDIR)$NXT_MANDIR/man8/

.PHONY: uninstall ${NXT_DAEMON}-uninstall manpage-uninstall

uninstall: ${NXT_DAEMON}-uninstall manpage-uninstall

${NXT_DAEMON}-uninstall:
	rm -f \$(DESTDIR)$NXT_SBINDIR/$NXT_DAEMON
	@rmdir -p \$(DESTDIR)$NXT_SBINDIR 2>/dev/null || true

manpage-uninstall:
	rm -f \$(DESTDIR)$NXT_MANDIR/man8/unitd.8
	@rmdir -p \$(DESTDIR)$NXT_MANDIR/man8 2>/dev/null || true

END

cat << END >> $NXT_MAKEFILE

.PHONY: libunit-install libunit-uninstall

libunit-install: $NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC
	test -d \$(DESTDIR)$NXT_LIBDIR \
		|| install -d \$(DESTDIR)$NXT_LIBDIR
	install -p -m u=rw,go=r $NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC \
		\$(DESTDIR)$NXT_LIBDIR/
	test -d \$(DESTDIR)$NXT_PKGCONFIGDIR \
		|| install -d \$(DESTDIR)$NXT_PKGCONFIGDIR
	install -p -m u=rw,go=r $NXT_BUILD_DIR/share/pkgconfig/unit.pc \
		\$(DESTDIR)$NXT_PKGCONFIGDIR/
	test -d \$(DESTDIR)$NXT_INCLUDEDIR \
		|| install -d \$(DESTDIR)$NXT_INCLUDEDIR
	install -p -m u=rw,go=r src/nxt_unit.h \
		src/nxt_unit_field.h \
		src/nxt_unit_request.h \
		src/nxt_unit_response.h \
		src/nxt_unit_sptr.h \
		src/nxt_unit_typedefs.h \
		src/nxt_unit_websocket.h \
		$NXT_BUILD_DIR/include/nxt_auto_config.h \
		$NXT_BUILD_DIR/include/nxt_version.h \
		src/nxt_websocket_header.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/

libunit-uninstall:
	rm -f \$(DESTDIR)$NXT_LIBDIR/$NXT_LIB_UNIT_STATIC
	@rmdir -p \$(DESTDIR)$NXT_LIBDIR 2>/dev/null || true
	rm -f \$(DESTDIR)$NXT_PKGCONFIGDIR/unit.pc
	@rmdir -p \$(DESTDIR)$NXT_PKGCONFIGDIR 2>/dev/null || true
	rm -f \$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_field.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_request.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_response.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_sptr.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_typedefs.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_unit_websocket.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_auto_config.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_version.h \
		\$(DESTDIR)$NXT_INCLUDEDIR/nxt_websocket_header.h
	@rmdir -p \$(DESTDIR)$NXT_INCLUDEDIR 2>/dev/null || true

END

# pkg-config files

cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/share/pkgconfig/unit.pc: src/unit.pc.in
	\$(PP_SED) \$@
	\$(v)sed -e "s|@PREFIX@|$NXT_PREFIX|" \\
		-e "s|@LIBDIR@|$NXT_LIBDIR|" \\
		-e "s|@CFLAGS@|-I$NXT_INCLUDEDIR|" \\
		-e "s|@VERSION@|\$(NXT_VERSION)|" \\
		-e "s|@EXTRA_LIBS@|$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS|" \\
		-e "s|@CONFARGS@|$(echo $NXT_CONFIGURE_OPTIONS | sed -e 's| -pie||' -e 's| --njs||')|" \\
		-e "s|@MODULESDIR@|$NXT_MODULESDIR|" \\
	< src/unit.pc.in > \$@

$NXT_BUILD_DIR/share/pkgconfig/unit-uninstalled.pc: src/unit.pc.in
	\$(PP_SED) \$@
	\$(v)sed -e "s|@PREFIX@|$(pwd)/$NXT_BUILD_DIR|" \\
		-e "s|@LIBDIR@|$(pwd)/$NXT_BUILD_DIR/lib|" \\
		-e "s|@CFLAGS@|-I$(pwd)/src -I$(pwd)$NXT_BUILD_DIR/include|" \\
		-e "s|@VERSION@|\$(NXT_VERSION)|" \\
		-e "s|@EXTRA_LIBS@|$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS|" \\
		-e "s|@CONFARGS@|$(echo $NXT_CONFIGURE_OPTIONS | sed -e 's| -pie||' -e 's| --njs||')|" \\
	< src/unit.pc.in > \$@

END

# Makefile.
# *.dSYM is MacOSX Clang debug information.

cat << END > Makefile

include $NXT_MAKEFILE

.PHONY: help
help:
	@echo "Variables to control make/build behaviour:"
	@echo
	@echo "  make V=1 ...           - Enables verbose output"
	@echo "  make D=1 ...           - Enables debug builds (-O0)"
	@echo "  make E=0 ...           - Disables -Werror"
	@echo
	@echo "  make EXTRA_CFLAGS= ... - Add extra compiler options"
	@echo
	@echo "  Variables can be combined."

.PHONY: clean
clean:
		rm -rf $NXT_BUILD_DIR *.dSYM Makefile
END

if [ $NXT_OTEL = YES ]; then
    cat << END >> Makefile
		cd "$NXT_OTEL_LIB_DIR" && cargo clean
END

NXT_OTEL_DEPS=" \
    build/src/nxt_otel.o \
    src/otel/src/lib.rs \
"

    cat << END >> $NXT_MAKEFILE

\$(NXT_OTEL_LIB_LOC): $NXT_OTEL_DEPS
	cargo build \$(RUST_FLAGS) --manifest-path $NXT_OTEL_LIB_DIR/Cargo.toml
END
fi