Browse Source

Convert to autosetup

It allows to simplify the build system
While changing the build system, modify it to build pkg as a semi static
binary
tags/1.11.0
Baptiste Daroussin 2 years ago
parent
commit
6faf6c38f3
81 changed files with 30813 additions and 2164 deletions
  1. +10
    -23
      .gitignore
  2. +0
    -3
      .travis.yml
  3. +0
    -0
      Kyuafile
  4. +6
    -21
      Makefile.autosetup
  5. +0
    -1
      README.md
  6. +266
    -0
      auto.def
  7. +1
    -1
      autogen.sh
  8. +35
    -0
      autosetup/LICENSE
  9. +11
    -0
      autosetup/README.autosetup
  10. +2431
    -0
      autosetup/autosetup
  11. +1421
    -0
      autosetup/autosetup-config.guess
  12. +1807
    -0
      autosetup/autosetup-config.sub
  13. +17
    -0
      autosetup/autosetup-find-tclsh
  14. +20
    -0
      autosetup/autosetup-test-tclsh
  15. +15
    -0
      autosetup/cc-db.tcl
  16. +189
    -0
      autosetup/cc-lib.tcl
  17. +117
    -0
      autosetup/cc-shared.tcl
  18. +722
    -0
      autosetup/cc.tcl
  19. +25
    -0
      autosetup/default.auto
  20. +22274
    -0
      autosetup/jimsh0.c
  21. +186
    -0
      autosetup/pkg-config.tcl
  22. +325
    -0
      autosetup/system.tcl
  23. +55
    -0
      autosetup/tmake.auto
  24. +52
    -0
      autosetup/tmake.tcl
  25. +0
    -14
      compat/Makefile.am
  26. +16
    -0
      compat/Makefile.autosetup
  27. +5
    -5
      compat/bsd_compat.h
  28. +2
    -2
      compat/closefrom.c
  29. +7
    -7
      compat/file_at.c
  30. +3
    -0
      configure
  31. +0
    -552
      configure.ac
  32. +0
    -1
      dev_version.m4
  33. +0
    -52
      docs/Makefile.am
  34. +68
    -0
      docs/Makefile.autosetup
  35. +0
    -289
      external/Makefile.am
  36. +3
    -0
      external/Makefile.autosetup
  37. +0
    -11
      external/blake2/Makefile.am
  38. +6
    -0
      external/blake2/Makefile.autosetup
  39. +12
    -0
      external/expat/Makefile.autosetup
  40. +79
    -0
      external/libelf/Makefile.autosetup
  41. +0
    -81
      external/libfetch/Makefile
  42. +15
    -0
      external/libfetch/Makefile.autosetup
  43. +6
    -0
      external/libmachista/Makefile.autosetup
  44. +0
    -81
      external/libucl/Makefile.am
  45. +19
    -0
      external/libucl/Makefile.autosetup
  46. +0
    -9
      external/libucl/doc/Makefile.am
  47. +0
    -26
      external/libucl/lua/Makefile.am
  48. +0
    -30
      external/libucl/src/Makefile.am
  49. +0
    -45
      external/libucl/tests/Makefile.am
  50. +0
    -23
      external/libucl/utils/Makefile.am
  51. +5
    -0
      external/linenoise/Makefile.autosetup
  52. +7
    -0
      external/picosat/Makefile.autosetup
  53. +39
    -0
      external/sqlite/Makefile.autosetup
  54. +0
    -150
      libpkg/Makefile.am
  55. +141
    -0
      libpkg/Makefile.autosetup
  56. +0
    -1
      libpkg/repo/Makefile.am
  57. +20
    -0
      libpkg/repo/Makefile.autosetup
  58. +0
    -29
      libpkg/repo/binary/Makefile.am
  59. +17
    -0
      libpkg/repo/binary/Makefile.autosetup
  60. +2
    -0
      libpkg/xmalloc.h
  61. +0
    -5
      m4/.gitignore
  62. +0
    -70
      m4/ax_append_flag.m4
  63. +0
    -124
      m4/ax_cflags_warn_all.m4
  64. +0
    -37
      m4/ax_require_defined.m4
  65. +0
    -53
      m4/ld-version-script.m4
  66. +0
    -159
      m4/pkg.m4
  67. +15
    -0
      mk/common.mk
  68. +3
    -0
      mk/common.mk.in
  69. +26
    -0
      mk/defs.mk.in
  70. +14
    -0
      mk/dir.mk
  71. +18
    -0
      mk/lib.mk
  72. +13
    -0
      mk/prog.mk
  73. +16
    -0
      mk/static-lib.mk
  74. +0
    -13
      scripts/Makefile.am
  75. +39
    -0
      scripts/Makefile.autosetup
  76. +2
    -2
      scripts/travis_build.sh
  77. +0
    -105
      src/Makefile.am
  78. +78
    -0
      src/Makefile.autosetup
  79. +0
    -138
      tests/Makefile.am
  80. +131
    -0
      tests/Makefile.autosetup
  81. +1
    -1
      tests/frontend/test_environment.sh.in

+ 10
- 23
.gitignore View File

@@ -1,6 +1,7 @@
*.o
*.so*
*.a
*.pico
*.po
*.Po
*.So
@@ -41,13 +42,16 @@ scripts/sbin/pkg2ng
# Generated files:

/Makefile
/config.guess
/config.status
/config.sub
/compat/Makefile
/docs/Makefile
/external/Makefile
external/blake2/Makefile
/external/blake2/Makefile
/external/picosat/Makefile
/external/expat/Makefile
/external/linenoise/Makefile
/external/libucl/Makefile
/external/sqlite/Makefile
/external/sqlite/config.h
/external/libelf/libelf_convert.c
/external/libelf/libelf_fsize.c
/external/libelf/libelf_msize.c
@@ -55,27 +59,10 @@ external/blake2/Makefile
/libpkg/Makefile
/libpkg/repo/Makefile
/libpkg/repo/binary/Makefile
/libtool
/ltmain.sh
/pkg_config.h
/pkg_config.h.in
/pkg_repos.h
/scripts/Makefile
/src/Makefile
/test-driver
/tests/Makefile

# http://www.gnu.org/software/automake

Makefile.in

# http://www.gnu.org/software/autoconf

/autom4te.cache
/aclocal.m4
/compile
/configure
/depcomp
/install-sh
/missing
/stamp-h1
/tests/frontend/test_environment.sh
/mk/defs.mk

+ 0
- 3
.travis.yml View File

@@ -24,9 +24,6 @@ compiler:
before_install:
- scripts/install_deps.sh

before_script:
- autoreconf -i

script:
- scripts/travis_build.sh


Kyuafile.in → Kyuafile View File


Makefile.am → Makefile.autosetup View File

@@ -1,17 +1,10 @@
AUTOMAKE_OPTIONS= subdir-objects
ACLOCAL_AMFLAGS= -I m4
include @builddir@/mk/defs.mk
DIRS= external compat libpkg/repo libpkg src docs scripts @testsdir@

pkgconfigdir= $(prefix)/libdata/pkgconfig
pkgconfig_DATA= libpkg/pkg.pc
include $(MK)/dir.mk

$(pkgconfig_DATA): config.status

DISTCLEANFILES= pkg_repos.h
EXTRA_DIST= docs Kyuafile
dist-hook:
rm -rf `find $(distdir)/external -type d -name .deps`

check-local:
check: all
@if testsdir == "tests"
if [ "$(HTML)" != "" ]; then \
args="-r $(top_builddir)/res.db" ; \
fi ; \
@@ -23,6 +16,7 @@ check-local:
rm -f $(top_builddir)/res.db ; \
fi ; \
exit $${FAILED}
@endif

