summaryrefslogtreecommitdiffhomepage
path: root/auto/make
blob: 24b6dac6f8ef8a8515aa540a4cc41311d95f1f8d (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

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


$echo "creating $NXT_MAKEFILE"

mkdir -p $NXT_BUILD_DIR/src \
         $NXT_BUILD_DIR/test


cat << END > $NXT_MAKEFILE

CC =			$CC

CFLAGS = 		$NXT_CFLAGS $NXT_CC_OPT $CFLAGS

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 $NXT_LD_OPT

.PHONY: $NXT_DAEMON
$NXT_DAEMON: $NXT_BUILD_DIR/$NXT_DAEMON

all: $NXT_DAEMON

END


# The include paths list.

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

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

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


# The include files dependences list.

$echo "NXT_LIB_DEPS = \\" >> $NXT_MAKEFILE

for nxt_dep in $NXT_LIB_DEPS $NXT_TEST_DEPS $NXT_AUTO_CONFIG_H
do
    $echo "	$nxt_dep \\" >> $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=`$echo $nxt_src | sed -e "s/\.c$/\.o/"`
    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
done

$echo >> $NXT_MAKEFILE


# Shared and static library.

cat << END >> $NXT_MAKEFILE

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

$NXT_BUILD_DIR/$NXT_LIB_SHARED:	\$(NXT_LIB_OBJS)
	\$(NXT_SHARED_LOCAL_LINK) -o $NXT_BUILD_DIR/$NXT_LIB_SHARED \\
		\$(NXT_LIB_OBJS) \\
		$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

$NXT_BUILD_DIR/$NXT_LIB_STATIC:	\$(NXT_LIB_OBJS)
	$NXT_STATIC_LINK $NXT_BUILD_DIR/$NXT_LIB_STATIC \\
		\$(NXT_LIB_OBJS)

END


# Object files.

for nxt_src in $NXT_LIB_SRCS $NXT_TEST_SRCS
do
    nxt_obj=`$echo $nxt_src | sed -e "s/\.c$/\.o/"`
    cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$nxt_obj: $nxt_src \$(NXT_LIB_DEPS)
	\$(CC) -c \$(CFLAGS) \$(NXT_LIB_INCS) $NXT_LIB_AUX_CFLAGS \\
	-o $NXT_BUILD_DIR/$nxt_obj \\
	$nxt_src
END

done

$echo >> $NXT_MAKEFILE


# Test object files list.

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

for nxt_src in $NXT_TEST_SRCS
do
    nxt_obj=`$echo $nxt_src | sed -e "s/\.c$/\.o/"`
    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
done


# Test executables.

cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/tests: \$(NXT_TEST_OBJS) \\
			$NXT_BUILD_DIR/$NXT_LIB_STATIC \$(NXT_LIB_DEPS)
	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/tests \\
		\$(CFLAGS) \$(NXT_TEST_OBJS) \\
		$NXT_BUILD_DIR/$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/$NXT_LIB_STATIC \$(NXT_LIB_DEPS)
	\$(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/$NXT_LIB_STATIC \\
		$NXT_LD_OPT $NXT_LIBM $NXT_LIBS

END


NXT_MAKE_INCS="src $NXT_BUILD_DIR"
NXT_MAKE_DEPS="\$(NXT_LIB_DEPS) $NXT_DEPS"
NXT_MAKE_SRCS="$NXT_SRCS"


# The include pathes 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


# The include files dependences list.

$echo "NXT_DEPS = \\" >> $NXT_MAKEFILE

for nxt_dep in $NXT_MAKE_DEPS
do
    $echo "	$nxt_dep \\" >> $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=`$echo $nxt_src | sed -e "s/\.c$/\.o/"`
    $echo "	$NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE
done

$echo >> $NXT_MAKEFILE


# unit executable.

cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$NXT_DAEMON:	$NXT_BUILD_DIR/$NXT_LIB_STATIC \\
				\$(NXT_OBJS)
	\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/$NXT_DAEMON \$(CFLAGS) \\
		\$(NXT_OBJS) $NXT_BUILD_DIR/$NXT_LIB_STATIC \\
		$NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS

END


# unit object files.

for nxt_src in $NXT_MAKE_SRCS
do
    nxt_obj=`$echo $nxt_src | sed -e "s/\.c$/\.o/"`
    cat << END >> $NXT_MAKEFILE

$NXT_BUILD_DIR/$nxt_obj:	$nxt_src \$(NXT_DEPS)
	\$(CC) -c \$(CFLAGS) \$(NXT_INCS) \\
		$NXT_LIB_AUX_CFLAGS \\
		-o $NXT_BUILD_DIR/$nxt_obj \\
		$nxt_src
END

done


# install

cat << END >> $NXT_MAKEFILE

.PHONY: install ${NXT_DAEMON}-install

install: ${NXT_DAEMON}-install

${NXT_DAEMON}-install: $NXT_DAEMON
	install -d \$(DESTDIR)$NXT_SBINDIR
	install -p $NXT_BUILD_DIR/$NXT_DAEMON \$(DESTDIR)$NXT_SBINDIR/
	install -d \$(DESTDIR)$NXT_STATE


.PHONY: uninstall ${NXT_DAEMON}-uninstall

uninstall: ${NXT_DAEMON}-uninstall

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

END


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

cat << END > Makefile

NXT_VERSION =	0.1

include $NXT_MAKEFILE

.PHONY:		tests
tests:		$NXT_BUILD_DIR/tests $NXT_BUILD_DIR/utf8_file_name_test

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

.PHONY: dist
dist:
		rm -f unit-\$(NXT_VERSION).tar.gz
		mkdir unit-\$(NXT_VERSION)
		cp -rp LICENSE NOTICE CHANGES README.md \\
			configure auto src test \\
			unit-\$(NXT_VERSION)
		tar czf unit-\$(NXT_VERSION).tar.gz unit-\$(NXT_VERSION)
		rm -rf unit-\$(NXT_VERSION)

END