Add Swift 3/4 'servaldswift' executable

If the Swift 3 or Swift 4 compiler is present or passed to the configure
script in the SWIFTC variable, then the Makefile will compile a Swift
'servaldswift' executable to ensure that the module map links correctly
into a stand-alone Swift program.

Use the gold linker if supported, to avoid relocation errors on symbols
produced by Swift when linking dynamic libraries.
This commit is contained in:
Andrew Bettison 2016-10-20 16:52:53 +10:30
parent e9d91d04ca
commit f2eb2bf9ab
16 changed files with 648 additions and 64 deletions

1
.gitignore vendored
View File

@ -21,6 +21,7 @@
/config.h /config.h
/servald /servald
/servaldwrap /servaldwrap
/servaldswift
/serval-tests /serval-tests
/directory_service /directory_service
/tfw_createfile /tfw_createfile

View File

@ -1,6 +1,6 @@
Serval DNA Build and Test Serval DNA Build and Test
========================= =========================
[Serval Project][], September 2017 [Serval Project][], December 2017
Supported Architectures Supported Architectures
----------------------- -----------------------
@ -54,6 +54,7 @@ Mandatory dependencies:
Optional: Optional:
* Java compiler and SDK 1.6.0 or later * Java compiler and SDK 1.6.0 or later
* [Swift][] 3 or 4 compiler
* ALSA sound library and headers (present on Linux, not on Android) * ALSA sound library and headers (present on Linux, not on Android)
Test dependencies: Test dependencies:
@ -68,11 +69,15 @@ Test dependencies:
OS-X using the [homebrew][] package manager. The [Notes for Developers][] give OS-X using the [homebrew][] package manager. The [Notes for Developers][] give
more details. more details.
Build Native Build
----- ------------
To compile a native (ie, not cross-compiled) Serval DNA from source, run the A *native build* of Serval DNA will produce libraries and executable programs
following commands: that can be run on the same platform on which the build is performed. This is
useful for development and testing.
The following commands will compile a native (ie, not cross-compiled) Serval
DNA from source:
$ cd $HOME/src/serval-dna $ cd $HOME/src/serval-dna
$ autoreconf -f -i -I m4 $ autoreconf -f -i -I m4
@ -125,9 +130,20 @@ A successful session should appear something like:
LIB CC cli.c LIB CC cli.c
LIB CC cli_stdio.c LIB CC cli_stdio.c
... ...
LINK simulator LINK servald
CC directory_service.c
LINK directory_service
SERVALD CC servalwrap.c
LINK servaldwrap
SERVALD CC test_features.c SERVALD CC test_features.c
LINK serval-tests LINK serval-tests
CC fakeradio.c
LINK fakeradio
CC simulator.c
LINK simulator
CC tfw_createfile.c
LINK tfw_createfile
SWIFT servaldswift
make[1]: Entering directory '/home/username/src/serval-dna/java-api' make[1]: Entering directory '/home/username/src/serval-dna/java-api'
JAVAC classes JAVAC classes
JAVAC testclasses JAVAC testclasses
@ -152,16 +168,27 @@ In the event of a build failure:
* consult the [Notes for Developers][] * consult the [Notes for Developers][]
* as a last resort, [contact the Serval Project][] * as a last resort, [contact the Serval Project][]
Android build
-------------
The [batphone][] app for Android builds Serval DNA from source by including
[Android.mk](./Android.mk) in its own build process; see the [batphone build
instructions][] for more information.
It is not necessary to perform a [native build](#native-build) before or after
an Android build; the two produce completely unrelated artifacts.
Built artifacts Built artifacts
--------------- ---------------
The build process produces the following artifacts: The [native build](#native-build) process produces the following artifacts:
* **servald** is the main Serval DNA daemon executable. All the Serval DNA * **servald** is the main Serval DNA daemon executable. All the Serval DNA
daemon, SQLite and libsodium code is statically linked into this executable, daemon, SQLite and libsodium code is statically linked into this executable,
so it does not need to load any Serval or libsodium shared libraries at and only common system libraries are dynamically linked, which keeps its
run-time. Its unstripped size is about 9.5 MB on a typical 64-bit system, of run-time dependencies to a minimum. Its unstripped size is about 9.5 MB on a
which about 7 MB is SQLite. Its stripped size is about 3 MB. typical 64-bit system, of which about 7 MB is SQLite. Its stripped size is
about 3 MB.
* **servaldwrap** is a Serval DNA executable identical to *servald*, but * **servaldwrap** is a Serval DNA executable identical to *servald*, but
it loads `libservaldaemon.so` at run-time using [dlopen(3)][] instead of it loads `libservaldaemon.so` at run-time using [dlopen(3)][] instead of
@ -182,8 +209,9 @@ The build process produces the following artifacts:
* **libservaldaemon.so** is a dynamic library containing the complete executable * **libservaldaemon.so** is a dynamic library containing the complete executable
code of the Serval DNA daemon, including [JNI][] entry points, SQLite and code of the Serval DNA daemon, including [JNI][] entry points, SQLite and
libsodium cryptographic functions. The Serval DNA Java API, which is used by libsodium cryptographic functions. The *servaldwrap* executable and the
[batphone][], and the *servaldwrap* executable both use this dynamic library. Serval DNA Java API, which is used by [batphone][], both use this dynamic
library.
* **directory_service** is the executable for the [Serval Infrastructure][] * **directory_service** is the executable for the [Serval Infrastructure][]
daemon. daemon.
@ -213,6 +241,16 @@ The build process produces the following artifacts:
* **tfw_createfile** is an executable utility needed by test scripts for * **tfw_createfile** is an executable utility needed by test scripts for
creating large data files with unique, non-repeating content. creating large data files with unique, non-repeating content.
In addition, the following artifacts are produced [if a Swift compiler is
present][Swift development]:
* **servaldswift** is a statically linked Serval DNA executable identical to
*servald*, but its *main* entry point is compiled from a [Swift][] program to
prove that Swift code can invoke internal Serval DNA daemon APIs. It
dynamically links to many more system libraries than *servald* because of the
Swift language's run-time support and resultant library dependencies, so is
not suitable for deployment.
Test scripts Test scripts
------------ ------------
@ -270,6 +308,7 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[Serval DNA]: ./README.md [Serval DNA]: ./README.md
[serval-dna]: https://github.com/servalproject/serval-dna [serval-dna]: https://github.com/servalproject/serval-dna
[batphone]: https://github.com/servalproject/batphone [batphone]: https://github.com/servalproject/batphone
[batphone build instructions]: https://github.com/servalproject/batphone/blob/development/INSTALL.md
[Android 2.2 “Froyo”]: http://developer.android.com/about/versions/android-2.2-highlights.html [Android 2.2 “Froyo”]: http://developer.android.com/about/versions/android-2.2-highlights.html
[Android NDK]: http://developer.android.com/tools/sdk/ndk/index.html [Android NDK]: http://developer.android.com/tools/sdk/ndk/index.html
[Xcode]: https://developer.apple.com/xcode/ [Xcode]: https://developer.apple.com/xcode/
@ -277,6 +316,7 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[gcc 5]: http://gcc.gnu.org/gcc-5/ [gcc 5]: http://gcc.gnu.org/gcc-5/
[gcc 6]: http://gcc.gnu.org/gcc-6/ [gcc 6]: http://gcc.gnu.org/gcc-6/
[Notes for Developers]: ./doc/Development.md [Notes for Developers]: ./doc/Development.md
[Swift development]: ./doc/Development.md#swift
[OpenWRT]: ./doc/OpenWRT.md [OpenWRT]: ./doc/OpenWRT.md
[Serval Infrastructure]: ./doc/Serval-Infrastructure.md [Serval Infrastructure]: ./doc/Serval-Infrastructure.md
[Serval Mesh Extender]: http://developer.servalproject.org/dokuwiki/doku.php?id=content:meshextender: [Serval Mesh Extender]: http://developer.servalproject.org/dokuwiki/doku.php?id=content:meshextender:
@ -288,6 +328,7 @@ This document is available under the [Creative Commons Attribution 4.0 Internati
[MDP API]: ./doc/Mesh-Datagram-Protocol.md#mdp-api [MDP API]: ./doc/Mesh-Datagram-Protocol.md#mdp-api
[CLI API]: ./doc/CLI-API.md [CLI API]: ./doc/CLI-API.md
[JNI]: http://en.wikipedia.org/wiki/Java_Native_Interface [JNI]: http://en.wikipedia.org/wiki/Java_Native_Interface
[Swift]: https://en.wikipedia.org/wiki/Swift_(programming_language)
[Bash]: http://en.wikipedia.org/wiki/Bash_(Unix_shell) [Bash]: http://en.wikipedia.org/wiki/Bash_(Unix_shell)
[GNU make]: http://www.gnu.org/software/make/ [GNU make]: http://www.gnu.org/software/make/
[Git]: http://git-scm.com/ [Git]: http://git-scm.com/

View File

@ -8,6 +8,20 @@ sysconfdir=@sysconfdir@
localstatedir=@localstatedir@ localstatedir=@localstatedir@
srcdir=@srcdir@ srcdir=@srcdir@
CC = @CC@
AR = @AR@
RANLIB = @RANLIB@
JAVAC= @JAVAC@
SWIFTC= @SWIFTC@
SWIFTCFLAGS= @SWIFTCFLAGS@ -I. -I $(srcdir)
SWIFTLIBS= @LIBS@
SWIFT_MODULE_NAME= ServalDNA
INSTALL= install
INSTALL_PROGRAM= $(INSTALL)
INSTALL_DATA= $(INSTALL) -m 644
SQLITE3_AMALGAMATION = sqlite-amalgamation-3140200 SQLITE3_AMALGAMATION = sqlite-amalgamation-3140200
include $(srcdir)/sourcefiles.mk include $(srcdir)/sourcefiles.mk
@ -62,8 +76,6 @@ SIMULATOR_OBJS = \
PREFIXED_HEADERS = $(addprefix $(srcdir)/, $(HDRS)) PREFIXED_HEADERS = $(addprefix $(srcdir)/, $(HDRS))
PREFIXED_SOURCES = $(addprefix $(srcdir)/, $(ALL_SOURCES)) PREFIXED_SOURCES = $(addprefix $(srcdir)/, $(ALL_SOURCES))
CC= @CC@
LDFLAGS=@LDFLAGS@ @LIBS@ LDFLAGS=@LDFLAGS@ @LIBS@
CFLAGS= -I. -I$(srcdir)/$(SQLITE3_AMALGAMATION) @CPPFLAGS@ @CFLAGS@ CFLAGS= -I. -I$(srcdir)/$(SQLITE3_AMALGAMATION) @CPPFLAGS@ @CFLAGS@
@ -83,35 +95,38 @@ CFLAGS+=-DSHA2_USE_INTTYPES_H -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_
CFLAGS+=-D_DARWIN_C_SOURCE CFLAGS+=-D_DARWIN_C_SOURCE
CFLAGS_SQLITE= @CFLAGS_SQLITE@ CFLAGS_SQLITE= @CFLAGS_SQLITE@
JAVAC= @JAVAC@
INSTALL= install
INSTALL_PROGRAM=$(INSTALL)
INSTALL_DATA= $(INSTALL) -m 644
-include $(srcdir)/Makefile.dbg -include $(srcdir)/Makefile.dbg
DEFS= @DEFS@ # More warnings, discover problems that only happen on some archs
CFLAGS+=-Wextra
# Security enhancements from Debian
CFLAGS+=-Wformat -Werror=format-security -D_FORTIFY_SOURCE=2
CONFIG_H = @CONFIG_H@ CONFIG_H = @CONFIG_H@
DEFS= @DEFS@
SWIFTDEFS= $(addprefix -Xcc , $(DEFS))
# Usage: $(call MERGE_STATIC_LIBS, libdest.a, libsrcfoo.a libsrcbar.a) # Usage: $(call MERGE_STATIC_LIBS, libdest.a, libsrcfoo.a libsrcbar.a)
MERGE_STATIC_LIBS = echo MERGE $(1) = $(2); \ MERGE_STATIC_LIBS = echo MERGE $(1) = $(2); \
tmp="$$(mktemp -d)" && \ tmp="$$(mktemp -d)" && \
( cd "$$tmp" $(foreach LIB, $(2), && $(AR) -x $(abspath $(LIB))) ) && \ ( cd "$$tmp" $(foreach LIB, $(2), && $(AR) -x $(abspath $(LIB))) ) && \
$(RM) $@ && \ $(RM) $(1) && \
$(AR) -cr $(1) "$$tmp"/* && \ $(AR) -cr $(1) "$$tmp"/*.o && \
$(RANLIB) $(1) && \
$(RM) -r "$$tmp" $(RM) -r "$$tmp"
.PHONY: all libs test install uninstall clean .PHONY: all libs test install uninstall clean
all: libs servald servaldwrap test all: libs servald directory_service test
libs: libservaldaemon.so \ libs: libservaldaemon.so libservaldaemon.a \
libservalclient.so libservalclient.a \ libservalclient.so libservalclient.a \
libmonitorclient.so libmonitorclient.a libmonitorclient.so libmonitorclient.a
test: tfw_createfile directory_service fakeradio simulator serval-tests test: servaldwrap serval-tests \
fakeradio simulator \
tfw_createfile
install: servald install: servald
$(INSTALL_PROGRAM) -D servald $(DESTDIR)$(sbindir)/servald $(INSTALL_PROGRAM) -D servald $(DESTDIR)$(sbindir)/servald
@ -321,6 +336,26 @@ servald: $(OBJSDIR_SERVALD)/servald_features.o \
@echo LINK $@ @echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS) @$(CC) -Wall -o $@ $^ $(LDFLAGS)
ifneq ($(SWIFTC),) # Only provide Swift targets if the Swift compiler is available.
test: servaldswift
# A servald equivalent whose main entry point and logging output is implemented
# in the Swift language, rather than the C entry point in main.c. This exists
# mainly to ensure that the Serval daemon library can be linked into a Swift
# program and executed. This linkage support is needed by the iOS framework
# package.
servaldswift: $(srcdir)/servaldswift.swift \
$(OBJSDIR_SERVALD)/servald_features.o \
$(OBJSDIR_SERVALD)/log_output_console.o \
$(OBJSDIR_SERVALD)/log_output_file.o \
libservaldaemon.a \
$(srcdir)/module.modulemap
@echo SWIFT $@
@$(SWIFTC) -emit-executable $(SWIFTCFLAGS) $(SWIFTDEFS) -o $@ $(filter %.swift, $^) $(filter %.o, $^) $(filter %.a, $^) $(SWIFTLIBS)
endif # $(SWIFTC)
servaldwrap: $(OBJSDIR_SERVALD)/servalwrap.o servaldwrap: $(OBJSDIR_SERVALD)/servalwrap.o
@echo LINK $@ @echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS) @$(CC) -Wall -o $@ $^ $(LDFLAGS)

View File

@ -4,26 +4,13 @@ AC_INIT(servald, 0.9)
AC_CONFIG_SRCDIR([serval_types.h]) AC_CONFIG_SRCDIR([serval_types.h])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AC_ARG_VAR([AR], [Library archiver])
AC_ARG_VAR([RANLIB], [Archive indexer])
AC_ARG_VAR([SWIFTC], [Swift compiler])
AC_ARG_VAR([SWIFTCFLAGS], [Swift compiler flags])
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
dnl Set $host_os, which is needed by javac detection.
AC_CANONICAL_SYSTEM
dnl Various GCC function and variable attributes
AX_GCC_FUNC_ATTRIBUTE(aligned)
AX_GCC_FUNC_ATTRIBUTE(alloc_size)
AX_GCC_FUNC_ATTRIBUTE(error)
AX_GCC_FUNC_ATTRIBUTE(format)
AX_GCC_FUNC_ATTRIBUTE(malloc)
AX_GCC_FUNC_ATTRIBUTE(unused)
AX_GCC_FUNC_ATTRIBUTE(used)
AX_GCC_VAR_ATTRIBUTE(section)
AX_GCC_VAR_ATTRIBUTE(section_seg)
AX_GCC_STMT_ATTRIBUTE(fallthrough)
dnl Init pkg-config
PKG_PROG_PKG_CONFIG()
dnl Specify default instance path dnl Specify default instance path
AC_ARG_VAR([INSTANCE_PATH], [default instance path for servald]) AC_ARG_VAR([INSTANCE_PATH], [default instance path for servald])
AS_IF([test "x$INSTANCE_PATH" != x], [AC_DEFINE_UNQUOTED([INSTANCE_PATH], ["$INSTANCE_PATH"], [default instance path])]) AS_IF([test "x$INSTANCE_PATH" != x], [AC_DEFINE_UNQUOTED([INSTANCE_PATH], ["$INSTANCE_PATH"], [default instance path])])
@ -52,10 +39,58 @@ dnl Specify default Rhizome store directory
AC_ARG_VAR([RHIZOME_STORE_PATH], [default Rhizome store directory]) AC_ARG_VAR([RHIZOME_STORE_PATH], [default Rhizome store directory])
AS_IF([test "x$RHIZOME_STORE_PATH" != x], [AC_DEFINE_UNQUOTED([RHIZOME_STORE_PATH], ["$RHIZOME_STORE_PATH"], [default Rhizome store directory])]) AS_IF([test "x$RHIZOME_STORE_PATH" != x], [AC_DEFINE_UNQUOTED([RHIZOME_STORE_PATH], ["$RHIZOME_STORE_PATH"], [default Rhizome store directory])])
dnl Check for programs. dnl Set $host_os, which is needed by javac detection.
AC_PROG_CC AC_CANONICAL_SYSTEM
dnl Check for compiler options dnl Check for C99 compiler and other tools.
AC_PROG_CC_C99
AC_PROG_CPP
AC_CHECK_TOOL([AR], [ar], [:])
AS_IF([test "x$AR" = x:], [AC_MSG_ERROR([Library archiver not found: ar])])
AC_CHECK_TOOL([RANLIB], [ranlib], [:])
AS_IF([test "x$RANLIB" = x:], [AC_MSG_ERROR([Archive indexer not found: ranlib])])
dnl Check for a Swift 3 or 4 compiler; set SWIFTC if found.
AC_PROG_SWIFTC
AS_IF([test "x$SWIFTC" != x], [ dnl
dnl Check whether the Swift compiler will compile a simple Swift 4 program with the supplied flags.
dnl If not, report failure but keep going.
AC_PROG_SWIFTC_IS_SWIFT4
AS_IF([test "x$ac_cv_prog_swiftc_is_swift4" = xyes], [SWIFT_VERSION=4], [ dnl
AC_PROG_SWIFTC_IS_SWIFT3
AS_IF([test "x$ac_cv_prog_swiftc_is_swift3" = xyes], [SWIFT_VERSION=3], [ dnl
AC_MSG_WARN([$SWIFTC version is too old; omitting Swift API])
SWIFT_VERSION=
SWIFTC=
])
])
])
AC_SUBST([SWIFTC])
AC_SUBST([SWIFTCFLAGS])
AC_SUBST([SWIFT_VERSION])
dnl Various GCC function and variable attributes
AX_GCC_FUNC_ATTRIBUTE(aligned)
AX_GCC_FUNC_ATTRIBUTE(alloc_size)
AX_GCC_FUNC_ATTRIBUTE(error)
AX_GCC_FUNC_ATTRIBUTE(format)
AX_GCC_FUNC_ATTRIBUTE(malloc)
AX_GCC_FUNC_ATTRIBUTE(unused)
AX_GCC_FUNC_ATTRIBUTE(used)
AX_GCC_VAR_ATTRIBUTE(section)
AX_GCC_VAR_ATTRIBUTE(section_seg)
AX_GCC_STMT_ATTRIBUTE(fallthrough)
dnl The default GNU linker (BFD) cannot relocate some symbols produced by the
dnl Swift compiler, so the gold linker is used to create dynamic libraries.
dnl See doc/Development.md for details.
AX_APPEND_LINK_FLAGS(-fuse-ld=gold)
dnl Check compiler options for compiling SQLite.
AX_APPEND_COMPILE_FLAGS( AX_APPEND_COMPILE_FLAGS(
-Wno-empty-body \ -Wno-empty-body \
-Wno-unused-value \ -Wno-unused-value \
@ -81,7 +116,7 @@ popdef([AC_MSG_ERROR])
AC_SUBST([JAVAC]) AC_SUBST([JAVAC])
dnl Check Java version, ditch Java if not adequate dnl Check Java version, ditch Java if not adequate
if test -n "$JAVAC"; then AS_IF([test -n "$JAVAC"], [ dnl
dnl Discover the version of the Java compiler dnl Discover the version of the Java compiler
AC_PROG_JAVAC_VERSION AC_PROG_JAVAC_VERSION
dnl Check that the Java compiler is modern enough dnl Check that the Java compiler is modern enough
@ -94,9 +129,9 @@ if test -n "$JAVAC"; then
AC_MSG_WARN([Java version $ax_cv_prog_javac_version is too old; omitting Java API]) AC_MSG_WARN([Java version $ax_cv_prog_javac_version is too old; omitting Java API])
JAVAC="" JAVAC=""
]) ])
fi ])
if test -n "$JAVAC"; then AS_IF([test -n "$JAVAC"], [ dnl
dnl Discover the locations of JNI header files dnl Discover the locations of JNI header files
dnl *** Kludge: override AC_MSG_ERROR because AC_JNI_INCLUDE_DIR does not have dnl *** Kludge: override AC_MSG_ERROR because AC_JNI_INCLUDE_DIR does not have
dnl *** [if-found] and [if-not-found] action parameters. dnl *** [if-found] and [if-not-found] action parameters.
@ -106,7 +141,7 @@ if test -n "$JAVAC"; then
CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR" CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR"
done done
popdef([AC_MSG_ERROR]) popdef([AC_MSG_ERROR])
fi ])
dnl XXX Isn't this pointless? we are always linked against libc dnl XXX Isn't this pointless? we are always linked against libc
AC_CHECK_LIB(c,srandomdev) AC_CHECK_LIB(c,srandomdev)

View File

@ -1,6 +1,6 @@
Notes for Serval DNA Developers Notes for Serval DNA Developers
=============================== ===============================
[Serval Project][], September 2017 [Serval Project][], December 2017
Introduction Introduction
------------ ------------
@ -11,12 +11,12 @@ non-developers who are experiencing errors in the [build][] process.
Autotools Autotools
--------- ---------
The [configure.ac](../configure.ac) file is an [autoconf][] script that The [configure.ac][] file is an [autoconf][] script that contains instructions
contains instructions for adapting the build of Serval DNA to different for adapting the build of Serval DNA to different platforms and CPU
platforms and CPU architectures. This script makes use of many [GNU M4][] architectures. This script makes use of many [GNU M4][] macros, each of which
macros, each of which tests an aspect of the build environment, such as the tests an aspect of the build environment, such as the make and version of the C
make and version of the C compiler (eg, [GCC][], [Clang][]), the availability compiler (eg, [GCC][], [Clang][]), the availability of headers, functions and
of headers, functions and system calls in the standard library, and so forth. system calls in the standard library, and so forth.
Most of these M4 macros are standard, either supplied with [autoconf][] or from Most of these M4 macros are standard, either supplied with [autoconf][] or from
the [autoconf macro archive][]. Some macros are specific to Serval DNA, either the [autoconf macro archive][]. Some macros are specific to Serval DNA, either
@ -27,8 +27,7 @@ sub-directory.
The [autoreconf][] command used in the [build][] instructions generates an The [autoreconf][] command used in the [build][] instructions generates an
`aclocal.m4` file that includes all the necessary files from the [m4](../m4) `aclocal.m4` file that includes all the necessary files from the [m4](../m4)
directory. In turn, it then includes this `aclocal.m4` file when invoking [GNU directory. In turn, it then includes this `aclocal.m4` file when invoking [GNU
M4][] to convert the [configure.ac](../configure.ac) file into the M4][] to convert the [configure.ac][] file into the `./configure` script.
`./configure` script.
When invoked without arguments, all [autoreconf][] versions up to 2.69 will When invoked without arguments, all [autoreconf][] versions up to 2.69 will
emit warning messages like this: emit warning messages like this:
@ -63,7 +62,18 @@ the `-I m4` option, which will eliminate the warnings:
The `-I m4` option should be unnecessary in [autoreconf][] versions 2.70 and The `-I m4` option should be unnecessary in [autoreconf][] versions 2.70 and
later, because they will deduce it from the `AC_CONFIG_MACRO_DIR([m4])` later, because they will deduce it from the `AC_CONFIG_MACRO_DIR([m4])`
directive near the top of `configure.ac`. directive near the top of [configure.ac][].
Linker
------
The default GNU linker (based on the BFD library) does not support relocation
of some symbols produced by the Swift compiler:
relocation R_X86_64_PC32 against protected symbol `...' can not be used when making a shared object
The Serval DNA dynamic library is linked using the GNU [gold][] linker
(available in GNU binutils since 2008), which does not have this problem.
libsodium libsodium
--------- ---------
@ -217,6 +227,34 @@ using the [homebrew][] package manager:
/usr/local/Cellar/jq/1.5_2: 18 files, 958K /usr/local/Cellar/jq/1.5_2: 18 files, 958K
$ $
Java
----
The Serval DNA *libservaldeamon* static and dynamic libraries provide a [JNI][]
API so that the Serval [command line][CLI] can be called from Java programs,
and the daemon server can be run in a Java thread.
Swift
-----
Serval DNA supports [Swift][], the language that Apple recommend for developing
iOS apps for their mobile devices such as phones and tablets. The
`./configure` script [generated from configure.ac](#autotools) detects whether
a [Swift 4][] compiler is present, or failing that, a [Swift 3][] compiler, and
if so, then produces a Makefile that will compile
[servaldswift.swift](../servaldswift.swift) into the *servaldswift* executable,
to prove that the Swift [module map](../module.modulemap) allows Swift source
code to invoke internal Serval DNA functions.
The `./configure` script can be passed the following variables, either as
environment variables or using the `VARNAME=value` syntax on its command line:
* `SWIFTC` the path name of the Swift compiler to use; by default the configure
script searches `$PATH` for `swiftc`
* `SWIFTCFLAGS` extra command-line arguments to pass to the Swift compiler;
analogous to `CFLAGS` for the C compiler
About the examples About the examples
------------------ ------------------
@ -241,6 +279,7 @@ Available under the [Creative Commons Attribution 4.0 International licence][CC
[CC BY 4.0]: ../LICENSE-DOCUMENTATION.md [CC BY 4.0]: ../LICENSE-DOCUMENTATION.md
[Serval DNA]: ../README.md [Serval DNA]: ../README.md
[build]: ../INSTALL.md [build]: ../INSTALL.md
[configure.ac]: ../configure.ac
[autoconf]: http://www.gnu.org/software/autoconf/autoconf.html [autoconf]: http://www.gnu.org/software/autoconf/autoconf.html
[autoconf macro archive]: http://www.gnu.org/software/autoconf-archive/ [autoconf macro archive]: http://www.gnu.org/software/autoconf-archive/
[GNU M4]: http://www.gnu.org/software/m4/m4.html [GNU M4]: http://www.gnu.org/software/m4/m4.html
@ -262,4 +301,11 @@ Available under the [Creative Commons Attribution 4.0 International licence][CC
[OS X awk(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/awk.1.html [OS X awk(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/awk.1.html
[jq(1)]: https://stedolan.github.io/jq/ [jq(1)]: https://stedolan.github.io/jq/
[homebrew]: http://brew.sh/ [homebrew]: http://brew.sh/
[CLI]: ./CLI-API.md
[JNI]: http://en.wikipedia.org/wiki/Java_Native_Interface
[Swift]: https://en.wikipedia.org/wiki/Swift_(programming_language)
[Swift module]: https://swift.org/package-manager/#modules
[Swift 3]: https://swift.org/blog/swift-3-0-released/
[Swift 4]: https://swift.org/blog/swift-4-0-released/
[gold]: https://en.wikipedia.org/wiki/Gold_(linker)
[Bourne shell]: http://en.wikipedia.org/wiki/Bourne_shell [Bourne shell]: http://en.wikipedia.org/wiki/Bourne_shell

View File

@ -0,0 +1,61 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_append_link_flags.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_APPEND_LINK_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS])
#
# DESCRIPTION
#
# For every FLAG1, FLAG2 it is checked whether the linker works with the
# flag. If it does, the flag is added FLAGS-VARIABLE
#
# If FLAGS-VARIABLE is not specified, the linker's flags (LDFLAGS) is
# used. During the check the flag is always added to the linker's flags.
#
# If EXTRA-FLAGS is defined, it is added to the linker's default flags
# when the check is done. The check is thus made with the flags: "LDFLAGS
# EXTRA-FLAGS FLAG". This can for example be used to force the linker to
# issue an error when a bad flag is given.
#
# NOTE: This macro depends on the AX_APPEND_FLAG and AX_CHECK_LINK_FLAG.
# Please keep this macro in sync with AX_APPEND_COMPILE_FLAGS.
#
# LICENSE
#
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 2
AC_DEFUN([AX_APPEND_LINK_FLAGS],
[for flag in $1; do
AX_CHECK_LINK_FLAG([$flag], [AX_APPEND_FLAG([$flag], [m4_default([$2], [LDFLAGS])])], [], [$3])
done
])dnl AX_APPEND_LINK_FLAGS

71
m4/ax_check_link_flag.m4 Normal file
View File

@ -0,0 +1,71 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS])
#
# DESCRIPTION
#
# Check whether the given FLAG works with the linker or gives an error.
# (Warnings, however, are ignored)
#
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
# success/failure.
#
# If EXTRA-FLAGS is defined, it is added to the linker's default flags
# when the check is done. The check is thus made with the flags: "LDFLAGS
# EXTRA-FLAGS FLAG". This can for example be used to force the linker to
# issue an error when a bad flag is given.
#
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG.
#
# LICENSE
#
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
#serial 2
AC_DEFUN([AX_CHECK_LINK_FLAG],
[AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl
AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [
ax_check_save_flags=$LDFLAGS
LDFLAGS="$LDFLAGS $4 $1"
AC_LINK_IFELSE([AC_LANG_PROGRAM()],
[AS_VAR_SET(CACHEVAR,[yes])],
[AS_VAR_SET(CACHEVAR,[no])])
LDFLAGS=$ax_check_save_flags])
AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
[m4_default([$2], :)],
[m4_default([$3], :)])
AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CHECK_LINK_FLAGS

56
m4/ax_prog_swiftc.m4 Normal file
View File

@ -0,0 +1,56 @@
# Serval Project Swift language support
#
# SYNOPSIS
#
# AX_PROG_SWIFTC
#
# DESCRIPTION
#
# AX_PROG_SWIFTC tests for the presence of a Swift compiler.
#
# Sets the SWIFTC shell variable to the name of the Swift executable (not the
# Swift compiler!) either relative to $PATH or an absolute path if necessary;
# this is usually just "swiftc".
#
# To force a specific compiler, either:
#
# - in configure.ac, set SWIFTC=yourcompiler before calling AX_PROG_SWIFTC,
# or
#
# - before invoking ./configure, export SWIFTC=yourcompiler
#
# LICENSE
#
# Copyright (C) 2016 Flinders University
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
AU_ALIAS([AC_PROG_SWIFTC], [AX_PROG_SWIFTC])
AC_DEFUN([AX_PROG_SWIFTC],[
test "x$SWIFTC" = x && AC_CHECK_PROGS(SWIFTC, swiftc)
AC_PROVIDE([$0])dnl
])

View File

@ -0,0 +1,74 @@
# Serval Project Swift language support
#
# SYNOPSIS
#
# AX_PROG_SWIFTC_IS_SWIFT3
#
# DESCRIPTION
#
# AX_PROG_SWIFTC_IS_SWIFT3 tests whether the Swift compiler in the SWIFTC
# variable (eg, as detected by the AX_PROG_SWIFTC macro) can compile a Swift
# 3 program to a working native executable, with the given SWIFTCFLAGS
# compiler options.
#
# LICENSE
#
# Copyright (C) 2016 Flinders University
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
AU_ALIAS([AC_PROG_SWIFTC_IS_SWIFT3], [AX_PROG_SWIFTC_IS_SWIFT3])
AC_DEFUN([AX_PROG_SWIFTC_IS_SWIFT3],[
AC_REQUIRE([AX_TMPDIR_SWIFT])
AC_CACHE_CHECK([if $SWIFTC supports Swift 3], ac_cv_prog_swiftc_is_swift3, [
cat <<EOF > "$ax_tmpdir_swift/Test.swift"
/* Swift 2 uses Process.arguments, so this only compiles in Swift 3 */
print(CommandLine.arguments)
EOF
if AC_TRY_COMMAND($SWIFTC $SWIFTCFLAGS -emit-executable -o "$ax_tmpdir_swift/Test" "$ax_tmpdir_swift/Test.swift") >/dev/null 2>&1; then
if AC_TRY_COMMAND("$ax_tmpdir_swift/Test" one two three) > "$ax_tmpdir_swift/Test.out" 2>&1; then
ac_swift_test_out=`cat "$ax_tmpdir_swift/Test.out"`
if test "x$ac_swift_test_out" = ['x["'"$ax_tmpdir_swift"'/Test", "one", "two", "three"]']; then
ac_cv_prog_swiftc_is_swift3=yes
else
echo "incorrect output was: $ac_swift_test_out" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift3=no
fi
else
echo "failed "$ax_tmpdir_swift/Test" execution produced output:" >&AS_MESSAGE_LOG_FD
cat "$ax_tmpdir_swift/Test.out" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift3=no
fi
else
echo "compilation failed for:" >&AS_MESSAGE_LOG_FD
cat "$ax_tmpdir_swift/Test.swift" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift3=no
fi
rm -f Test.swift Test Test.out
])
AC_PROVIDE([$0])dnl
])