COCCI_ARGS= -I ${top_srcdir} \
-I /usr/include \
@@ -47,12 +41,3 @@ cocci:
spatch ${COCCI_ARGS} -in_place -sp_file $$c -dir ${top_srcdir}/libpkg ; \
spatch ${COCCI_ARGS} -in_place -sp_file $$c -dir ${top_srcdir}/src ; \
done

STYLEPATTERN= *.[c]

style-fix:
find ${top_srcdir}/src ${top_srcdir}/libpkg -name "${STYLEPATTERN}" | xargs \
uncrustify -c ${top_srcdir}/freebsd.cfg --no-backup


SUBDIRS = compat external libpkg src tests scripts docs

+ 0
- 1
README.md View File

@@ -270,7 +270,6 @@ Just open your browser and download the release you want.
Once you have the pkg sources, installing it is fairly easy:

% cd pkg
% ./autogen.sh
% ./configure
% make
# make install

+ 266
- 0
auto.def View File

@@ -0,0 +1,266 @@
# vim:se syn=tcl:
#

use cc cc-lib cc-shared pkg-config

set maj_ver 1
set med_ver 10
set min_ver 99
set dev_ver 8
define PKG_API [expr $maj_ver * 1000000 + $med_ver * 1000 + $min_ver]

if { $dev_ver ne 0 } {
define VERSION [format "%d.%d.%d.%d" $maj_ver $med_ver $min_ver $dev_ver]
} else {
define VERSION [format "%d.%d.%d" $maj_ver $med_ver $min_ver]
}

# 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"
}

if {[opt-str pkgconfigdir dir]} {
define pkgconfigdir $dir
} else {
if {[string match *-freebsd* [get-define host]]} {
define pkgconfigdir [format "%s/libdata/pkgconfig" [get-define prefix]]
} else {
define pkgconfigdir [format "%s/lib/pkgconfig" [get-define prefix]]
}
}

cc-check-tools ar ranlib strip

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

define GITHASH ""
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
if {$gitdirty eq "" } {
define GITHASH [format "-%s" $gitrev $gitdirty]
} else {
define GITHASH [format "-%s-dirty" $gitrev]
}
}

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"
}
}
}

if {![opt-bool with-libarchive.pc]} {
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"
}
}

# 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
}

set fatal_functions [list memmove usleep pread pwrite ]
foreach fct $fatal_functions {
if {![cc-check-functions $fct]} {
user-error "Cannot find $fct"
}
}

cc-with { -includes fcntl.h } {
if {[cc-check-decls F_CLOSEM]} {
define-feature f_closem 1
} else {
define-feature f_closem 0
}
}

cc-with { -includes sys/socket.h } {
if {[cc-check-decls SOCK_SEQPACKET]} {
define-feature seqpacket
}
}

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

cc-with { -includes sys/stat.h } {
cc-check-members "struct stat.st_mtim"
}

# check for sqlite
cc-check-functions gmtime_r isnan localtime_r strchrnul strerror_r
cc-check-includes stdint.h inttypes.h

# check for pkg itself
cc-check-functions arc4random arc4random_stir basename_r chflags chflagsat \
closefrom dirfd eaccess fopencookie fstatfs funopen strnstr \
strtofflags strtonum sysconf utimensat __res_setservers unlinkat \
faccessat fstatat openat readlinkat fflagstostr

cc-with { -libs { -lutil }} {
if {[cc-check-functions humanize_number]} {
define-feature LIBUTIL
}
}

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
set headers [list endian.h sys/endian.h]
foreach header $headers {
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]]} {
define libabidir libmachista
} else {
# libelf
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
define-append EXTRA_LIBS -lelf
define libabidir ""
} else {
define-feature libelf 0
define libabidir "libelf"
}
}
}
}

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 \
bsd/stdio.h bsd/strlib.h bsd/string.h bsd/sys/cdefs.h \
bsd/unistd.h
# capsicum
if {[cc-check-functions cap_sandboxed]} {
define-feature capsicum
cc-check-includes sys/capsicum.h sys/capability.h
}

define testsdir ""
if {[pkg-config-init 0]} {
# atf
if {[pkg-config atf-c] && [cc-check-progs kyua]} {
define testsdir tests
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]
}
}
}

set repos [list binary]

foreach repo $repos {
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
}

make-config-header pkg_config.h
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

set dirs [list external/expat external/blake2 external/picosat \
external/linenoise external/libfetch external/sqlite \
external compat libpkg libpkg/repo libpkg/repo/binary src \
external/libucl external/libelf external/libmachista tests docs scripts]

foreach dir $dirs {
make-template $dir/Makefile.autosetup $dir/Makefile
}

+ 1
- 1
autogen.sh View File

@@ -1,2 +1,2 @@
#!/bin/sh
autoreconf -if
true

+ 35
- 0
autosetup/LICENSE View File

@@ -0,0 +1,35 @@
Unless explicitly stated, all files which form part of autosetup
are released under the following license:

---------------------------------------------------------------------
autosetup - A build environment "autoconfigurator"

Copyright (c) 2010-2011, WorkWare Systems <http://workware.net.au/>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE WORKWARE SYSTEMS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WORKWARE
SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation
are those of the authors and should not be interpreted as representing
official policies, either expressed or implied, of WorkWare Systems.

+ 11
- 0
autosetup/README.autosetup View File

@@ -0,0 +1,11 @@
README.autosetup created by autosetup v0.6.8

This is the autosetup directory for a local install of autosetup.
It contains autosetup, support files and loadable modules.

*.tcl files in this directory are optional modules which
can be loaded with the 'use' directive.

*.auto files in this directory are auto-loaded.

For more information, see http://msteveb.github.com/autosetup/

+ 2431
- 0
autosetup/autosetup
File diff suppressed because it is too large
View File


+ 1421
- 0
autosetup/autosetup-config.guess
File diff suppressed because it is too large
View File


+ 1807
- 0
autosetup/autosetup-config.sub
File diff suppressed because it is too large
View File


+ 17
- 0
autosetup/autosetup-find-tclsh View File

@@ -0,0 +1,17 @@
#!/bin/sh
# Looks for a suitable tclsh or jimsh in the PATH
# If not found, builds a bootstrap jimsh from source
# Prefer $autosetup_tclsh if is set in the environment
d=`dirname "$0"`
{ "$d/jimsh0" "$d/autosetup-test-tclsh"; } 2>/dev/null && exit 0
PATH="$PATH:$d"; export PATH
for tclsh in $autosetup_tclsh jimsh tclsh tclsh8.5 tclsh8.6; do
{ $tclsh "$d/autosetup-test-tclsh"; } 2>/dev/null && exit 0
done
echo 1>&2 "No installed jimsh or tclsh, building local bootstrap jimsh0"
for cc in ${CC_FOR_BUILD:-cc} gcc; do
{ $cc -o "$d/jimsh0" "$d/jimsh0.c"; } 2>/dev/null || continue
"$d/jimsh0" "$d/autosetup-test-tclsh" && exit 0
done
echo 1>&2 "No working C compiler found. Tried ${CC_FOR_BUILD:-cc} and gcc."
echo false

+ 20
- 0
autosetup/autosetup-test-tclsh View File

@@ -0,0 +1,20 @@
# A small Tcl script to verify that the chosen
# interpreter works. Sometimes we might e.g. pick up
# an interpreter for a different arch.
# Outputs the full path to the interpreter

if {[catch {info version} version] == 0} {
# This is Jim Tcl
if {$version >= 0.72} {
# Ensure that regexp works
regexp (a.*?) a
puts [info nameofexecutable]
exit 0
}
} elseif {[catch {info tclversion} version] == 0} {
if {$version >= 8.5 && ![string match 8.5a* [info patchlevel]]} {
puts [info nameofexecutable]
exit 0
}
}
exit 1

