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.

315 lines
7.6KB

  1. # vim:se syn=tcl:
  2. #
  3. use cc cc-lib cc-shared pkg-config
  4. set maj_ver 1
  5. set med_ver 12
  6. set min_ver 99
  7. set dev_ver 0
  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. define ZSTDLIB ""
  71. cc-with { -libs { -lprivatezstd }} {
  72. if {[cc-check-functions ZSTD_versionNumber]} {
  73. define ZSTDLIB "-lprivatezstd"
  74. }
  75. }
  76. # Atomics
  77. msg-checking "Checking for atomic builtins... "
  78. if {[cctest -code {
  79. volatile unsigned long val = 1;
  80. __sync_synchronize();
  81. __sync_val_compare_and_swap(&val, 1, 0);
  82. __sync_add_and_fetch(&val, 1);
  83. __sync_sub_and_fetch(&val, 1);
  84. return 0;
  85. }
  86. ]} {
  87. msg-result ok
  88. define-feature atomic_builtins
  89. } else {
  90. msg-result no
  91. define-feature atomic_builtins 0
  92. }
  93. msg-checking "Checking for /proc/self/fd support... "
  94. if {[file exists /proc/self/fd]} {
  95. msg-result ok
  96. define-feature proc-pid
  97. } else {
  98. msg-result no
  99. define-feature proc-pid 0
  100. }
  101. foreach fct [list memmove usleep pread pwrite] {
  102. if {![cc-check-functions $fct]} {
  103. user-error "Cannot find $fct"
  104. }
  105. }
  106. cc-with { -includes fcntl.h } {
  107. cc-check-decls F_CLOSEM
  108. }
  109. cc-with { -includes sys/socket.h } {
  110. cc-check-decls SOCK_SEQPACKET
  111. }
  112. cc-with { -includes netinet/in.h } {
  113. cc-check-members "struct sockaddr_in.sin_len"
  114. }
  115. cc-with { -includes sys/stat.h } {
  116. cc-check-members "struct stat.st_mtim" "struct stat.st_flags"
  117. }
  118. # check for sqlite
  119. cc-check-functions gmtime_r isnan localtime_r strchrnul strerror_r
  120. cc-check-includes stdint.h inttypes.h
  121. # check for pkg itself
  122. cc-check-functions arc4random arc4random_stir basename_r chflagsat \
  123. closefrom dirfd eaccess fopencookie fstatfs funopen strnstr \
  124. strtofflags strtonum sysconf utimensat __res_setservers unlinkat \
  125. faccessat fstatat openat readlinkat fflagstostr
  126. cc-with { -includes { libutil.h }} {
  127. if {[cc-check-decls humanize_number]} {
  128. }
  129. }
  130. if {![cc-check-functions fts_open]} {
  131. cc-with { -libs { -lfts }} {
  132. if {[cc-check-functions fts_open]} {
  133. define-feature LIBFTS
  134. }
  135. }
  136. }
  137. if {[get-define HAVE_DECL_HUMANIZE_NUMBER] eq 1} {
  138. cc-with { -libs { -lutil }} {
  139. if {[cc-check-functions humanize_number]} {
  140. define-feature LIBUTIL
  141. }
  142. }
  143. }
  144. if {![cc-check-functions dlclose]} {
  145. cc-with { -libs { -ldl }} {
  146. if {[cc-check-functions dlclose]} {
  147. define-feature LIBDL
  148. }
  149. }
  150. }
  151. if {![cc-check-functions __res_query]} {
  152. cc-with { -libs { -lresolv }} {
  153. if {[cc-check-functions __res_query]} {
  154. define-feature LIBRESOLV
  155. }
  156. }
  157. }
  158. cc-check-includes link.h machine/endian.h osreldate.h readpassphrase.h \
  159. sys/procctl.h sys/statfs.h sys/statvfs.h libutil.h
  160. # for compat
  161. cc-check-includes dirent.h
  162. #endian stuff
  163. foreach header [list endian.h sys/endian.h] {
  164. if {[cc-check-includes $header]} {
  165. cc-with [list -includes $header] {
  166. cc-check-decls be16dec be16enc be32dec be32enc be64dec be64enc \
  167. le16dec le16enc le32dec le32enc le64dec le64enc
  168. }
  169. }
  170. }
  171. if {[string match *-darwin* [get-define host]]} {
  172. define libabidir libmachista
  173. define waflags ""
  174. define nowaflags ""
  175. } else {
  176. # libelf
  177. define waflags "-Wl,-whole-archive"
  178. define nowaflags "-Wl,-no-whole-archive"
  179. cc-with { -includes { sys/types.h }} {
  180. cc-check-includes elf-hints.h sys/elf_common.h
  181. }
  182. if {[cc-check-includes gelf.h libelf.h]} {
  183. cc-with { -libs { -lelf } } {
  184. if {[cc-check-functions gelf_getehdr]} {
  185. define-feature libelf
  186. define-append EXTRA_LIBS -lelf
  187. define libabidir ""
  188. cc-check-types Elf_Note
  189. } else {
  190. define-feature libelf 0
  191. define libabidir "libelf"
  192. }
  193. }
  194. } else {
  195. define-feature libelf 0
  196. define libabidir "libelf"
  197. }
  198. }
  199. cc-with { -libs { -ljail} } {
  200. if {[cc-check-functions jail_getid]} {
  201. define-feature libjail
  202. define-append EXTRA_LIBS -ljail
  203. }
  204. }
  205. # libbsd
  206. cc-check-includes bsd/err.h bsd/libutil.h bsd/readpassphrase.h \
  207. bsd/stdio.h bsd/strlib.h bsd/string.h bsd/sys/cdefs.h \
  208. bsd/unistd.h
  209. if {[opt-bool with-coverage]} {
  210. define-append COVERAGE_CFLAGS -O0 -ggdb -fprofile-instr-generate -fcoverage-mapping
  211. define-append COVERAGE_LDFLAGS -fprofile-instr-generate -fuse-ld=/usr/local/bin/ld.lld
  212. define CC /usr/local/bin/clang
  213. define CC_FOR_BUILD /usr/local/bin/clang
  214. define coverage 1
  215. # disable capsicum when coverage is used because coverage does not work in
  216. # capsicum mode
  217. } else {
  218. # capsicum
  219. if {[cc-check-functions cap_sandboxed]} {
  220. define-feature capsicum
  221. cc-check-includes sys/capsicum.h
  222. }
  223. }
  224. define testsdir ""
  225. if {[pkg-config-init 0]} {
  226. # atf
  227. if {[pkg-config atf-c] && [cc-check-progs kyua]} {
  228. define testsdir tests
  229. puts "test suite will be built"
  230. } else {
  231. puts "Skipping test suite"
  232. }
  233. if {[opt-bool with-ldns]} {
  234. if {![pkg-config libldns]} {
  235. user-error "Unable to find libldns"
  236. } else {
  237. define PKG_LIBDNS_LIBS_STATIC [exec pkg-config --static --libs-only-l libldns]
  238. }
  239. }
  240. if {[opt-bool with-libarchive.pc]} {
  241. if {![pkg-config libarchive]} {
  242. user-error "Unable to find libarchive"
  243. } else {
  244. define PKG_LIBARCHIVE_LIBS_STATIC [exec pkg-config --static --libs-only-l libarchive]
  245. cc-with { -libs { -larchive }} {
  246. cc-check-functions archive_write_add_filter_zstd
  247. }
  248. }
  249. }
  250. }
  251. foreach repo [list binary] {
  252. define-append REPOS $repo
  253. define-append REPOS_LDFLAGS -L\$(top_builddir)/libpkg/repo/${repo} -lrepo-${repo}_pic
  254. define-append REPOS_STATIC_LIBS \$(top_builddir)/libpkg/repo/${repo}/librepo-${repo}.a
  255. }
  256. # ccache
  257. if {[get-define CCACHE] ne {none}} {
  258. define CC "[get-define CCACHE] [get-define CC]"
  259. }
  260. make-config-header pkg_config.h
  261. make-config-header external/sqlite/config.h
  262. make-template mk/defs.mk.in
  263. make-template libpkg/pkg.h.in
  264. make-template libpkg/pkg.pc.in
  265. make-template tests/frontend/test_environment.sh.in
  266. make-template Makefile.autosetup Makefile
  267. foreach dir [list external/blake2 external/picosat \
  268. external/linenoise external/libfetch external/sqlite \
  269. external compat libpkg libpkg/repo libpkg/repo/binary src \
  270. external/libucl external/libelf external/libmachista tests docs \
  271. external/liblua external/msgpuck external/yxml scripts] {
  272. make-template $dir/Makefile.autosetup $dir/Makefile
  273. }