View File

@ -0,0 +1,80 @@
# Serval Project Swift language support
#
# SYNOPSIS
#
# AX_PROG_SWIFTC_IS_SWIFT4
#
# DESCRIPTION
#
# AX_PROG_SWIFTC_IS_SWIFT4 tests whether the Swift compiler in the SWIFTC
# variable (eg, as detected by the AX_PROG_SWIFTC macro) can compile a Swift
# 4 program to a working native executable, with the given SWIFTCFLAGS
# compiler options.
#
# LICENSE
#
# Copyright (C) 2017 Flinders University
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
# scripts that are the output of Autoconf when processing the Macro. You
# need not follow the terms of the GNU General Public License when using
# or distributing such scripts, even though portions of the text of the
# Macro appear in them. The GNU General Public License (GPL) does govern
# all other use of the material that constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the Autoconf
# Macro released by the Autoconf Archive. When you make and distribute a
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.
AU_ALIAS([AC_PROG_SWIFTC_IS_SWIFT4], [AX_PROG_SWIFTC_IS_SWIFT4])
AC_DEFUN([AX_PROG_SWIFTC_IS_SWIFT4],[
AC_REQUIRE([AX_TMPDIR_SWIFT])
AC_CACHE_CHECK([if $SWIFTC supports Swift 4], ac_cv_prog_swiftc_is_swift4, [
[
cat <<EOF > "$ax_tmpdir_swift/Test.swift"
/* Substring was introduced in Swift 4 */
let a = "test"
let b : Substring = a[a.startIndex ... a.index(a.startIndex, offsetBy: 2)]
precondition(b == "tes")
/* Swift 2 uses Process.arguments, so this only compiles in Swift 3 and later */
print(CommandLine.arguments)
EOF
]
if AC_TRY_COMMAND($SWIFTC $SWIFTCFLAGS -emit-executable -o "$ax_tmpdir_swift/Test" "$ax_tmpdir_swift/Test.swift") >/dev/null 2>&1; then
if AC_TRY_COMMAND("$ax_tmpdir_swift/Test" one two three) > "$ax_tmpdir_swift/Test.out" 2>&1; then
ac_swift_test_out=`cat "$ax_tmpdir_swift/Test.out"`
if test "x$ac_swift_test_out" = ['x["'"$ax_tmpdir_swift"'/Test", "one", "two", "three"]']; then
ac_cv_prog_swiftc_is_swift4=yes
else
echo "incorrect output was: $ac_swift_test_out" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift4=no
fi
else
echo "failed "$ax_tmpdir_swift/Test" execution produced output:" >&AS_MESSAGE_LOG_FD
cat "$ax_tmpdir_swift/Test.out" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift4=no
fi
else
echo "compilation failed for:" >&AS_MESSAGE_LOG_FD
cat "$ax_tmpdir_swift/Test.swift" >&AS_MESSAGE_LOG_FD
ac_cv_prog_swiftc_is_swift4=no
fi
rm -f Test.swift Test Test.out
])
AC_PROVIDE([$0])dnl
])

