auto.def 9.07 KB
Newer Older
Baptiste Daroussin's avatar
Baptiste Daroussin committed
1
2
3
4
5
6
# vim:se syn=tcl:
#

use cc cc-lib cc-shared pkg-config

set maj_ver 1
Emmanuel Vadot's avatar
Emmanuel Vadot committed
7
set med_ver 16
Baptiste Daroussin's avatar
Baptiste Daroussin committed
8
set min_ver 99
Baptiste Daroussin's avatar
Baptiste Daroussin committed
9
set dev_ver 4
Baptiste Daroussin's avatar
Baptiste Daroussin committed
10
define PKG_API [expr $maj_ver * 1000000 + $med_ver * 1000 + $min_ver]
Pietro Cerutti's avatar
Pietro Cerutti committed
11
define VERSION $maj_ver.$med_ver.$min_ver[expr {$dev_ver ? ".$dev_ver" : ""}]
Baptiste Daroussin's avatar
Baptiste Daroussin committed
12
13
14
15
16
17

# Add any user options here
options {
	pkgconfigdir:WHERE => "path to the directory where to install pc files"
	with-ldns => "add support for libldns"
	with-libarchive.pc => "build with libarchive getting flags via pc files"
18
	with-coverage => "build with llvm coverage support"
19
20
	with-asan => "build with libasan support"
	with-ubsan => "Build with libubsan support"
21
	default-format:txz => "Default compression format: tzst, txz (default), tbz, tar"
Baptiste Daroussin's avatar
Baptiste Daroussin committed
22
23
24
25
26
27
}

if {[opt-str pkgconfigdir dir]} {
	define pkgconfigdir $dir
} else {
	if {[string match *-freebsd* [get-define host]]} {
28
		define pkgconfigdir [get-define prefix]/libdata/pkgconfig
Baptiste Daroussin's avatar
Baptiste Daroussin committed
29
	} else {
30
		define pkgconfigdir [get-define prefix]/lib/pkgconfig
Baptiste Daroussin's avatar
Baptiste Daroussin committed
31
32
33
	}
}

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# default compression format

if {[opt-str default-format fmt]} {
	switch $fmt \
	    "tzst" { set comp TZS } \
	    "txz" { set comp TXZ } \
	    "tbz" { set comp TBZ } \
	    "tgz" { set comp TGZ } \
	    "tar" { set comp TAR } \
	    "default" { user-error "Invalid format $fmt" }
	define DEFAULT_COMPRESSION $comp
} else {
	define DEFAULT_COMPRESSION TXZ
}

Baptiste Daroussin's avatar
Baptiste Daroussin committed
49
50
51
52
53
54
55
cc-check-tools ar ranlib strip

define EXTRA_LIBS ""
define LIBVERSION 4
define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define LIBVERSION]]

define GITHASH ""
56
57
58
if {[cc-check-progs git] && [file exists .git] &&
    ![catch {exec git rev-parse --short HEAD} gitrev] &&
    ![catch {exec git diff-index -m --name-only HEAD} gitdirty]} {
Pietro Cerutti's avatar
Pietro Cerutti committed
59
	define GITHASH -$gitrev[expr {$gitdirty eq {} ? {} : {-dirty}}]
Baptiste Daroussin's avatar
Baptiste Daroussin committed
60
61
62
63
64
65
66
67
68
69
70
}

if {[string match *-linux* [get-define host]]} {
	cc-with { -libs { -lbsd }} {
		if {[cc-check-functions getprogname]} {
			define-append EXTRA_LIBS -lbsd
			define-feature libbsd
		} else {
			user-error "Unable to find libbsd"
		}
	}
71
72
} else {
	define-feature static
Baptiste Daroussin's avatar
Baptiste Daroussin committed
73
74
}

75
if {![opt-bool with-libarchive.pc]} {
Baptiste Daroussin's avatar
Baptiste Daroussin committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
	cc-with { -libs { -larchive }} {
		if {![cc-check-functions archive_read_open]} {
			user-error "Unable to find libarchive"
		}
	}
}

cc-with { -libs { -lz }} {
	if {![cc-check-functions zlibVersion]} {
		user-error "Unable to find zlib"
	}
}