+ 15
- 0
autosetup/cc-db.tcl View File

@@ -0,0 +1,15 @@
# Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# @synopsis:
#
# The 'cc-db' module provides a knowledge-base of system idiosyncrasies.
# In general, this module can always be included.

use cc

module-options {}

# openbsd needs sys/types.h to detect some system headers
cc-include-needs sys/socket.h sys/types.h
cc-include-needs netinet/in.h sys/types.h

+ 189
- 0
autosetup/cc-lib.tcl View File

@@ -0,0 +1,189 @@
# Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# @synopsis:
#
# Provides a library of common tests on top of the 'cc' module.

use cc

module-options {}

# @cc-check-lfs
#
# The equivalent of the 'AC_SYS_LARGEFILE' macro.
#
# defines 'HAVE_LFS' if LFS is available,
# and defines '_FILE_OFFSET_BITS=64' if necessary
#
# Returns 1 if 'LFS' is available or 0 otherwise
#
proc cc-check-lfs {} {
cc-check-includes sys/types.h
msg-checking "Checking if -D_FILE_OFFSET_BITS=64 is needed..."
set lfs 1
if {[msg-quiet cc-with {-includes sys/types.h} {cc-check-sizeof off_t}] == 8} {
msg-result no
} elseif {[msg-quiet cc-with {-includes sys/types.h -cflags -D_FILE_OFFSET_BITS=64} {cc-check-sizeof off_t}] == 8} {
define _FILE_OFFSET_BITS 64
msg-result yes
} else {
set lfs 0
msg-result none
}
define-feature lfs $lfs
return $lfs
}

# @cc-check-endian
#
# The equivalent of the 'AC_C_BIGENDIAN' macro.
#
# defines 'HAVE_BIG_ENDIAN' if endian is known to be big,
# or 'HAVE_LITTLE_ENDIAN' if endian is known to be little.
#
# Returns 1 if determined, or 0 if not.
#
proc cc-check-endian {} {
cc-check-includes sys/types.h sys/param.h
set rc 0
msg-checking "Checking endian..."
cc-with {-includes {sys/types.h sys/param.h}} {
if {[cctest -code {
#if !defined(BIG_ENDIAN) || !defined(BYTE_ORDER)
#error unknown
#elif BYTE_ORDER != BIG_ENDIAN
#error little
#endif
}]} {
define-feature big-endian
msg-result "big"
set rc 1
} elseif {[cctest -code {
#if !defined(LITTLE_ENDIAN) || !defined(BYTE_ORDER)
#error unknown
#elif BYTE_ORDER != LITTLE_ENDIAN
#error big
#endif
}]} {
define-feature little-endian
msg-result "little"
set rc 1
} else {
msg-result "unknown"
}
}
return $rc
}

# @cc-check-flags flag ?...?
#
# Checks whether the given C/C++ compiler flags can be used. Defines feature
# names prefixed with 'HAVE_CFLAG' and 'HAVE_CXXFLAG' respectively, and
# appends working flags to '-cflags' and 'CFLAGS' or 'CXXFLAGS'.
proc cc-check-flags {args} {
set result 1
array set opts [cc-get-settings]
switch -exact -- $opts(-lang) {
c++ {
set lang C++
set prefix CXXFLAG
}
c {
set lang C
set prefix CFLAG
}
default {
autosetup-error "cc-check-flags failed with unknown language: $opts(-lang)"
}
}
foreach flag $args {
msg-checking "Checking whether the $lang compiler accepts $flag..."
if {[cctest -cflags $flag]} {
msg-result yes
define-feature $prefix$flag
cc-with [list -cflags [list $flag]]
define-append ${prefix}S $flag
} else {
msg-result no
set result 0
}
}
return $result
}

# @cc-check-standards ver ?...?
#
# Checks whether the C/C++ compiler accepts one of the specified '-std=$ver'
# options, and appends the first working one to '-cflags' and 'CFLAGS' or
# 'CXXFLAGS'.
proc cc-check-standards {args} {
array set opts [cc-get-settings]
foreach std $args {
if {[cc-check-flags -std=$std]} {
return $std
}
}
return ""
}

# Checks whether $keyword is usable as alignof
proc cctest_alignof {keyword} {
msg-checking "Checking for $keyword..."
if {[cctest -code "int x = ${keyword}(char), y = ${keyword}('x');"]} then {
msg-result ok
define-feature $keyword
} else {
msg-result "not found"
}
}

# @cc-check-c11
#
# Checks for several C11/C++11 extensions and their alternatives. Currently
# checks for '_Static_assert', '_Alignof', '__alignof__', '__alignof'.
proc cc-check-c11 {} {
msg-checking "Checking for _Static_assert..."
if {[cctest -code {
_Static_assert(1, "static assertions are available");
}]} then {
msg-result ok
define-feature _Static_assert
} else {
msg-result "not found"
}

cctest_alignof _Alignof
cctest_alignof __alignof__
cctest_alignof __alignof
}

# @cc-check-alloca
#
# The equivalent of the 'AC_FUNC_ALLOCA' macro.
#
# Checks for the existence of 'alloca'
# defines 'HAVE_ALLOCA' and returns 1 if it exists.
proc cc-check-alloca {} {
cc-check-some-feature alloca {
cctest -includes alloca.h -code { alloca (2 * sizeof (int)); }
}
}

# @cc-signal-return-type
#
# The equivalent of the 'AC_TYPE_SIGNAL' macro.
#
# defines 'RETSIGTYPE' to 'int' or 'void'.
proc cc-signal-return-type {} {
msg-checking "Checking return type of signal handlers..."
cc-with {-includes {sys/types.h signal.h}} {
if {[cctest -code {return *(signal (0, 0)) (0) == 1;}]} {
set type int
} else {
set type void
}
define RETSIGTYPE $type
msg-result $type
}
}

+ 117
- 0
autosetup/cc-shared.tcl View File

@@ -0,0 +1,117 @@
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# @synopsis:
#
# The 'cc-shared' module provides support for shared libraries and shared objects.
# It defines the following variables:
#
## SH_CFLAGS Flags to use compiling sources destined for a shared library
## SH_LDFLAGS Flags to use linking (creating) a shared library
## SH_SOPREFIX Prefix to use to set the soname when creating a shared library
## SH_SOEXT Extension for shared libs
## SH_SOEXTVER Format for versioned shared libs - %s = version
## SHOBJ_CFLAGS Flags to use compiling sources destined for a shared object
## SHOBJ_LDFLAGS Flags to use linking a shared object, undefined symbols allowed
## SHOBJ_LDFLAGS_R - as above, but all symbols must be resolved
## SH_LINKFLAGS Flags to use linking an executable which will load shared objects
## LD_LIBRARY_PATH Environment variable which specifies path to shared libraries
## STRIPLIBFLAGS Arguments to strip a dynamic library

module-options {}

# Defaults: gcc on unix
define SHOBJ_CFLAGS -fpic
define SHOBJ_LDFLAGS -shared
define SH_CFLAGS -fpic
define SH_LDFLAGS -shared
define SH_LINKFLAGS -rdynamic
define SH_SOEXT .so
define SH_SOEXTVER .so.%s
define SH_SOPREFIX -Wl,-soname,
define LD_LIBRARY_PATH LD_LIBRARY_PATH
define STRIPLIBFLAGS --strip-unneeded

# Note: This is a helpful reference for identifying the toolchain
# http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers

switch -glob -- [get-define host] {
*-*-darwin* {
define SHOBJ_CFLAGS "-dynamic -fno-common"
define SHOBJ_LDFLAGS "-bundle -undefined dynamic_lookup"
define SHOBJ_LDFLAGS_R -bundle
define SH_CFLAGS -dynamic
define SH_LDFLAGS -dynamiclib
define SH_LINKFLAGS ""
define SH_SOEXT .dylib
define SH_SOEXTVER .%s.dylib
define SH_SOPREFIX -Wl,-install_name,
define LD_LIBRARY_PATH DYLD_LIBRARY_PATH
define STRIPLIBFLAGS -x
}
*-*-ming* - *-*-cygwin - *-*-msys {
define SHOBJ_CFLAGS ""
define SHOBJ_LDFLAGS -shared
define SH_CFLAGS ""
define SH_LDFLAGS -shared
define SH_LINKFLAGS ""
define SH_SOEXT .dll
define SH_SOEXTVER .dll
define SH_SOPREFIX ""
define LD_LIBRARY_PATH PATH
}
sparc* {
if {[msg-quiet cc-check-decls __SUNPRO_C]} {
msg-result "Found sun stdio compiler"
# sun stdio compiler
# XXX: These haven't been fully tested.
define SHOBJ_CFLAGS -KPIC
define SHOBJ_LDFLAGS "-G"
define SH_CFLAGS -KPIC
define SH_LINKFLAGS -Wl,-export-dynamic
define SH_SOPREFIX -Wl,-h,
} else {
# sparc has a very small GOT table limit, so use -fPIC
define SH_CFLAGS -fPIC
define SHOBJ_CFLAGS -fPIC
}
}
*-*-solaris* {
if {[msg-quiet cc-check-decls __SUNPRO_C]} {
msg-result "Found sun stdio compiler"
# sun stdio compiler
# XXX: These haven't been fully tested.
define SHOBJ_CFLAGS -KPIC
define SHOBJ_LDFLAGS "-G"
define SH_CFLAGS -KPIC
define SH_LINKFLAGS -Wl,-export-dynamic
define SH_SOPREFIX -Wl,-h,
}
}
*-*-hpux {
# XXX: These haven't been tested
define SHOBJ_CFLAGS "+O3 +z"
define SHOBJ_LDFLAGS -b
define SH_CFLAGS +z
define SH_LINKFLAGS -Wl,+s
define LD_LIBRARY_PATH SHLIB_PATH
}
*-*-haiku {
define SHOBJ_CFLAGS ""
define SHOBJ_LDFLAGS -shared
define SH_CFLAGS ""
define SH_LDFLAGS -shared
define SH_LINKFLAGS ""
define SH_SOPREFIX ""
define LD_LIBRARY_PATH LIBRARY_PATH
}
microblaze* {
# Microblaze generally needs -fPIC rather than -fpic
define SHOBJ_CFLAGS -fPIC
define SH_CFLAGS -fPIC
}
}

if {![is-defined SHOBJ_LDFLAGS_R]} {
define SHOBJ_LDFLAGS_R [get-define SHOBJ_LDFLAGS]
}

+ 722
- 0
autosetup/cc.tcl View File

@@ -0,0 +1,722 @@
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# @synopsis:
#
# The 'cc' module supports checking various 'features' of the C or C++
# compiler/linker environment. Common commands are 'cc-check-includes',
# 'cc-check-types', 'cc-check-functions', 'cc-with', 'make-config-header' and 'make-template'.
#
# The following environment variables are used if set:
#
## CC - C compiler
## CXX - C++ compiler
## CCACHE - Set to "none" to disable automatic use of ccache
## CFLAGS - Additional C compiler flags
## CXXFLAGS - Additional C++ compiler flags
## LDFLAGS - Additional compiler flags during linking
## LIBS - Additional libraries to use (for all tests)
## CROSS - Tool prefix for cross compilation
#
# The following variables are defined from the corresponding
# environment variables if set.
#
## CPPFLAGS
## LINKFLAGS
## CC_FOR_BUILD
## LD

use system

module-options {}

# Checks for the existence of the given function by linking
#
proc cctest_function {function} {
cctest -link 1 -declare "extern void $function\(void);" -code "$function\();"
}

# Checks for the existence of the given type by compiling
proc cctest_type {type} {
cctest -code "$type _x;"
}

# Checks for the existence of the given type/structure member.
# e.g. "struct stat.st_mtime"
proc cctest_member {struct_member} {
# split at the first dot
regexp {^([^.]+)[.](.*)$} $struct_member -> struct member
cctest -code "static $struct _s; return sizeof(_s.$member);"
}

# Checks for the existence of the given define by compiling
#
proc cctest_define {name} {
cctest -code "#ifndef $name\n#error not defined\n#endif"
}

# Checks for the existence of the given name either as
# a macro (#define) or an rvalue (such as an enum)
#
proc cctest_decl {name} {
cctest -code "#ifndef $name\n(void)$name;\n#endif"
}

# @cc-check-sizeof type ...
#
# Checks the size of the given types (between 1 and 32, inclusive).
# Defines a variable with the size determined, or 'unknown' otherwise.
# e.g. for type 'long long', defines 'SIZEOF_LONG_LONG'.
# Returns the size of the last type.
#
proc cc-check-sizeof {args} {
foreach type $args {
msg-checking "Checking for sizeof $type..."
set size unknown
# Try the most common sizes first
foreach i {4 8 1 2 16 32} {
if {[cctest -code "static int _x\[sizeof($type) == $i ? 1 : -1\] = { 1 };"]} {
set size $i
break
}
}
msg-result $size
set define [feature-define-name $type SIZEOF_]
define $define $size
}
# Return the last result
get-define $define
}

# Checks for each feature in $list by using the given script.
#
# When the script is evaluated, $each is set to the feature
# being checked, and $extra is set to any additional cctest args.
#
# Returns 1 if all features were found, or 0 otherwise.
proc cc-check-some-feature {list script} {
set ret 1
foreach each $list {
if {![check-feature $each $script]} {
set ret 0
}
}
return $ret
}

# @cc-check-includes includes ...
#
# Checks that the given include files can be used.
proc cc-check-includes {args} {
cc-check-some-feature $args {
set with {}
if {[dict exists $::autosetup(cc-include-deps) $each]} {
set deps [dict keys [dict get $::autosetup(cc-include-deps) $each]]
msg-quiet cc-check-includes {*}$deps
foreach i $deps {
if {[have-feature $i]} {
lappend with $i
}
}
}
if {[llength $with]} {
cc-with [list -includes $with] {
cctest -includes $each
}
} else {
cctest -includes $each
}
}
}

# @cc-include-needs include required ...
#
# Ensures that when checking for '$include', a check is first
# made for each '$required' file, and if found, it is included with '#include'.
proc cc-include-needs {file args} {
foreach depfile $args {
dict set ::autosetup(cc-include-deps) $file $depfile 1
}
}

# @cc-check-types type ...
#
# Checks that the types exist.
proc cc-check-types {args} {
cc-check-some-feature $args {
cctest_type $each
}
}

# @cc-check-defines define ...
#
# Checks that the given preprocessor symbols are defined.
proc cc-check-defines {args} {
cc-check-some-feature $args {
cctest_define $each
}
}

# @cc-check-decls name ...
#
# Checks that each given name is either a preprocessor symbol or rvalue
# such as an enum. Note that the define used is 'HAVE_DECL_xxx'
# rather than 'HAVE_xxx'.
proc cc-check-decls {args} {
set ret 1
foreach name $args {
msg-checking "Checking for $name..."
set r [cctest_decl $name]
define-feature "decl $name" $r
if {$r} {
msg-result "ok"
} else {
msg-result "not found"
set ret 0
}
}
return $ret
}

# @cc-check-functions function ...
#
# Checks that the given functions exist (can be linked).
proc cc-check-functions {args} {
cc-check-some-feature $args {
cctest_function $each
}
}

# @cc-check-members type.member ...
#
# Checks that the given type/structure members exist.
# A structure member is of the form 'struct stat.st_mtime'.
proc cc-check-members {args} {
cc-check-some-feature $args {
cctest_member $each
}
}

