serval-dna/Makefile.in
Andrew Bettison ca8e846264 Add iOS Framework Bundle build
The new ios/configure script performs a separate ../configure for each of
the following iOS targets:

    iPhoneOS        on armv7
    iPhoneOS        on arm64
    iPhoneSimulator on i386
    iPhoneSimulator on x86_64

The script then creates ios/Makefile that builds a static iOS Framework
Bundle suitable for inclusion in an Xcode iOS project.

Add the --xcode-sdk=SDK option to configure.ac, to support cross
compiling using Apple Xcode.  It prefixes all compile/link toolchain
commands with the "xcrun --sdk SDK" command, ie, CC, AS, LD, AR, RANLIB,
etc.

Re-structure headerfiles.mk to separate "public" from "private" headers,
because the Framework module only exposes the public ones.  Moves the
SQLITE3_AMALGAMATION definition from Makefile.in into headerfiles.mk.

Update INSTALL.md and add a technical document for Apple iOS.

This enables development of Serval DNA within the context of an Xcode
iOS project using the standard edit-make-test cycle: after modifying a
Serval DNA source file, "cd ios; make" will recompile the changed file
for all the target architectures and update the Framework Bundle.
Rebuilding the Xcode project will then incorporate the changes, which
can be tested immediately.
2018-03-06 15:29:29 +10:30

488 lines
16 KiB
Makefile