cc-with { -libs { -lbz2 }} {
	if {![cc-check-functions BZ2_bzReadOpen]} {
		user-error "Unable to find bzip2"
	}
}

cc-with { -libs { -llzma }} {
	if {![cc-check-functions lzma_version_string]} {
		user-error "Unable to find liblzma"
	}
}
Emmanuel Vadot's avatar
Emmanuel Vadot committed
100
101
102
103
104
105
106
107
108
if {[string match *-freebsd* [get-define host]]} {
	cc-with { -libs { -lmd }} {
		if {![cc-check-functions SHA256_Data]} {
			user-error "Unable to find libmd"
		} else {
			define-feature libmd
		}
	}
}
Baptiste Daroussin's avatar
Baptiste Daroussin committed
109

110
111
112
113
cc-with { -libs { -larchive }} {
	cc-check-functions archive_write_add_filter_zstd
}

114
115
116
117
118
119
120
define ZSTDLIB ""
cc-with { -libs { -lprivatezstd }} {
	if {[cc-check-functions ZSTD_versionNumber]} {
		define ZSTDLIB "-lprivatezstd"
	}
}

Baptiste Daroussin's avatar
Baptiste Daroussin committed
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
# Atomics
msg-checking "Checking for atomic builtins... "
if {[cctest -code {
	volatile unsigned long val = 1;
	__sync_synchronize();
	__sync_val_compare_and_swap(&val, 1, 0);
	__sync_add_and_fetch(&val, 1);
	__sync_sub_and_fetch(&val, 1);
	return 0;
	}
]} {
	msg-result ok
	define-feature atomic_builtins
} else {
	msg-result no
	define-feature atomic_builtins 0
}

msg-checking "Checking for /proc/self/fd support... "
if {[file exists /proc/self/fd]} {
	msg-result ok
	define-feature proc-pid
} else {
	msg-result no
	define-feature proc-pid 0
}

Baptiste Daroussin's avatar
Baptiste Daroussin committed
148
foreach fct [list memmove usleep pread pwrite] {
Baptiste Daroussin's avatar
Baptiste Daroussin committed
149
150
151
152
153
154
	if {![cc-check-functions $fct]} {
		user-error "Cannot find $fct"
	}
}

cc-with { -includes fcntl.h } {
155
	cc-check-decls F_CLOSEM
Baptiste Daroussin's avatar
Baptiste Daroussin committed
156
157
158
}

cc-with { -includes sys/socket.h } {
159
	cc-check-decls SOCK_SEQPACKET
Baptiste Daroussin's avatar
Baptiste Daroussin committed
160
161
162
163
164
165
166
}

cc-with { -includes netinet/in.h } {
	cc-check-members "struct sockaddr_in.sin_len"
}

cc-with { -includes sys/stat.h } {
167
	cc-check-members "struct stat.st_mtim" "struct stat.st_flags"
Baptiste Daroussin's avatar
Baptiste Daroussin committed
168
169
170
}

# check for sqlite
171
172
cc-check-functions gmtime_r isnan localtime_r strchrnul strerror_r fdatasync \
	fchown lstat readlink
Baptiste Daroussin's avatar
Baptiste Daroussin committed
173
174
175
cc-check-includes stdint.h inttypes.h

# check for pkg itself
176
cc-check-functions arc4random arc4random_stir basename_r chflagsat \
177
	closefrom dirfd eaccess fopencookie fstatfs funopen getprogname strnstr \
Baptiste Daroussin's avatar
Baptiste Daroussin committed
178
	strtofflags strtonum sysconf utimensat __res_setservers unlinkat \
179
	faccessat fstatat openat readlinkat fflagstostr reallocarray strchrnul
Baptiste Daroussin's avatar
Baptiste Daroussin committed
180

181
182
183
184
cc-with { -includes { libutil.h }} {
	if {[cc-check-decls humanize_number]} {
	}
}
Baptiste Daroussin's avatar
Baptiste Daroussin committed
185
186
187
188

if {![cc-check-functions fts_open]} {
	cc-with { -libs { -lfts }} {
		if {[cc-check-functions fts_open]} {
189
			define-feature LIBFTS
Baptiste Daroussin's avatar
Baptiste Daroussin committed
190
191
192
193
		}
	}
}