22
m4/ax_tmpdir_swift.m4 Normal file
View File

@ -0,0 +1,22 @@
# Serval Project Swift language support
#
# SYNOPSIS
#
# AX_TMPDIR_SWIFT
#
# DESCRIPTION
#
# AX_TMPDIR_SWIFT creates a temporary directory prefixed with "swft" that
# will be deleted when the shell exits. It sets the ax_tmpdir_swift shell
# variable to the absolute path of the created directory.
#
# Uses AS_TMPDIR() internally but preserves the value of the 'tmp' shell
# variable.
#
AC_DEFUN([AX_TMPDIR_SWIFT],[
AS_VAR_COPY([_swift_tmp], [tmp])
AS_TMPDIR([swft])
ax_tmpdir_swift="$tmp"
AS_VAR_COPY([tmp], [_swift_tmp])
])

2
main.c
View File

@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
extern int servald_main(int, char**); #include "servald_main.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

27
module.modulemap Normal file
View File

@ -0,0 +1,27 @@
/*
Serval DNA module map
Copyright (C) 2016-2017 Flinders University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
module servald {
requires tls // thread-local storage
module main {
header "servald_main.h"
}
}

View File

@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <signal.h> #include <signal.h>
#include "servald_main.h"
#include "commandline.h" #include "commandline.h"
#include "sighandlers.h" #include "sighandlers.h"
#include "conf.h" #include "conf.h"

20
servald_main.h Normal file
View File

@ -0,0 +1,20 @@
/*
Serval DNA main command-line entry point
Copyright (C) 2016 Flinders University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
int servald_main(int argc, char **argv);

14
servaldswift.swift Normal file
View File

@ -0,0 +1,14 @@
import Foundation
import servald.main
public func serval_daemon_main(args: [String]) -> CInt {
// print "args = \(args)"
var argv = args.map { strdup($0) }
argv.append(nil)
defer {
argv.forEach { free($0) }
}
return servald_main(CInt(argv.count - 1), &argv)
}
exit(serval_daemon_main(args: CommandLine.arguments))