# @cc-check-function-in-lib function libs ?otherlibs?
#
# Checks that the given function can be found in one of the libs.
#
# First checks for no library required, then checks each of the libraries
# in turn.
#
# If the function is found, the feature is defined and 'lib_$function' is defined
# to '-l$lib' where the function was found, or "" if no library required.
# In addition, '-l$lib' is prepended to the 'LIBS' define.
#
# If additional libraries may be needed for linking, they should be specified
# with '$extralibs' as '-lotherlib1 -lotherlib2'.
# These libraries are not automatically added to 'LIBS'.
#
# Returns 1 if found or 0 if not.
#
proc cc-check-function-in-lib {function libs {otherlibs {}}} {
msg-checking "Checking libs for $function..."
set found 0
cc-with [list -libs $otherlibs] {
if {[cctest_function $function]} {
msg-result "none needed"
define lib_$function ""
incr found
} else {
foreach lib $libs {
cc-with [list -libs -l$lib] {
if {[cctest_function $function]} {
msg-result -l$lib
define lib_$function -l$lib
# prepend to LIBS
define LIBS "-l$lib [get-define LIBS]"
incr found
break
}
}
}
}
}
define-feature $function $found
if {!$found} {
msg-result "no"
}
return $found
}

# @cc-check-tools tool ...
#
# Checks for existence of the given compiler tools, taking
# into account any cross compilation prefix.
#
# For example, when checking for 'ar', first 'AR' is checked on the command
# line and then in the environment. If not found, '${host}-ar' or
# simply 'ar' is assumed depending upon whether cross compiling.
# The path is searched for this executable, and if found 'AR' is defined
# to the executable name.
# Note that even when cross compiling, the simple 'ar' is used as a fallback,
# but a warning is generated. This is necessary for some toolchains.
#
# It is an error if the executable is not found.
#
proc cc-check-tools {args} {
foreach tool $args {
set TOOL [string toupper $tool]
set exe [get-env $TOOL [get-define cross]$tool]
if {[find-executable {*}$exe]} {
define $TOOL $exe
continue
}
if {[find-executable {*}$tool]} {
msg-result "Warning: Failed to find $exe, falling back to $tool which may be incorrect"
define $TOOL $tool
continue
}
user-error "Failed to find $exe"
}
}

# @cc-check-progs prog ...
#
# Checks for existence of the given executables on the path.
#
# For example, when checking for 'grep', the path is searched for
# the executable, 'grep', and if found 'GREP' is defined as 'grep'.
#
# If the executable is not found, the variable is defined as 'false'.
# Returns 1 if all programs were found, or 0 otherwise.
#
proc cc-check-progs {args} {
set failed 0
foreach prog $args {
set PROG [string toupper $prog]
msg-checking "Checking for $prog..."
if {![find-executable $prog]} {
msg-result no
define $PROG false
incr failed
} else {
msg-result ok
define $PROG $prog
}
}
expr {!$failed}
}

# @cc-path-progs prog ...
#
# Like cc-check-progs, but sets the define to the full path rather
# than just the program name.
#
proc cc-path-progs {args} {
set failed 0
foreach prog $args {
set PROG [string toupper $prog]
msg-checking "Checking for $prog..."
set path [find-executable-path $prog]
if {$path eq ""} {
msg-result no
define $PROG false
incr failed
} else {
msg-result $path
define $PROG $path
}
}
expr {!$failed}
}

# Adds the given settings to $::autosetup(ccsettings) and
# returns the old settings.
#
proc cc-add-settings {settings} {
if {[llength $settings] % 2} {
autosetup-error "settings list is missing a value: $settings"
}

set prev [cc-get-settings]
# workaround a bug in some versions of jimsh by forcing
# conversion of $prev to a list
llength $prev

array set new $prev

foreach {name value} $settings {
switch -exact -- $name {
-cflags - -includes {
# These are given as lists
lappend new($name) {*}[list-non-empty $value]
}
-declare {
lappend new($name) $value
}
-libs {
# Note that new libraries are added before previous libraries
set new($name) [list {*}[list-non-empty $value] {*}$new($name)]
}
-link - -lang - -nooutput {
set new($name) $value
}
-source - -sourcefile - -code {
# XXX: These probably are only valid directly from cctest
set new($name) $value
}
default {
autosetup-error "unknown cctest setting: $name"
}
}
}

cc-store-settings [array get new]

return $prev
}

proc cc-store-settings {new} {
set ::autosetup(ccsettings) $new
}

proc cc-get-settings {} {
return $::autosetup(ccsettings)
}

# Similar to cc-add-settings, but each given setting
# simply replaces the existing value.
#
# Returns the previous settings
proc cc-update-settings {args} {
set prev [cc-get-settings]
cc-store-settings [dict merge $prev $args]
return $prev
}

# @cc-with settings ?{ script }?
#
# Sets the given 'cctest' settings and then runs the tests in '$script'.
# Note that settings such as '-lang' replace the current setting, while
# those such as '-includes' are appended to the existing setting.
#
# If no script is given, the settings become the default for the remainder
# of the 'auto.def' file.
#
## cc-with {-lang c++} {
## # This will check with the C++ compiler
## cc-check-types bool
## cc-with {-includes signal.h} {
## # This will check with the C++ compiler, signal.h and any existing includes.
## ...
## }
## # back to just the C++ compiler
## }
#
# The '-libs' setting is special in that newer values are added *before* earlier ones.
#
## cc-with {-libs {-lc -lm}} {
## cc-with {-libs -ldl} {
## cctest -libs -lsocket ...
## # libs will be in this order: -lsocket -ldl -lc -lm
## }
## }
proc cc-with {settings args} {
if {[llength $args] == 0} {
cc-add-settings $settings
} elseif {[llength $args] > 1} {
autosetup-error "usage: cc-with settings ?script?"
} else {
set save [cc-add-settings $settings]
set rc [catch {uplevel 1 [lindex $args 0]} result info]
cc-store-settings $save
if {$rc != 0} {
return -code [dict get $info -code] $result
}
return $result
}
}