194
195
196
197
198
if {[get-define HAVE_DECL_HUMANIZE_NUMBER] eq 1} {
	cc-with { -libs { -lutil }} {
		if {[cc-check-functions humanize_number]} {
			define-feature LIBUTIL
		}
Baptiste Daroussin's avatar
Baptiste Daroussin committed
199
200
201
	}
}

Baptiste Daroussin's avatar
Baptiste Daroussin committed
202
203
204
205
206
207
208
209
if {![cc-check-functions dlclose]} {
	cc-with { -libs { -ldl }} {
		if {[cc-check-functions dlclose]} {
			define-feature LIBDL
		}
	}
}

210
if {![cc-check-functions __res_query]} {
211
	cc-with { -libs { -lresolv }} {
212
		if {[cc-check-functions __res_query]} {
213
214
215
216
217
			define-feature LIBRESOLV
		}
	}
}

Baptiste Daroussin's avatar
Baptiste Daroussin committed
218
219
220
221
222
223
224
cc-check-includes link.h machine/endian.h osreldate.h readpassphrase.h \
	sys/procctl.h sys/statfs.h sys/statvfs.h libutil.h

# for compat
cc-check-includes dirent.h

#endian stuff
225
foreach header [list endian.h sys/endian.h] {
Baptiste Daroussin's avatar
Baptiste Daroussin committed
226
227
228
229
230
231
232
233
234
	if {[cc-check-includes $header]} {
		cc-with [list -includes $header] {
			cc-check-decls be16dec be16enc be32dec be32enc be64dec be64enc \
				le16dec le16enc le32dec le32enc le64dec le64enc
		}
	}
}

if {[string match *-darwin* [get-define host]]} {
235
	define libmachista
236
237
	define waflags ""
	define nowaflags ""
Baptiste Daroussin's avatar
Baptiste Daroussin committed
238
239
} else {
# libelf
240
241
	define waflags "-Wl,-whole-archive"
	define nowaflags "-Wl,-no-whole-archive"
Baptiste Daroussin's avatar
Baptiste Daroussin committed
242
243
244
245
246
247
248
249
	cc-with { -includes { sys/types.h }} {
		cc-check-includes elf-hints.h sys/elf_common.h
	}

	if {[cc-check-includes gelf.h libelf.h]} {
		cc-with { -libs { -lelf } } {
			if {[cc-check-functions gelf_getehdr]} {
				define-feature libelf
250
				define libelf-external
Baptiste Daroussin's avatar
Baptiste Daroussin committed
251
				define-append EXTRA_LIBS -lelf
Ralf Hubert's avatar
Ralf Hubert committed
252
				cc-check-types Elf_Note
Baptiste Daroussin's avatar
Baptiste Daroussin committed
253
			} else {
254
				define libelf-internal
Baptiste Daroussin's avatar
Baptiste Daroussin committed
255
256
257
				define-feature libelf 0
			}
		}
Baptiste Daroussin's avatar
Baptiste Daroussin committed
258
259
	} else {
		define-feature libelf 0
260
		define libelf-internal
Baptiste Daroussin's avatar
Baptiste Daroussin committed
261
262
263
264
265
266
267
268
269
270
271
272
	}
}

cc-with { -libs { -ljail} } {
	if {[cc-check-functions jail_getid]} {
		define-feature libjail
		define-append EXTRA_LIBS -ljail
	}
}

# libbsd
cc-check-includes bsd/err.h bsd/libutil.h bsd/readpassphrase.h \
273
274
	bsd/stdio.h bsd/stdlib.h bsd/strlib.h bsd/string.h \
	bsd/sys/cdefs.h bsd/unistd.h
Baptiste Daroussin's avatar
Baptiste Daroussin committed
275
 
