You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

319 lines
7.7 KiB

  1. # vim:se syn=tcl:
  2. #
  3. use cc cc-lib cc-shared pkg-config
  4. set maj_ver 1
  5. set med_ver 14
  6. set min_ver 99
  7. set dev_ver 2
  8. define PKG_API [expr $maj_ver * 1000000 + $med_ver * 1000 + $min_ver]
  9. define VERSION $maj_ver.$med_ver.$min_ver[expr {$dev_ver ? ".$dev_ver" : ""}]
  10. # Add any user options here
  11. options {
  12. pkgconfigdir:WHERE => "path to the directory where to install pc files"
  13. with-ldns => "add support for libldns"
  14. with-libarchive.pc => "build with libarchive getting flags via pc files"
  15. with-coverage => "build with llvm coverage support"
  16. }
  17. if {[opt-str pkgconfigdir dir]} {
  18. define pkgconfigdir $dir
  19. } else {
  20. if {[string match *-freebsd* [get-define host]]} {
  21. define pkgconfigdir [get-define prefix]/libdata/pkgconfig
  22. } else {
  23. define pkgconfigdir [get-define prefix]/lib/pkgconfig
  24. }
  25. }
  26. cc-check-tools ar ranlib strip
  27. define EXTRA_LIBS ""
  28. define LIBVERSION 4
  29. define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define LIBVERSION]]
  30. define GITHASH ""
  31. if {[cc-check-progs git] && [file exists .git]} {
  32. catch {exec git rev-parse --short HEAD} gitrev
  33. catch {exec git diff-index -m --name-only HEAD} gitdirty
  34. define GITHASH -$gitrev[expr {$gitdirty eq {} ? {} : {-dirty}}]
  35. }
  36. if {[string match *-linux* [get-define host]]} {
  37. cc-with { -libs { -lbsd }} {
  38. if {[cc-check-functions getprogname]} {
  39. define-append EXTRA_LIBS -lbsd
  40. define-feature libbsd
  41. } else {
  42. user-error "Unable to find libbsd"
  43. }
  44. }
  45. } else {
  46. define-feature static
  47. }
  48. if {![opt-bool with-libarchive.pc]} {
  49. cc-with { -libs { -larchive }} {
  50. if {![cc-check-functions archive_read_open]} {
  51. user-error "Unable to find libarchive"
  52. }
  53. }
  54. }
  55. cc-with { -libs { -lz }} {
  56. if {![cc-check-functions zlibVersion]} {
  57. user-error "Unable to find zlib"
  58. }
  59. }
  60. cc-with { -libs { -lbz2 }} {
  61. if {![cc-check-functions BZ2_bzReadOpen]} {
  62. user-error "Unable to find bzip2"
  63. }
  64. }
  65. cc-with { -libs { -llzma }} {
  66. if {![cc-check-functions lzma_version_string]} {
  67. user-error "Unable to find liblzma"
  68. }
  69. }
  70. cc-with { -libs { -larchive }} {
  71. cc-check-functions archive_write_add_filter_zstd
  72. }
  73. define ZSTDLIB ""
  74. cc-with { -libs { -lprivatezstd }} {
  75. if {[cc-check-functions ZSTD_versionNumber]} {
  76. define ZSTDLIB "-lprivatezstd"
  77. }
  78. }
  79. # Atomics
  80. msg-checking "Checking for atomic builtins... "
  81. if {[cctest -code {
  82. volatile unsigned long val = 1;
  83. __sync_synchronize();
  84. __sync_val_compare_and_swap(&val, 1, 0);
  85. __sync_add_and_fetch(&val, 1);
  86. __sync_sub_and_fetch(&val, 1);
  87. return 0;
  88. }
  89. ]} {
  90. msg-result ok
  91. define-feature atomic_builtins
  92. } else {
  93. msg-result no
  94. define-feature atomic_builtins 0
  95. }
  96. msg-checking "Checking for /proc/self/fd support... "
  97. if {[file exists /proc/self/fd]} {
  98. msg-result ok
  99. define-feature proc-pid
  100. } else {
  101. msg-result no
  102. define-feature proc-pid 0
  103. }
  104. foreach fct [list memmove usleep pread pwrite] {
  105. if {![cc-check-functions $fct]} {
  106. user-error "Cannot find $fct"
  107. }
  108. }
  109. cc-with { -includes fcntl.h } {
  110. cc-check-decls F_CLOSEM
  111. }
  112. cc-with { -includes sys/socket.h } {
  113. cc-check-decls SOCK_SEQPACKET
  114. }
  115. cc-with { -includes netinet/in.h } {
  116. cc-check-members "struct sockaddr_in.sin_len"
  117. }
  118. cc-with { -includes sys/stat.h } {
  119. cc-check-members "struct stat.st_mtim" "struct stat.st_flags"
  120. }
  121. # check for sqlite
  122. cc-check-functions gmtime_r isnan localtime_r strchrnul strerror_r fdatasync \
  123. fchown lstat readlink
  124. cc-check-includes stdint.h inttypes.h
  125. # check for pkg itself
  126. cc-check-functions arc4random arc4random_stir basename_r chflagsat \
  127. closefrom dirfd eaccess fopencookie fstatfs funopen strnstr \
  128. strtofflags strtonum sysconf utimensat __res_setservers unlinkat \
  129. faccessat fstatat openat readlinkat fflagstostr reallocarray strchrnul
  130. cc-with { -includes { libutil.h }} {
  131. if {[cc-check-decls humanize_number]} {
  132. }
  133. }
  134. if {![cc-check-functions fts_open]} {
  135. cc-with { -libs { -lfts }} {
  136. if {[cc-check-functions fts_open]} {
  137. define-feature LIBFTS
  138. }
  139. }
  140. }
  141. if {[get-define HAVE_DECL_HUMANIZE_NUMBER] eq 1} {
  142. cc-with { -libs { -lutil }} {
  143. if {[cc-check-functions humanize_number]} {
  144. define-feature LIBUTIL
  145. }
  146. }
  147. }
  148. if {![cc-check-functions dlclose]} {
  149. cc-with { -libs { -ldl }} {
  150. if {[cc-check-functions dlclose]} {
  151. define-feature LIBDL
  152. }
  153. }
  154. }
  155. if {![cc-check-functions __res_query]} {
  156. cc-with { -libs { -lresolv }} {
  157. if {[cc-check-functions __res_query]} {
  158. define-feature LIBRESOLV
  159. }
  160. }
  161. }
  162. cc-check-includes link.h machine/endian.h osreldate.h readpassphrase.h \
  163. sys/procctl.h sys/statfs.h sys/statvfs.h libutil.h
  164. # for compat
  165. cc-check-includes dirent.h
  166. #endian stuff
  167. foreach header [list endian.h sys/endian.h] {
  168. if {[cc-check-includes $header]} {
  169. cc-with [list -includes $header] {
  170. cc-check-decls be16dec be16enc be32dec be32enc be64dec be64enc \
  171. le16dec le16enc le32dec le32enc le64dec le64enc
  172. }
  173. }
  174. }
  175. if {[string match *-darwin* [get-define host]]} {
  176. define libmachista
  177. define waflags ""
  178. define nowaflags ""
  179. } else {
  180. # libelf
  181. define waflags "-Wl,-whole-archive"
  182. define nowaflags "-Wl,-no-whole-archive"
  183. cc-with { -includes { sys/types.h }} {
  184. cc-check-includes elf-hints.h sys/elf_common.h
  185. }
  186. if {[cc-check-includes gelf.h libelf.h]} {
  187. cc-with { -libs { -lelf } } {
  188. if {[cc-check-functions gelf_getehdr]} {
  189. define-feature libelf
  190. define libelf-external
  191. define-append EXTRA_LIBS -lelf
  192. cc-check-types Elf_Note
  193. } else {
  194. define libelf-internal
  195. define-feature libelf 0
  196. }
  197. }
  198. } else {
  199. define-feature libelf 0
  200. define libelf-internal
  201. }
  202. }
  203. cc-with { -libs { -ljail} } {
  204. if {[cc-check-functions jail_getid]} {
  205. define-feature libjail
  206. define-append EXTRA_LIBS -ljail
  207. }
  208. }
  209. # libbsd
  210. cc-check-includes bsd/err.h bsd/libutil.h bsd/readpassphrase.h \
  211. bsd/stdio.h bsd/strlib.h bsd/string.h bsd/sys/cdefs.h \
  212. bsd/unistd.h
  213. if {[opt-bool with-coverage]} {
  214. define-append COVERAGE_CFLAGS -O0 -ggdb -fprofile-instr-generate -fcoverage-mapping
  215. define-append COVERAGE_LDFLAGS -fprofile-instr-generate -fuse-ld=/usr/local/bin/ld.lld
  216. define CC /usr/local/bin/clang
  217. define CC_FOR_BUILD /usr/local/bin/clang
  218. define coverage 1
  219. # disable capsicum when coverage is used because coverage does not work in
  220. # capsicum mode
  221. } else {
  222. # capsicum
  223. if {[cc-check-functions cap_sandboxed]} {
  224. define-feature capsicum
  225. cc-check-includes sys/capsicum.h
  226. }
  227. }
  228. if {[pkg-config-init 0]} {
  229. # atf
  230. if {[pkg-config atf-c] && [cc-check-progs kyua]} {
  231. define TESTS
  232. puts "test suite will be built"
  233. } else {
  234. puts "Skipping test suite"
  235. }
  236. if {[opt-bool with-ldns]} {
  237. if {![pkg-config libldns]} {
  238. user-error "Unable to find libldns"
  239. } else {
  240. define PKG_LIBDNS_LIBS_STATIC [exec pkg-config --static --libs-only-l libldns]
  241. }
  242. }
  243. if {[opt-bool with-libarchive.pc]} {
  244. if {![pkg-config libarchive]} {
  245. user-error "Unable to find libarchive"
  246. } else {
  247. define PKG_LIBARCHIVE_LIBS_STATIC [exec pkg-config --static --libs-only-l libarchive]
  248. cc-with { -libs { -larchive }} {
  249. cc-check-functions archive_write_add_filter_zstd
  250. }
  251. }
  252. }
  253. }
  254. foreach repo [list binary] {
  255. define-append REPOS $repo
  256. define-append REPOS_LDFLAGS -L\$(top_builddir)/libpkg/repo/${repo} -lrepo-${repo}_pic
  257. define-append REPOS_STATIC_LIBS \$(top_builddir)/libpkg/repo/${repo}/librepo-${repo}.a
  258. }
  259. # ccache
  260. if {[get-define CCACHE] ne {none}} {
  261. define CC "[get-define CCACHE] [get-define CC]"
  262. }
  263. make-config-header pkg_config.h
  264. make-config-header external/sqlite/config.h
  265. make-template mk/defs.mk.in
  266. make-template libpkg/pkg.h.in
  267. make-template libpkg/pkg.pc.in
  268. make-template tests/frontend/test_environment.sh.in
  269. make-template Makefile.autosetup Makefile
  270. foreach dir [list external/blake2 external/picosat \
  271. external/linenoise external/libfetch external/sqlite \
  272. external compat libpkg libpkg/repo libpkg/repo/binary src \
  273. external/libucl external/libelf external/libmachista tests docs \
  274. external/liblua external/msgpuck external/yxml scripts] {
  275. make-template $dir/Makefile.autosetup $dir/Makefile
  276. }