# @cctest ?settings?
#
# Low level C/C++ compiler checker. Compiles and or links a small C program
# according to the arguments and returns 1 if OK, or 0 if not.
#
# Supported settings are:
#
## -cflags cflags A list of flags to pass to the compiler
## -includes list A list of includes, e.g. {stdlib.h stdio.h}
## -declare code Code to declare before main()
## -link 1 Don't just compile, link too
## -lang c|c++ Use the C (default) or C++ compiler
## -libs liblist List of libraries to link, e.g. {-ldl -lm}
## -code code Code to compile in the body of main()
## -source code Compile a complete program. Ignore -includes, -declare and -code
## -sourcefile file Shorthand for -source [readfile [get-define srcdir]/$file]
## -nooutput 1 Treat any compiler output (e.g. a warning) as an error
#
# Unless '-source' or '-sourcefile' is specified, the C program looks like:
#
## #include <firstinclude> /* same for remaining includes in the list */
##
## declare-code /* any code in -declare, verbatim */
##
## int main(void) {
## code /* any code in -code, verbatim */
## return 0;
## }
#
# Any failures are recorded in 'config.log'
#
proc cctest {args} {
set src conftest__.c
set tmp conftest__

# Easiest way to merge in the settings
cc-with $args {
array set opts [cc-get-settings]
}

if {[info exists opts(-sourcefile)]} {
set opts(-source) [readfile [get-define srcdir]/$opts(-sourcefile) "#error can't find $opts(-sourcefile)"]
}
if {[info exists opts(-source)]} {
set lines $opts(-source)
} else {
foreach i $opts(-includes) {
if {$opts(-code) ne "" && ![feature-checked $i]} {
# Compiling real code with an unchecked header file
# Quickly (and silently) check for it now

# Remove all -includes from settings before checking
set saveopts [cc-update-settings -includes {}]
msg-quiet cc-check-includes $i
cc-store-settings $saveopts
}
if {$opts(-code) eq "" || [have-feature $i]} {
lappend source "#include <$i>"
}
}
lappend source {*}$opts(-declare)
lappend source "int main(void) {"
lappend source $opts(-code)
lappend source "return 0;"
lappend source "}"

set lines [join $source \n]
}

# Build the command line
set cmdline {}
lappend cmdline {*}[get-define CCACHE]
switch -exact -- $opts(-lang) {
c++ {
lappend cmdline {*}[get-define CXX] {*}[get-define CXXFLAGS]
}
c {
lappend cmdline {*}[get-define CC] {*}[get-define CFLAGS]
}
default {
autosetup-error "cctest called with unknown language: $opts(-lang)"
}
}

if {$opts(-link)} {
lappend cmdline {*}[get-define LDFLAGS]
} else {
set tmp conftest__.o
lappend cmdline -c
}
lappend cmdline {*}$opts(-cflags) {*}[get-define cc-default-debug ""]
lappend cmdline $src -o $tmp {*}$opts(-libs)
if {$opts(-link)} {
lappend cmdline {*}[get-define LIBS]
}

# At this point we have the complete command line and the
# complete source to be compiled. Get the result from cache if
# we can
if {[info exists ::cc_cache($cmdline,$lines)]} {
msg-checking "(cached) "
set ok $::cc_cache($cmdline,$lines)
if {$::autosetup(debug)} {
configlog "From cache (ok=$ok): [join $cmdline]"
configlog "============"
configlog $lines
configlog "============"
}
return $ok
}

writefile $src $lines\n

set ok 1
set err [catch {exec-with-stderr {*}$cmdline} result errinfo]
if {$err || ($opts(-nooutput) && [string length $result])} {
configlog "Failed: [join $cmdline]"
configlog $result
configlog "============"
configlog "The failed code was:"
configlog $lines
configlog "============"
set ok 0
} elseif {$::autosetup(debug)} {
configlog "Compiled OK: [join $cmdline]"
configlog "============"
configlog $lines
configlog "============"
}
file delete $src
file delete $tmp

# cache it
set ::cc_cache($cmdline,$lines) $ok

return $ok
}

# @make-autoconf-h outfile ?auto-patterns=HAVE_*? ?bare-patterns=SIZEOF_*?
#
# Deprecated - see 'make-config-header'
proc make-autoconf-h {file {autopatterns {HAVE_*}} {barepatterns {SIZEOF_* HAVE_DECL_*}}} {
user-notice "*** make-autoconf-h is deprecated -- use make-config-header instead"
make-config-header $file -auto $autopatterns -bare $barepatterns
}

# @make-config-header outfile ?-auto patternlist? ?-bare patternlist? ?-none patternlist? ?-str patternlist? ...
#
# Examines all defined variables which match the given patterns
# and writes an include file, '$file', which defines each of these.
# Variables which match '-auto' are output as follows:
# - defines which have the value '0' are ignored.
# - defines which have integer values are defined as the integer value.
# - any other value is defined as a string, e.g. '"value"'
# Variables which match '-bare' are defined as-is.
# Variables which match '-str' are defined as a string, e.g. '"value"'
# Variables which match '-none' are omitted.
#
# Note that order is important. The first pattern that matches is selected.
# Default behaviour is:
#
## -bare {SIZEOF_* HAVE_DECL_*} -auto HAVE_* -none *
#
# If the file would be unchanged, it is not written.
proc make-config-header {file args} {
set guard _[string toupper [regsub -all {[^a-zA-Z0-9]} [file tail $file] _]]
file mkdir [file dirname $file]
set lines {}
lappend lines "#ifndef $guard"
lappend lines "#define $guard"

# Add some defaults
lappend args -bare {SIZEOF_* HAVE_DECL_*} -auto HAVE_*

foreach n [lsort [dict keys [all-defines]]] {
set value [get-define $n]
set type [calc-define-output-type $n $args]
switch -exact -- $type {
-bare {
# Just output the value unchanged
}
-none {
continue
}
-str {
set value \"[string map [list \\ \\\\ \" \\\"] $value]\"
}
-auto {
# Automatically determine the type
if {$value eq "0"} {
lappend lines "/* #undef $n */"
continue
}
if {![string is integer -strict $value]} {
set value \"[string map [list \\ \\\\ \" \\\"] $value]\"
}
}
"" {
continue
}
default {
autosetup-error "Unknown type in make-config-header: $type"
}
}
lappend lines "#define $n $value"
}
lappend lines "#endif"
set buf [join $lines \n]
write-if-changed $file $buf {
msg-result "Created $file"
}
}

proc calc-define-output-type {name spec} {
foreach {type patterns} $spec {
foreach pattern $patterns {
if {[string match $pattern $name]} {
return $type
}
}
}
return ""
}

# Initialise some values from the environment or commandline or default settings
foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS {CFLAGS "-g -O2"}} {
lassign $i var default
define $var [get-env $var $default]
}

if {[env-is-set CC]} {
# Set by the user, so don't try anything else
set try [list [get-env CC ""]]
} else {
# Try some reasonable options
set try [list [get-define cross]cc [get-define cross]gcc]
}
define CC [find-an-executable {*}$try]
if {[get-define CC] eq ""} {
user-error "Could not find a C compiler. Tried: [join $try ", "]"
}

define CPP [get-env CPP "[get-define CC] -E"]

# XXX: Could avoid looking for a C++ compiler until requested
# Note that if CXX isn't found, we just set it to "false". It might not be needed.
if {[env-is-set CXX]} {
define CXX [find-an-executable -required [get-env CXX ""]]
} else {
define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++ false]
}

# CXXFLAGS default to CFLAGS if not specified
define CXXFLAGS [get-env CXXFLAGS [get-define CFLAGS]]

# May need a CC_FOR_BUILD, so look for one
define CC_FOR_BUILD [find-an-executable [get-env CC_FOR_BUILD ""] cc gcc false]

if {[get-define CC] eq ""} {
user-error "Could not find a C compiler. Tried: [join $try ", "]"
}

define CCACHE [find-an-executable [get-env CCACHE ccache]]

# Initial cctest settings
cc-store-settings {-cflags {} -includes {} -declare {} -link 0 -lang c -libs {} -code {} -nooutput 0}
set autosetup(cc-include-deps) {}

msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS]"
if {[get-define CXX] ne "false"} {
msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS]"
}
msg-result "Build C compiler...[get-define CC_FOR_BUILD]"

# On Darwin, we prefer to use -g0 to avoid creating .dSYM directories
# but some compilers may not support it, so test here.
switch -glob -- [get-define host] {
*-*-darwin* {
if {[cctest -cflags {-g0}]} {
define cc-default-debug -g0
}
}
}

if {![cc-check-includes stdlib.h]} {
user-error "Compiler does not work. See config.log"
}

+ 25
- 0
autosetup/default.auto View File

@@ -0,0 +1,25 @@
# Copyright (c) 2012 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# Auto-load module for 'make' build system integration

use init

autosetup_add_init_type make {Simple "make" build system} {
autosetup_check_create auto.def \
{# Initial auto.def created by 'autosetup --init=make'

use cc

# Add any user options here
options {
}

make-config-header config.h
make-template Makefile.in
}

if {![file exists Makefile.in]} {
puts "Note: I don't see Makefile.in. You will probably need to create one."
}
}

+ 22274
- 0
autosetup/jimsh0.c
File diff suppressed because it is too large
View File