276
277
278
if {[opt-bool with-asan]} {
	define-append ASAN_CFLAGS -O0 -ggdb -fsanitize=address
	define-append ASAN_LDFLAGS -fsanitize=address
279
280
281
282
	if {[string match *-linux* [get-define host]]} {
		# ASAN depends on libdl for dlsym when building with GCC
		define-append ASAN_LDFLAGS -ldl
	}
283
284
285
286
	define asan 1
	undefine HAVE_STATIC
}
if {[opt-bool with-ubsan]} {
287
288
289
290
	# Avoid alignment error when building with UBSan inside _mum_hash_avx2
	define-append UBSAN_CFLAGS -D_MUM_UNALIGNED_ACCESS=0
	define-append UBSAN_CFLAGS -O0 -ggdb -fsanitize=undefined
	define-append UBSAN_LDFLAGS -fsanitize=undefined
291
292
	define ubsan 1
}
293
294
295
296
297
298
299
300
301
302
303
304
305
306
if {[opt-bool with-coverage]} {
	define-append COVERAGE_CFLAGS -O0 -ggdb -fprofile-instr-generate -fcoverage-mapping
	define-append COVERAGE_LDFLAGS -fprofile-instr-generate -fuse-ld=/usr/local/bin/ld.lld
	define CC /usr/local/bin/clang
	define CC_FOR_BUILD /usr/local/bin/clang
	define coverage 1
# disable capsicum when coverage is used because coverage does not work in
# capsicum mode
} else {
# capsicum 
	if {[cc-check-functions cap_sandboxed]} {
		define-feature capsicum
			cc-check-includes sys/capsicum.h
	}
Baptiste Daroussin's avatar
Baptiste Daroussin committed
307
308
309
310
311
}

if {[pkg-config-init 0]} {
# atf
	if {[pkg-config atf-c] && [cc-check-progs kyua]} {
312
		define TESTS
Baptiste Daroussin's avatar
Baptiste Daroussin committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
		puts "test suite will be built"
	} else {
		puts "Skipping test suite"
	}
	if {[opt-bool with-ldns]} {
		if {![pkg-config libldns]} {
			user-error "Unable to find libldns"
		} else {
			define PKG_LIBDNS_LIBS_STATIC [exec pkg-config --static --libs-only-l libldns]
		}
	}
	if {[opt-bool with-libarchive.pc]} {
		if {![pkg-config libarchive]} {
			user-error "Unable to find libarchive"
		} else {
			define PKG_LIBARCHIVE_LIBS_STATIC [exec pkg-config --static --libs-only-l libarchive]
329
330
331
332
			cc-with { -libs { -larchive }} {
				cc-check-functions archive_write_add_filter_zstd
			}
		}
333
334
335
	}
}

336
foreach repo [list binary] {
Baptiste Daroussin's avatar
Baptiste Daroussin committed
337
338
339
340
341
	define-append REPOS $repo
	define-append REPOS_LDFLAGS -L\$(top_builddir)/libpkg/repo/${repo} -lrepo-${repo}_pic
	define-append REPOS_STATIC_LIBS \$(top_builddir)/libpkg/repo/${repo}/librepo-${repo}.a
}

Pietro Cerutti's avatar
Pietro Cerutti committed
342
343
344
345
346
# ccache
if {[get-define CCACHE] ne {none}} {
  define CC "[get-define CCACHE] [get-define CC]"
}

347
make-config-header pkg_config.h -bare { DEFAULT_* }
Baptiste Daroussin's avatar
Baptiste Daroussin committed
348
349
350
351
352
353
354
make-config-header external/sqlite/config.h
make-template mk/defs.mk.in
make-template libpkg/pkg.h.in
make-template libpkg/pkg.pc.in
make-template tests/frontend/test_environment.sh.in
make-template Makefile.autosetup Makefile

355
foreach dir [list external/blake2 external/picosat \
Baptiste Daroussin's avatar
Baptiste Daroussin committed
356
357
	external/linenoise external/libfetch external/sqlite \
	external compat libpkg libpkg/repo libpkg/repo/binary src \
Baptiste Daroussin's avatar
Baptiste Daroussin committed
358
	external/libucl external/libelf external/libmachista tests docs \
359
	external/liblua external/msgpuck external/yxml scripts] {
Baptiste Daroussin's avatar
Baptiste Daroussin committed
360
361
	make-template $dir/Makefile.autosetup $dir/Makefile
}
Pietro Cerutti's avatar
Pietro Cerutti committed
362