# Makefile.in for Serval DNA daemon and libraries
# nnnn
# vim: noet ts=8 sts=0 sw=8
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
sysconfdir=@sysconfdir@
localstatedir=@localstatedir@
srcdir=@srcdir@
abs_srcdir=@abs_srcdir@
abs_builddir=@abs_builddir@
CC = @CC@
AR = @AR@
RANLIB = @RANLIB@
JAVAC= @JAVAC@
SWIFTC= @SWIFTC@
SWIFTCFLAGS= @SWIFTCFLAGS@ -I$(abs_builddir) -I$(abs_srcdir)
SWIFTLIBS= @LIBS@
SWIFT_BUILD= @SWIFT_BUILD@
SWIFT_BUILD_FLAGS= $(addprefix -Xswiftc , $(SWIFTCFLAGS))
SWIFT_MODULE_NAME= ServalDNA
SWIFT_PACKAGE_DIR= $(srcdir)/swift-daemon-api
SWIFT_BUILD_DIR= $(abs_builddir)/swift-daemon-api/build
INSTALL= install
INSTALL_PROGRAM= $(INSTALL)
INSTALL_DATA= $(INSTALL) -m 644
include $(srcdir)/headerfiles.mk # sets SQLITE3_AMALGAMATION
include $(srcdir)/sourcefiles.mk # depends on SQLITE3_AMALGAMATION
LIBSODIUM_SUBDIR = libsodium/
LIBSODIUM_DEV = libsodium-dev
LIBSODIUM_HEADERS = $(LIBSODIUM_DEV)/include/sodium.h
LIBSODIUM_A = $(LIBSODIUM_DEV)/lib/libsodium.a
LIBSODIUM_SO = $(LIBSODIUM_DEV)/lib/libsodium.so
OBJSDIR_SERVALD = objs_servald
OBJSDIR_LIB = objs_lib
OBJSDIR_TOOLS = objs
OBJSDIRS = $(OBJSDIR_SERVALD) $(OBJSDIR_LIB) $(OBJSDIR_TOOLS)
SERVAL_DAEMON_OBJS = \
$(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_SERVALD)/, $(MDP_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_SOURCES:.c=.o))
ifeq (@HAVE_JNI_H@,yes)
SERVAL_DAEMON_JNI_OBJS = \
$(addprefix $(OBJSDIR_SERVALD)/, $(SERVAL_DAEMON_JNI_SOURCES:.c=.o))
SERVAL_DAEMON_OBJS += $(SERVAL_DAEMON_JNI_OBJS)
endif
SQLITE3_OBJS = \
$(addprefix $(OBJSDIR_SERVALD)/, $(notdir $(SQLITE3_SOURCES:.c=.o)))
SERVALD_OBJS = \
$(SQLITE3_OBJS) \
$(SERVAL_DAEMON_OBJS)
LIB_SERVAL_OBJS = \
$(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(MDP_CLIENT_SOURCES:.c=.o))
MONITOR_CLIENT_OBJS = \
$(addprefix $(OBJSDIR_LIB)/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(CLIENT_ONLY_SOURCES:.c=.o)) \
$(addprefix $(OBJSDIR_LIB)/, $(MONITOR_CLIENT_SRCS:.c=.o))
SIMULATOR_OBJS = \
$(addprefix $(OBJSDIR_TOOLS)/, $(SIMULATOR_SOURCES:.c=.o))
PREFIXED_HEADERS = $(addprefix $(srcdir)/, $(ALL_HDRS))
PREFIXED_SOURCES = $(addprefix $(srcdir)/, $(ALL_SOURCES))
LDFLAGS=@LDFLAGS@ @LIBS@
CFLAGS= -I. -I$(srcdir)/$(SQLITE3_AMALGAMATION) @CPPFLAGS@ @CFLAGS@
CFLAGS+=-DSYSCONFDIR="\"$(sysconfdir)\"" -DLOCALSTATEDIR="\"$(localstatedir)\""
CFLAGS+=-DSQLITE_THREADSAFE=0 \
-DSQLITE_OMIT_DATETIME_FUNCS \
-DSQLITE_OMIT_COMPILEOPTION_DIAGS \
-DSQLITE_OMIT_DEPRECATED \
-DSQLITE_OMIT_LOAD_EXTENSION \
-DSQLITE_OMIT_VIRTUALTABLE \
-DSQLITE_OMIT_AUTHORIZATION
CFLAGS+=-fPIC -DSERVAL_ENABLE_DEBUG=1 -Wall -Werror -Wextra -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2
# Solaris magic
CFLAGS+=-DSHA2_USE_INTTYPES_H -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1
# OSX magic to compensate for the Solaris magic
CFLAGS+=-D_DARWIN_C_SOURCE
CFLAGS_SQLITE=@CFLAGS_SQLITE@
-include $(srcdir)/Makefile.dbg
# 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@
DEFS= @DEFS@
SWIFTDEFS= $(addprefix -Xcc , $(DEFS))
# Usage: $(call MERGE_STATIC_LIBS, libdest.a, libsrcfoo.a libsrcbar.a)
MERGE_STATIC_LIBS = echo MERGE $(1) = $(2); \
tmp="$$(mktemp -d)" && \
( cd "$$tmp" $(foreach LIB, $(2), && $(AR) -x $(abspath $(LIB))) ) && \
$(RM) $(1) && \
$(AR) -cr $(1) "$$tmp"/*.o && \
$(RANLIB) $(1) && \
$(RM) -r "$$tmp"
.PHONY: all libs test install uninstall clean
all: libs servald directory_service test
libs: libservaldaemon.so libservaldaemon.a \
libservalclient.so libservalclient.a \
libmonitorclient.so libmonitorclient.a
test: servaldwrap serval-tests \
fakeradio simulator \
tfw_createfile
install: servald
$(INSTALL_PROGRAM) -D servald $(DESTDIR)$(sbindir)/servald
uninstall:
$(RM) $(DESTDIR)$(sbindir)/servald
clean:
$(RM) -r $(LIBSODIUM_DEV) \
$(OBJSDIRS:%=%/*) \
servald \
libservaldaemon.so libservaldaemon.a \
libservalclient.so libservalclient.a \
libmonitorclient.so libmonitorclient.a \
tfw_createfile directory_service fakeradio simulator serval-tests \
tags
cd $(LIBSODIUM_SUBDIR) && $(MAKE) clean
distclean: clean
$(RM) config.h config.status config.log testconfig.sh
cd $(LIBSODIUM_SUBDIR) && $(MAKE) distclean
# Only provide Java targets if the Java compiler is available.
ifneq ($(JAVAC),)
all: java-api
clean: java-api-clean
.PHONY: java-api java-api-clean
java-api:
@mkdir -p java-api
@cd java-api && $(MAKE) all
java-api-clean:
@cd java-api 2>/dev/null && $(MAKE) clean
endif # $(JAVAC)
ifneq ($(SWIFTC),) # Only provide Swift targets if the Swift compiler is available.
all: swift-daemon-api swift-client-api
test: servaldswift
clean: swift-daemon-api-clean swift-client-api-clean
.PHONY: swift-daemon-api swift-daemon-api-clean swift-client-api swift-client-api-clean
libServalDNA.a $(SWIFT_MODULE_NAME).swiftmodule $(SWIFT_MODULE_NAME).swiftdoc: swift-daemon-api
cp $(SWIFT_BUILD_DIR)/debug/$(notdir $@) $@
swift-daemon-api:
mkdir -p $(SWIFT_BUILD_DIR) && \
cd $(SWIFT_PACKAGE_DIR) && \
$(SWIFT_BUILD) --build-path $(SWIFT_BUILD_DIR) $(SWIFT_BUILD_FLAGS) $(SWIFTDEFS)
swift-daemon-api-clean:
$(RM) -r $(SWIFT_BUILD_DIR) \
$(SWIFT_MODULE_NAME).swiftmodule \
$(SWIFT_MODULE_NAME).swiftdoc
swift-client-api:
@mkdir -p swift-client-api
cd swift-client-api && $(MAKE) all
swift-client-api-clean:
cd swift-client-api 2>/dev/null && $(MAKE) clean
endif # $(SWIFTC)
# Build the Sodium elliptic curve encryption library within its 'libsodium'
# subtree, and install its development files (headers and libraries) into our
# $(LIBSODIUM_DEV) subdirectory. Then use the contents of this subdirectory to
# provide system headers, eg <sodium.h>, and libraries, eg, libsodium.a, to
# compile and link Serval DNA. This completely avoids any dependency on the
# system's installed libsodium run-time and development packages.
CFLAGS+= -isystem $(LIBSODIUM_DEV)/include
.PHONY: libsodium-dev
libsodium-dev $(LIBSODIUM_HEADERS) $(LIBSODIUM_A): $(LIBSODIUM_DEV)/.installed
# The libsodium package uses libtool, so by default its static libraries get
# compiled without the -fPIC option. This prevents the libsodium static
# library from being linked into a shared library. However, this Makefile
# needs to do exactly that, to make libservaldaemon.so, so passes the
# -prefer-pic libtool option, which causes libtool to use -fPIC even when
# compiling for static libraries.
$(LIBSODIUM_DEV)/.installed:
@echo MAKE $(LIBSODIUM_DEV)
@mkdir -p $(LIBSODIUM_DEV)
@$(RM) $@
@touch $@.in-progress
@cd $(LIBSODIUM_SUBDIR) && $(MAKE) \
CFLAGS+="-prefer-pic" \
prefix=$(abspath $(LIBSODIUM_DEV)) \
install
@mv -f $@.in-progress $@
# Source code test coverage support -- see doc/Testing.md
.PHONY: covzero covinit covhtml is_built_with_coverage has_coverage_data
covzero: | is_built_with_coverage
@echo REMOVE all .gcda files
@find $(OBJSDIRS) -type f -name '*.gcda' -print0 | xargs -0 $(RM)
covinit: servald-initial.info
covhtml: coverage_html/index.html
is_built_with_coverage:
@for obj in $(SERVALD_OBJS); do \
gcno="$${obj%.o}.gcno" ;\
if [ ! -r "$$gcno" ]; then \
echo "ERROR: servald has not been compiled for code coverage; missing $$gcno" ;\
exit 1 ;\
fi ;\
done
has_coverage_data: | is_built_with_coverage
@count=0; for obj in $(SERVALD_OBJS); do \
gcda="$${obj%.o}.gcda" ;\
[ -s "$$gcda" ] && count=$$(($$count + 1)) ;\
done ;\
if [ $$count -eq 0 ]; then \
echo "ERROR: no code coverage data; run some tests" ;\
exit 1 ;\
fi
servald-initial.info: Makefile servald | is_built_with_coverage
geninfo --quiet --initial --checksum --base-directory=$(abspath .) --no-external $(OBJSDIR_SERVALD) -o $@
servald-coverage.info: Makefile servald $(shell find $(OBJSDIR_SERVALD) -type f -name '*.gcda' 2>/dev/null) | has_coverage_data
geninfo --quiet --checksum --base-directory=$(abspath .) --no-external $(OBJSDIR_SERVALD) -o $@ 2>&1 | { grep -v 'WARNING: no data found for .*\.h$$' || true; }
@[ -s $@ ]
coverage_html/index.html: Makefile servald-initial.info servald-coverage.info
$(RM) -r coverage_html
genhtml --quiet servald-initial.info servald-coverage.info -o coverage_html
# Autconf support -- helpful messages to help avoid some common build mistakes.
.PRECIOUS: Makefile config.status $(srcdir)/configure
Makefile: $(srcdir)/Makefile.in config.status
$(warning Makefile may be out of date, please run ./config.status)
config.status: $(srcdir)/configure
$(warning config.status may be out of date, please run $(srcdir)/configure)
$(srcdir)/configure: $(srcdir)/configure.ac
$(warning $(srcdir)configure may be out of date, please run $(if $(srcdir:.=),cd $(srcdir) && ,)autoreconf -f -i -I m4)
# Embed Serval DNA's version into libraries and executables.
$(OBJSDIR_TOOLS)/version.o: $(PREFIXED_SOURCES) \
$(PREFIXED_HEADERS) \
$(srcdir)/version_servald.c \
$(srcdir)/version_string.sh \
$(wildcard VERSION.txt) \
$(srcdir)/COPYRIGHT.txt
@echo CC version_servald.c
@mkdir -p $(dir $@)
@$(RM) $(@:.o=.gcno) $(@:.o=.gcda)
@V=`$(srcdir)/version_string.sh --repository=$(srcdir) --ignore-untracked` \
&& C="`sed -e :a -e N -e '$$!ba' -e 's/[\\\\"]/\\\\&/g' -e 's/\\n/\\\\n/g' $(srcdir)/COPYRIGHT.txt`" \
&& $(CC) $(CFLAGS) $(DEFS) -c $(srcdir)/version_servald.c -o $@ -DSERVALD_VERSION="\"$$V\"" -DSERVALD_COPYRIGHT="\"$$C\""
#' <-- fixes vim syntax highlighting
# Compile SQLITE as a special case, because it is imported source code.
# Instead of fixing warnings case-by-case in the sqlite.c source code, simply
# suppress the classes of warnings that cause compilation errors with
# -Werror.
$(SQLITE3_OBJS): $(OBJSDIR_SERVALD)/%.o: $(srcdir)/$(SQLITE3_AMALGAMATION)/%.c
@echo SERVALD CC $<
@mkdir -p $(dir $@)
@$(RM) $(@:.o=.gcno) $(@:.o=.gcda)
@$(CC) $(CFLAGS) $(CFLAGS_SQLITE) $(DEFS) -c $< -o $@
# No object files in source directory!
%.o: $(srcdir)/%.c
$(OBJSDIR_TOOLS)/%.o: $(srcdir)/%.c
@echo CC $<
@mkdir -p $(dir $@)
@$(RM) $(@:.o=.gcno) $(@:.o=.gcda)
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
$(OBJSDIR_SERVALD)/%.o: $(srcdir)/%.c
@echo SERVALD CC $<
@mkdir -p $(dir $@)
@$(RM) $(@:.o=.gcno) $(@:.o=.gcda)
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
$(OBJSDIR_LIB)/%.o: $(srcdir)/%.c
@echo LIB CC $<
@mkdir -p $(dir $@)
@$(RM) $(@:.o=.gcno) $(@:.o=.gcda)
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
# Dependencies on header files. The following list of dependencies is too
# broad so it sometimes results in unnecessary re-compilation, but that is
# better than too narrow, which can result in missed re-compilation.
$(SERVAL_DAEMON_OBJS): Makefile $(CONFIG_H) $(PREFIXED_HEADERS) $(LIBSODIUM_HEADERS)
$(SERVALD_OBJS): Makefile $(LIBSODIUM_HEADERS)
$(LIB_SERVAL_OBJS): Makefile $(CONFIG_H) $(PREFIXED_HEADERS) $(LIBSODIUM_HEADERS)
$(OBJSDIR_TOOLS)/tfw_createfile.o: Makefile $(srcdir)/str.h
$(OBJSDIR_TOOLS)/directory_service.o: Makefile $(CONFIG_H) $(PREFIXED_HEADERS) $(LIBSODIUM_HEADERS)
$(MONITOR_CLIENT_OBJS): Makefile $(CONFIG_H) $(PREFIXED_HEADERS) $(LIBSODIUM_HEADERS)
$(SIMULATOR_OBJS): Makefile $(CONFIG_H) $(PREFIXED_HEADERS) $(LIBSODIUM_HEADERS)
# Rules for main targets.
.INTERMEDIATE: _servald.a
_servald.a: $(SERVALD_OBJS) $(OBJSDIR_TOOLS)/version.o
@echo AR $@
@$(RM) $@
@$(AR) -cr $@ $^
libservaldaemon.a: _servald.a $(LIBSODIUM_A)
@$(call MERGE_STATIC_LIBS, $@, $^)
libservaldaemon.so: \
$(OBJSDIR_SERVALD)/servald_features.o \
$(OBJSDIR_SERVALD)/log_output_console.o \
$(OBJSDIR_SERVALD)/log_output_file.o \
$(SERVAL_DAEMON_JNI_OBJS) \
_servald.a \
$(LIBSODIUM_A)
@echo LINK $@
@$(CC) -Wall -shared -o $@ $(LDFLAGS) $(filter %.o, $^) $(filter %.a, $^)
# The daemon executable. There is no main.o mentioned in this link line, so
# the link brings it in from libservaldaemon.a in order to resolve the 'main'
# symbol. The servald_features.o object causes all the other .o object files
# to be pulled into the link.
servald: $(OBJSDIR_SERVALD)/servald_features.o \
$(OBJSDIR_SERVALD)/log_output_console.o \
$(OBJSDIR_SERVALD)/log_output_file.o \
libservaldaemon.a
@echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS)
ifneq ($(SWIFTC),) # Only provide Swift targets if the Swift compiler is available.
# 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_file.o \
libservaldaemon.a \
$(SWIFT_MODULE_NAME).swiftmodule \
libServalDNA.a
@echo SWIFT $@
@$(SWIFTC) -emit-executable -o $@ \
$(SWIFTCFLAGS) $(SWIFTDEFS) \
$(filter %.swift, $^) $(filter %.o, $^) $(filter %.a, $^) \
$(SWIFTLIBS)
endif # $(SWIFTC)
servaldwrap: $(OBJSDIR_SERVALD)/servalwrap.o
@echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS)
serval-tests: $(OBJSDIR_SERVALD)/test_features.o libservaldaemon.a
@echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS)
directory_service: $(OBJSDIR_TOOLS)/directory_service.o libservalclient.a
@echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS)
tfw_createfile: $(OBJSDIR_TOOLS)/tfw_createfile.o libservalclient.a
@echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS)
fakeradio: $(OBJSDIR_TOOLS)/fakeradio.o libservalclient.a
@echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS)
simulator: $(SIMULATOR_OBJS) libservalclient.a
@echo LINK $@
@$(CC) -Wall -o $@ $^ $(LDFLAGS)
.INTERMEDIATE: _servalclient.a
_servalclient.a: $(LIB_SERVAL_OBJS) $(OBJSDIR_TOOLS)/version.o
@echo AR $@
@$(RM) $@
@$(AR) -cr $@ $^
libservalclient.a: _servalclient.a $(LIBSODIUM_A)
@$(call MERGE_STATIC_LIBS, $@, $^)
libservalclient.so: $(LIB_SERVAL_OBJS) $(OBJSDIR_TOOLS)/version.o $(LIBSODIUM_A)
@echo LINK $@
@$(CC) -Wall -shared -o $@ $(LDFLAGS) $(filter %.o %.a, $^) $(filter %.a, $^)
.INTERMEDIATE: _monitorclient.a
_monitorclient.a: $(MONITOR_CLIENT_OBJS) $(OBJSDIR_TOOLS)/version.o
@echo AR $@
@$(RM) $@
@$(AR) -cr $@ $^
libmonitorclient.a: _monitorclient.a $(LIBSODIUM_A)
@$(call MERGE_STATIC_LIBS, $@, $^)
libmonitorclient.so: $(MONITOR_CLIENT_OBJS) $(OBJSDIR_TOOLS)/version.o $(LIBSODIUM_A)
@echo LINK $@
@$(CC) -Wall -shared -o $@ $(LDFLAGS) $(filter %.o, $^) $(filter %.a, $^)
# The tags will always index all the Serval DNA headers and source files. If
# serval-tools is installed, then it will also index all the libsodium, JNI
# and Android NDK header files.
$(srcdir)/tags: Makefile $(PREFIXED_HEADERS) $(PREFIXED_SOURCES)
{ for file in $(PREFIXED_HEADERS) $(PREFIXED_SOURCES); do echo "$$file"; done; \
find $(LIBSODIUM_DEV)/include -type f ; \
sp-find-gcc-headers $(CFLAGS) 2>/dev/null; \
ndk_prefix=$$(sp-ndk-prefix . 2>/dev/null) && find "$$ndk_prefix/arch-arm/usr/include" -type f; \
} | ctags -L- -f $@ --tag-relative=yes --c-kinds=defgmpstuv
# Helpful target to update the COPYRIGHT.txt file by harvesting copyright
# information from the contents of all the source and header files. This
# should be run periodically and the results reviewed, manually adjusted and
# committed to the repository.
findPATH = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
COPYRIGHT_TOOL := $(call findPATH,sp-copyright-tool)
copyright:
@if [ -x "$(COPYRIGHT_TOOL)" ]; then \
echo GENERATE COPYRIGHT.txt; \
$(COPYRIGHT_TOOL) -o COPYRIGHT.txt condense \
$(PREFIXED_HEADERS) \
$(PREFIXED_SOURCES) \
$(find $(srcdir)/java-api -type f -name '*.java') \
$(find $(srcdir)/swift-api -type f -name '*.swift') \
; \
else \
echo 'sp-copyright-tool is not in $$PATH; COPYRIGHT.txt not updated'; \
fi