+ 186
- 0
autosetup/pkg-config.tcl View File

@@ -0,0 +1,186 @@
# Copyright (c) 2016 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# @synopsis:
#
# The 'pkg-config' module allows package information to be found via 'pkg-config'.
#
# If not cross-compiling, the package path should be determined automatically
# by 'pkg-config'.
# If cross-compiling, the default package path is the compiler sysroot.
# If the C compiler doesn't support '-print-sysroot', the path can be supplied
# by the '--sysroot' option or by defining 'SYSROOT'.
#
# 'PKG_CONFIG' may be set to use an alternative to 'pkg-config'.

use cc

module-options {
sysroot:dir => "Override compiler sysroot for pkg-config search path"
}

# @pkg-config-init ?required?
#
# Initialises the 'pkg-config' system. Unless '$required' is set to 0,
# it is a fatal error if a usable 'pkg-config' is not found .
#
# This command will normally be called automatically as required,
# but it may be invoked explicitly if lack of 'pkg-config' is acceptable.
#
# Returns 1 if ok, or 0 if 'pkg-config' not found/usable (only if '$required' is 0).
#
proc pkg-config-init {{required 1}} {
if {[is-defined HAVE_PKG_CONFIG]} {
return [get-define HAVE_PKG_CONFIG]
}
set found 0

define PKG_CONFIG [get-env PKG_CONFIG pkg-config]
msg-checking "Checking for pkg-config..."

if {[catch {exec [get-define PKG_CONFIG] --version} version]} {
msg-result "[get-define PKG_CONFIG] (not found)"
if {$required} {
user-error "No usable pkg-config"
}
} else {
msg-result $version
define PKG_CONFIG_VERSION $version

set found 1

if {[opt-str sysroot o]} {
define SYSROOT [file-normalize $o]
msg-result "Using specified sysroot [get-define SYSROOT]"
} elseif {[get-define build] ne [get-define host]} {
if {[catch {exec-with-stderr [get-define CC] -print-sysroot} result errinfo] == 0} {
# Use the compiler sysroot, if there is one
define SYSROOT $result
msg-result "Found compiler sysroot $result"
} else {
set msg "pkg-config: Cross compiling, but no compiler sysroot and no --sysroot supplied"
if {$required} {
user-error $msg
} else {
msg-result $msg
}
set found 0
}
}
if {[is-defined SYSROOT]} {
set sysroot [get-define SYSROOT]

# XXX: It's possible that these should be set only when invoking pkg-config
global env
set env(PKG_CONFIG_DIR) ""
# Do we need to try /usr/local as well or instead?
set env(PKG_CONFIG_LIBDIR) $sysroot/usr/lib/pkgconfig:$sysroot/usr/share/pkgconfig
set env(PKG_CONFIG_SYSROOT_DIR) $sysroot
}
}
define HAVE_PKG_CONFIG $found
return $found
}

# @pkg-config module ?requirements?
#
# Use 'pkg-config' to find the given module meeting the given requirements.
# e.g.
#
## pkg-config pango >= 1.37.0
#
# If found, returns 1 and sets 'HAVE_PKG_PANGO' to 1 along with:
#
## PKG_PANGO_VERSION to the found version
## PKG_PANGO_LIBS to the required libs (--libs-only-l)
## PKG_PANGO_LDFLAGS to the required linker flags (--libs-only-L)
## PKG_PANGO_CFLAGS to the required compiler flags (--cflags)
## PKG_PANGO_LIBS_STATIC to the required libs (--libs-only-l -static)
#
# If not found, returns 0.
#
proc pkg-config {module args} {
set ok [pkg-config-init]

msg-checking "Checking for $module $args..."

if {!$ok} {
msg-result "no pkg-config"
return 0
}

if {[catch {exec [get-define PKG_CONFIG] --modversion "$module $args"} version]} {
msg-result "not found"
configlog "pkg-config --modversion $module $args: $version"
return 0
}
msg-result $version
set prefix [feature-define-name $module PKG_]
define HAVE_${prefix}
define ${prefix}_VERSION $version
define ${prefix}_LIBS [exec pkg-config --libs-only-l $module]

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch autosetup
# Your branch is up to date with 'origin/autosetup'.
#
# Changes to be committed:
# modified: auto.def
#
# Untracked files:
# ..travis.yml.un~
# .Makefile.autosetup.un~
# .auto.def.un~
# autosetup/.pkg-config.tcl.un~
# config.h
# docs/.Makefile.autosetup.un~
# docs/.Makefile.un~
# external/libfetch/.Makefile.autosetup.un~
# external/libfetch/Makefile
# libpkg/.Makefile.autosetup.un~
# libpkg/.Makefile.un~
# mk/.common.mk.un~
# mk/.defs.mk.in.un~
# mk/.defs.mk.un~
# mk/.doc.mk.un~
# mk/doc.mk
# plop.tar.xz
# scripts/.Makefile.autosetup.un~
# scripts/.Makefile.un~
# src/.Makefile.autosetup.un~
# src/.Makefile.un~
# tests/.Makefile.autosetup.un~
# tests/Kyuafile
# tests/checksum
# tests/deps_formula
# tests/frontend/Kyuafile
# tests/frontend/add
# tests/frontend/alias
# tests/frontend/annotate
# tests/frontend/autoremove
# tests/frontend/autoupgrade
# tests/frontend/config
# tests/frontend/configmerge
# tests/frontend/conflicts
# tests/frontend/conflicts-multirepo
# tests/frontend/create
# tests/frontend/delete
# tests/frontend/extract
# tests/frontend/fingerprint
define ${prefix}_LDFLAGS [exec pkg-config --libs-only-L $module]
define ${prefix}_CFLAGS [exec pkg-config --cflags $module]
return 1
}

# @pkg-config-get module setting
#
# Convenience access to the results of 'pkg-config'.
#
# For example, '[pkg-config-get pango CFLAGS]' returns
# the value of 'PKG_PANGO_CFLAGS', or '""' if not defined.
proc pkg-config-get {module name} {
set prefix [feature-define-name $module PKG_]
get-define ${prefix}_${name} ""
}

+ 325
- 0
autosetup/system.tcl View File

@@ -0,0 +1,325 @@
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# @synopsis:
#
# This module supports common system interrogation and options
# such as '--host', '--build', '--prefix', and setting 'srcdir', 'builddir', and 'EXEEXT'.
#
# It also support the "feature" naming convention, where searching
# for a feature such as 'sys/type.h' defines 'HAVE_SYS_TYPES_H'.
#
# It defines the following variables, based on '--prefix' unless overridden by the user:
#
## datadir
## sysconfdir
## sharedstatedir
## localstatedir
## infodir
## mandir
## includedir
#
# If '--prefix' is not supplied, it defaults to '/usr/local' unless 'defaultprefix' is defined *before*
# including the 'system' module.

if {[is-defined defaultprefix]} {
user-notice "Note: defaultprefix is deprecated. Use options-defaults to set default options"
options-defaults [list prefix [get-define defaultprefix]]
}

module-options [subst -noc -nob {
host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
the application will run (defaults to the same value as --build)}
build:build-alias => {a complete or partial cpu-vendor-opsys for the system
where the application will be built (defaults to the
result of running config.guess)}
prefix:dir=/usr/local => {the target directory for the build (default: '@default@')}

# These (hidden) options are supported for autoconf/automake compatibility
exec-prefix:
bindir:
sbindir:
includedir:
mandir:
infodir:
libexecdir:
datadir:
libdir:
sysconfdir:
sharedstatedir:
localstatedir:
maintainer-mode=0
dependency-tracking=0
silent-rules=0
}]

# @check-feature name { script }
#
# defines feature '$name' to the return value of '$script',
# which should be 1 if found or 0 if not found.
#
# e.g. the following will define 'HAVE_CONST' to 0 or 1.
#
## check-feature const {
## cctest -code {const int _x = 0;}
## }
proc check-feature {name code} {
msg-checking "Checking for $name..."
set r [uplevel 1 $code]
define-feature $name $r
if {$r} {
msg-result "ok"
} else {
msg-result "not found"
}
return $r
}

# @have-feature name ?default=0?
#
# Returns the value of feature '$name' if defined, or '$default' if not.
#
# See 'feature-define-name' for how the "feature" name
# is translated into the "define" name.
#
proc have-feature {name {default 0}} {
get-define [feature-define-name $name] $default
}

# @define-feature name ?value=1?
#
# Sets the feature 'define' to '$value'.
#
# See 'feature-define-name' for how the "feature" name
# is translated into the "define" name.
#
proc define-feature {name {value 1}} {
define [feature-define-name $name] $value
}

# @feature-checked name
#
# Returns 1 if feature '$name' has been checked, whether true or not.
#
proc feature-checked {name} {
is-defined [feature-define-name $name]
}

# @feature-define-name name ?prefix=HAVE_?
#
# Converts a "feature" name to the corresponding "define",
# e.g. 'sys/stat.h' becomes 'HAVE_SYS_STAT_H'.
#
# Converts '*' to 'P' and all non-alphanumeric to underscore.
#
proc feature-define-name {name {prefix HAVE_}} {
string toupper $prefix[regsub -all {[^a-zA-Z0-9]} [regsub -all {[*]} $name p] _]
}

# @write-if-changed filename contents ?script?
#
# If '$filename' doesn't exist, or it's contents are different to '$contents',
# the file is written and '$script' is evaluated.
#
# Otherwise a "file is unchanged" message is displayed.
proc write-if-changed {file buf {script {}}} {
set old [readfile $file ""]
if {$old eq $buf && [file exists $file]} {
msg-result "$file is unchanged"
} else {
writefile $file $buf\n
uplevel 1 $script
}
}

# @make-template template ?outfile?
#
# Reads the input file '<srcdir>/$template' and writes the output file '$outfile'
# (unless unchanged).
# If '$outfile' is blank/omitted, '$template' should end with '.in' which
# is removed to create the output file name.
#
# Each pattern of the form '@define@' is replaced with the corresponding
# "define", if it exists, or left unchanged if not.
#
# The special value '@srcdir@' is substituted with the relative
# path to the source directory from the directory where the output
# file is created, while the special value '@top_srcdir@' is substituted
# with the relative path to the top level source directory.
#
# Conditional sections may be specified as follows:
## @if name == value
## lines
## @else
## lines
## @endif
#
# Where 'name' is a defined variable name and '@else' is optional.
# If the expression does not match, all lines through '@endif' are ignored.
#
# The alternative forms may also be used:
## @if name
## @if name != value
#
# Where the first form is true if the variable is defined, but not empty nor 0.
#
# Currently these expressions can't be nested.
#
proc make-template {template {out {}}} {
set infile [file join $::autosetup(srcdir) $template]

if {![file exists $infile]} {
user-error "Template $template is missing"
}

# Define this as late as possible
define AUTODEPS $::autosetup(deps)

if {$out eq ""} {
if {[file ext $template] ne ".in"} {
autosetup-error "make_template $template has no target file and can't guess"
}
set out [file rootname $template]
}

set outdir [file dirname $out]

# Make sure the directory exists
file mkdir $outdir

# Set up srcdir and top_srcdir to be relative to the target dir
define srcdir [relative-path [file join $::autosetup(srcdir) $outdir] $outdir]
define top_srcdir [relative-path $::autosetup(srcdir) $outdir]

set mapping {}
foreach {n v} [array get ::define] {
lappend mapping @$n@ $v
}
set result {}
foreach line [split [readfile $infile] \n] {
if {[info exists cond]} {
set l [string trimright $line]
if {$l eq "@endif"} {
unset cond
continue
}
if {$l eq "@else"} {
set cond [expr {!$cond}]
continue
}
if {$cond} {
lappend result $line
}
continue
}
if {[regexp {^@if\s+(\w+)(.*)} $line -> name expression]} {
lassign $expression equal value
set varval [get-define $name ""]
if {$equal eq ""} {
set cond [expr {$varval ni {"" 0}}]
} else {
set cond [expr {$varval eq $value}]
if {$equal ne "=="} {
set cond [expr {!$cond}]
}
}
continue
}
lappend result $line
}
write-if-changed $out [string map $mapping [join $result \n]] {
msg-result "Created [relative-path $out] from [relative-path $template]"
}
}

# build/host tuples and cross-compilation prefix
opt-str build build ""
define build_alias $build
if {$build eq ""} {
define build [config_guess]
} else {
define build [config_sub $build]
}

opt-str host host ""
define host_alias $host
if {$host eq ""} {
define host [get-define build]
set cross ""
} else {
define host [config_sub $host]
set cross $host-
}
define cross [get-env CROSS $cross]

# build/host _cpu, _vendor and _os
foreach type {build host} {
set v [get-define $type]
if {![regexp {^([^-]+)-([^-]+)-(.*)$} $v -> cpu vendor os]} {
user-error "Invalid canonical $type: $v"
}
define ${type}_cpu $cpu
define ${type}_vendor $vendor
define ${type}_os $os
}

opt-str prefix prefix /usr/local

# These are for compatibility with autoconf
define target [get-define host]
define prefix $prefix
define builddir $autosetup(builddir)
define srcdir $autosetup(srcdir)
define top_srcdir $autosetup(srcdir)
define abs_top_srcdir [file-normalize $autosetup(srcdir)]
define abs_top_builddir [file-normalize $autosetup(builddir)]

# autoconf supports all of these
define exec_prefix [opt-str exec-prefix exec_prefix $prefix]
foreach {name defpath} {
bindir /bin
sbindir /sbin
libexecdir /libexec
libdir /lib
} {
define $name [opt-str $name o $exec_prefix$defpath]
}
foreach {name defpath} {
datadir /share
sharedstatedir /com
infodir /share/info
mandir /share/man
includedir /include
} {
define $name [opt-str $name o $prefix$defpath]
}
if {$prefix ne {/usr}} {
opt-str sysconfdir sysconfdir $prefix/etc
} else {
opt-str sysconfdir sysconfdir /etc
}
define sysconfdir $sysconfdir

define localstatedir [opt-str localstatedir o /var]

define SHELL [get-env SHELL [find-an-executable sh bash ksh]]

# These could be used to generate Makefiles following some automake conventions
define AM_SILENT_RULES [opt-bool silent-rules]
define AM_MAINTAINER_MODE [opt-bool maintainer-mode]
define AM_DEPENDENCY_TRACKING [opt-bool dependency-tracking]

# Windows vs. non-Windows
switch -glob -- [get-define host] {
*-*-ming* - *-*-cygwin - *-*-msys {
define-feature windows
define EXEEXT .exe
}
default {
define EXEEXT ""
}
}

# Display
msg-result "Host System...[get-define host]"
msg-result "Build System...[get-define build]"

+ 55
- 0
autosetup/tmake.auto View File

@@ -0,0 +1,55 @@
# Copyright (c) 2016 WorkWare Systems http://www.workware.net.au/
# All rights reserved

# Auto-load module for 'tmake' build system integration

use init

autosetup_add_init_type tmake "Tcl-based tmake build system" {
autosetup_check_create auto.def \
{# Initial auto.def created by 'autosetup --init=tmake'
# vim:set syntax=tcl:

use cc cc-lib cc-db cc-shared
use tmake

# Add any user options here
# Really want a --configure that takes over the rest of the command line
options {
}

cc-check-tools ar ranlib

set objdir [get-env BUILDDIR objdir]