autotoolize

This commit is contained in:
Barak A. Pearlmutter 2014-04-24 12:08:26 +01:00
parent 1619dd1863
commit 469edfa1b6
6 changed files with 322 additions and 199 deletions

View file

@ -1,80 +0,0 @@
prefix?=/usr/local
sbindir=$(prefix)/sbin
datadir=$(prefix)/share
mandir=$(datadir)/man
DESTDIR=
INSTALL=install
INSTALL_FLAGS=
MKDIR=mkdir
MKDIR_FLAGS=-p
RM=rm
RM_FLAGS=-f
TARGETOS = `uname`
all:
@(cd src; $(MAKE) TARGETOS=$(TARGETOS) all)
cross-android:
@(cd src; $(MAKE) base64u.c base64u.h)
@(cd src; ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk)
cross-android-dist:
@rm -rf iodine-latest-android*
@mkdir -p iodine-latest-android/armeabi iodine-latest-android/x86
@$(MAKE) cross-android TARGET_ARCH_ABI=armeabi
@cp src/libs/armeabi/* iodine-latest-android/armeabi
@$(MAKE) cross-android TARGET_ARCH_ABI=x86
@cp src/libs/x86/* iodine-latest-android/x86
@cp README README-android.txt CH* TO* iodine-latest-android
@echo "Create date: " > iodine-latest-android/VERSION
@date >> iodine-latest-android/VERSION
@echo "Git version: " >> iodine-latest-android/VERSION
@git rev-parse HEAD >> iodine-latest-android/VERSION
@zip -r iodine-latest-android.zip iodine-latest-android
cross-mingw:
@(cd src; $(MAKE) TARGETOS=windows32 CC=i686-mingw32-gcc all)
cross-mingw-dist: cross-mingw
@rm -rf iodine-latest-win32*
@mkdir -p iodine-latest-win32/bin
@for i in `ls bin`; do cp bin/$$i iodine-latest-win32/bin/$$i.exe; done
@cp /usr/i686-mingw32/usr/bin/zlib1.dll iodine-latest-win32/bin
@cp README README-win32.txt CH* TO* iodine-latest-win32
@echo "Create date: " > iodine-latest-win32/VERSION
@date >> iodine-latest-win32/VERSION
@echo "Git version: " >> iodine-latest-win32/VERSION
@git rev-parse HEAD >> iodine-latest-win32/VERSION
@zip -r iodine-latest-win32.zip iodine-latest-win32
install: all
$(MKDIR) $(MKDIR_FLAGS) $(DESTDIR)$(sbindir)
$(INSTALL) $(INSTALL_FLAGS) bin/iodine $(DESTDIR)$(sbindir)/iodine
chmod 755 $(DESTDIR)$(sbindir)/iodine
$(INSTALL) $(INSTALL_FLAGS) bin/iodined $(DESTDIR)$(sbindir)/iodined
chmod 755 $(DESTDIR)$(sbindir)/iodined
$(MKDIR) $(MKDIR_FLAGS) $(DESTDIR)$(mandir)/man8
$(INSTALL) $(INSTALL_FLAGS) man/iodine.8 $(DESTDIR)$(mandir)/man8/iodine.8
chmod 644 $(DESTDIR)$(mandir)/man8/iodine.8
uninstall:
$(RM) $(RM_FLAGS) $(DESTDIR)$(sbindir)/iodine
$(RM) $(RM_FLAGS) $(DESTDIR)$(sbindir)/iodined
$(RM) $(RM_FLAGS) $(DESTDIR)$(mandir)/man8/iodine.8
test: all
@echo "!! The check library is required for compiling and running the tests"
@echo "!! Get it at http://check.sf.net"
@(cd tests; $(MAKE) TARGETOS=$(TARGETOS) all)
clean:
@echo "Cleaning..."
@(cd src; $(MAKE) clean)
@(cd tests; $(MAKE) clean)
@rm -rf bin iodine-latest-win32* iodine-latest-android*

151
Makefile.am Normal file
View file

@ -0,0 +1,151 @@
## Process this file with automake to produce Makefile.in
################################################################
## shared ##
################################################################
AM_CPPFLAGS = -D$(OS)
AM_CFLAGS = -g -Wall -pedantic
################################################################
## docs ##
################################################################
dist_man_MANS = man/iodine.8
dist_doc_DATA = CHANGELOG README README-android.txt README-win32.txt \
TODO doc/proto_00000402.txt doc/proto_00000500.txt \
doc/proto_00000502.txt
################################################################
## misc ##
################################################################
EXTRA_DIST = .travis.yml doc/iodine-server.service \
doc/iodine-server.socket doc/iodine.te src/Android.mk
################################################################
## src/ ##
################################################################
sbin_PROGRAMS = iodine iodined
COMMONSRC0 = src/base32.c src/base64.c src/common.c src/dns.c \
src/encoding.c src/login.c src/md5.c src/read.c
COMMONSRC = $(COMMONSRC0) src/base128.c src/tun.c src/base64u.c \
src/base64u.h src/android_dns.h src/base128.h src/base32.h \
src/base64.h src/common.h src/dns.h src/encoding.h src/login.h \
src/md5.h src/read.h src/tun.h src/version.h src/windows.h
iodine_SOURCES = $(COMMONSRC) src/iodine.c src/client.c src/util.c \
src/client.h src/util.h
iodined_SOURCES = $(COMMONSRC) src/iodined.c src/user.c \
src/fw_query.c src/fw_query.h src/user.h
EXTRA_DIST += src/android_dns.h src/base128.h src/base32.h \
src/base64.h src/client.h src/common.h src/dns.h src/encoding.h \
src/fw_query.h src/login.h src/md5.h src/read.h src/tun.h src/user.h \
src/util.h src/version.h src/windows.h
src/base64u.c: src/base64.c
@echo Making $@
@echo '/* No use in editing, produced by Makefile! */' > $@
sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < $< >> $@
src/base64u.h: src/base64.h
@echo Making $@
@echo '/* No use in editing, produced by Makefile! */' > $@
sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < $< >> $@
BUILT_SOURCES = src/base64u.c src/base64u.h
MOSTLYCLEANFILES = src/base64u.c src/base64u.h
clean-local:
@echo Clean Android Stuff
-rm -rf src/obj src/libs
################################################################
## tests/ ##
################################################################
if HAVE_CHECK
TESTS = test-iodine
noinst_PROGRAMS = test-iodine
test_iodine_SOURCES = tests/test.c tests/base32.c tests/base64.c \
tests/common.c tests/read.c tests/dns.c tests/encoding.c \
tests/login.c tests/user.c tests/fw_query.c $(COMMONSRC0) src/user.c \
src/fw_query.c
EXTRA_DIST += tests/test.h
test_iodine_LDADD = $(CHECK_LIBS)
test_iodine_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS)
test_iodine_CPPFLAGS = $(AM_CPPFLAGS) -I src
endif
################################################################
## Ancient History ##
################################################################
# retain compatibility with former target "test"
.PHONY: test
test: check
# Compile for Android.
# It is likely possible to tweak autotools into supporting this
# configuration, once that is tested the below should be removed.
.PHONY: cross-android
cross-android: src/base64u.c src/base64u.h
(cd src; ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk)
.PHONY: cross-android-dist
cross-android-dist:
rm -rf iodine-latest-android*
mkdir -p iodine-latest-android/armeabi iodine-latest-android/x86
$(MAKE) cross-android TARGET_ARCH_ABI=armeabi
cp src/libs/armeabi/* iodine-latest-android/armeabi
$(MAKE) cross-android TARGET_ARCH_ABI=x86
cp src/libs/x86/* iodine-latest-android/x86
cp README README-android.txt CH* TO* iodine-latest-android/
echo "Create date: " > iodine-latest-android/VERSION
date >> iodine-latest-android/VERSION
echo "Git version: " >> iodine-latest-android/VERSION
echo $(GITREVISION) >> iodine-latest-android/VERSION
zip -r iodine-latest-android.zip iodine-latest-android
# Compile for MS Windows.
# This platform is supported by autotools, so the below should be removed once
# autotools is tested in that configuration.
.PHONY: cross-mingw
cross-mingw:
echo "WARNING:"
echo "This make target is unlikely to work properly."
echo "Cross compilation is supported by autotools."
echo " ./configure --build=turingmachine-unknown-linux-gnu --host=mingw32"
$(MAKE) OS=WINDOWS32 CC=i686-mingw32-gcc all
.PHONY: cross-mingw-dist
cross-mingw-dist: cross-mingw
rm -rf iodine-latest-win32*
mkdir -p iodine-latest-win32/bin
for i in `ls bin`; do cp bin/$$i iodine-latest-win32/bin/$$i.exe; done
cp /usr/i686-mingw32/usr/bin/zlib1.dll iodine-latest-win32/bin/
cp README README-win32.txt CH* TO* iodine-latest-win32/
echo "Create date: " > iodine-latest-win32/VERSION
date >> iodine-latest-win32/VERSION
echo "Git version: " >> iodine-latest-win32/VERSION
echo $(GITREVISION) >> iodine-latest-win32/VERSION
zip -r iodine-latest-win32.zip iodine-latest-win32

171
configure.ac Normal file
View file

@ -0,0 +1,171 @@
# Process this file with autoconf to produce a configure script.
# Prologue
AC_PREREQ([2.69])
AC_INIT([iodine],[0.6.0rc1],[erik@kryo.se],[],[http://dev.kryo.se/iodine/])
AC_CONFIG_SRCDIR([src/iodine.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([autotools])
AC_CONFIG_AUX_DIR([autotools])
AM_INIT_AUTOMAKE([subdir-objects foreign -Wall])
# Misc
# Define OS to upcased "uname --kernel-name", i.e., LINUX, DARWIN, etc.
# Used by Makefile.am as cpp symbol to define.
# We use autotools canonical designation to allow cross compilation.
# It would be reasonable to, at some point, update the C sources to
# use these more canonical designations.
# But for now, we must adjust some of them.
AC_MSG_CHECKING([environment to compile for])
AC_CANONICAL_HOST
# No need to adjust these: FREEBSD, NETBSD, OPENBSD, BEOS
AS_CASE([${host_os}],
[linux-gnu], [OS=LINUX],
[mingw32], [OS=WINDOWS32],
[macos], [OS=DARWIN],
[linux-android], [OS=ANDROID],
[OS="$(echo ${host_os}|tr "a-z" "A-Z_")"])
uname_os="$(uname | tr "a-z" "A-Z")"
AC_MSG_NOTICE([host_os: ${host_os}])
AC_MSG_NOTICE([uname_os: ${uname_os}])
AC_MSG_NOTICE([adjusted OS: ${OS}])
AC_SUBST([OS])
AS_CASE([${OS}],
[WINDOWS32],
AC_DEFINE([WINVER],[0x0501],
[Define appropriately on MS Windows 32]))
# The AC_SUBST for GITREVISION is used only in legacy stanza; remove
# when unused in Makefile.am, leaving only the config.h #define.
AC_SUBST([GITREVISION],[$(git describe --always || echo not-in-git)])
AC_DEFINE_UNQUOTED([GITREVISION],["${GITREVISION}"],
[Precise git commit checked out when building])
# Checks for programs
AC_PROG_CC
AC_PROG_INSTALL
# Process options
AC_ARG_ENABLE([systemd],
[AS_HELP_STRING([--enable-systemd],
[enable systemd support @<:@default=check@:>@])],,
[enable_systemd=check])
AC_ARG_ENABLE([selinux],
[AS_HELP_STRING([--enable-selinux],
[enable selinux support @<:@default=check@:>@])],,
[enable_selinux=check])
# Checks for libraries
# Unclear why pthread is needed.
# Uncomment and replace ? by called procedure requiring -lpthread.
#AC_SEARCH_LIBS([?], [pthread])
AC_SEARCH_LIBS([uncompress], [z])
# Enable systemd per option by setting HAVE_SYSTEMD
AS_CASE([${enable_systemd}],
[yes|check],
[AC_MSG_CHECKING([systemd])
AC_SEARCH_LIBS([sd_listen_fds], [systemd-daemon])
AC_CHECK_FUNC([sd_listen_fds],
[AC_MSG_RESULT([enabled: systemd])
AC_DEFINE([HAVE_SYSTEMD],[1],
[Define to 1 to enable systemd support])],
AS_CASE([${enable_systemd}],
[yes],
AC_MSG_ERROR([systemd support not available]),
AC_MSG_RESULT([disabled: systemd])))],
[no],,
[AC_MSG_ERROR([invalid argument, --enable-systemd=${enable_systemd}])])
# Enable selinux per option by setting HAVE_SETCON
AS_CASE([${enable_selinux}],
[yes|check],
[AC_SEARCH_LIBS([setcon], [selinux])
AC_CHECK_FUNCS([setcon],
AC_MSG_RESULT([enabled: selinux]),
AS_CASE([${enable_selinux}],
[yes],
AC_MSG_ERROR([selinux support not available]),
[check],
AC_MSG_RESULT([disabled: selinux])))],
[no],
AC_MSG_RESULT([disabled: selinux]),
[AC_MSG_ERROR([invalid argument, --enable-selinux=${enable_selinux}])])
# The check library is used for the unit testing. Not bothering to
# implement an --enable-tests option, as they are only run by "make
# check" so there is no user-level difference. If the unit tests
# won't even *compile* there is probably a better solution than just
# turning them off, and build time is minimal.
PKG_CHECK_MODULES(CHECK,[check],
AC_MSG_RESULT([enabled: unit testing]),
AC_MSG_RESULT([disabled: unit testing]))
AM_CONDITIONAL([HAVE_CHECK],[test -z "${CHECK_PKG_ERRORS}"])
# For each commented AC_SEARCH_LIBS below, uncomment and replace ? by
# called procedure provided only by that library on the platform(s) in
# question.
# for SunOS / solaris:
#AC_SEARCH_LIBS([?], [nsl])
# for BeOS:
#AC_SEARCH_LIBS([?], [bind])
#AC_SEARCH_LIBS([?], [bsd])
# for SunOS / solaris / BeOS:
#AC_SEARCH_LIBS([?], [socket])
# for Haiku:
#AC_SEARCH_LIBS([?], [network])
# for MS windows32:
#AC_SEARCH_LIBS([?], [ws2_32])
#AC_SEARCH_LIBS([?], [iphlpapi])
# Checks for headers
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h systemd/sd-daemon.h selinux/selinux.h])
# Checks for typedefs, structures, and compiler characteristics
AC_CHECK_TYPES([socklen_t],,
AC_DEFINE([socklen_t],[int],
[define to int if type socklen_t not found]))
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
# Checks for library functions
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_CHECK_FUNCS([alarm dup2 inet_ntoa memset select socket strcasecmp strchr strdup strerror strrchr strstr])
# Epilogue
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

View file

@ -1,48 +0,0 @@
COMMONOBJS = tun.o dns.o read.o encoding.o login.o base32.o base64.o base64u.o base128.o md5.o common.o
CLIENTOBJS = iodine.o client.o util.o
CLIENT = ../bin/iodine
SERVEROBJS = iodined.o user.o fw_query.o
SERVER = ../bin/iodined
OS = `echo $(TARGETOS) | tr "a-z" "A-Z"`
ARCH = `uname -m`
HEAD_COMMIT = `git rev-parse --short HEAD`
LIBPATH = -L.
LDFLAGS += -lz `sh osflags $(TARGETOS) link` $(LIBPATH)
CFLAGS += -c -g -Wall -D$(OS) -pedantic `sh osflags $(TARGETOS) cflags` -DGITREVISION=\"$(HEAD_COMMIT)\"
all: stateos $(CLIENT) $(SERVER)
stateos:
@echo OS is $(OS), arch is $(ARCH)
$(CLIENT): $(COMMONOBJS) $(CLIENTOBJS)
@echo LD $@
@mkdir -p ../bin
@$(CC) $(COMMONOBJS) $(CLIENTOBJS) -o $(CLIENT) $(LDFLAGS)
$(SERVER): $(COMMONOBJS) $(SERVEROBJS)
@echo LD $@
@mkdir -p ../bin
@$(CC) $(COMMONOBJS) $(SERVEROBJS) -o $(SERVER) $(LDFLAGS)
.c.o:
@echo CC $<
@$(CC) $(CFLAGS) $< -o $@
base64u.o client.o iodined.o: base64u.h
base64u.c: base64.c
@echo Making $@
@echo '/* No use in editing, produced by Makefile! */' > $@
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < base64.c >> $@
base64u.h: base64.h
@echo Making $@
@echo '/* No use in editing, produced by Makefile! */' > $@
@sed -e 's/\([Bb][Aa][Ss][Ee]64\)/\1u/g ; s/0123456789+/0123456789_/' < base64.h >> $@
clean:
@echo "Cleaning src/"
@rm -f $(CLIENT){,.exe} $(SERVER){,.exe} *~ *.o *.core base64u.*
@rm -rf obj libs #android stuff

View file

@ -1,45 +0,0 @@
#!/bin/sh
case $2 in
link)
case $1 in
SunOS | solaris)
echo '-lsocket -lnsl';
;;
BeOS)
echo '-lsocket -lbind -lbsd';
;;
Haiku)
echo '-lnetwork';
;;
windows32)
echo '-lws2_32 -liphlpapi';
;;
Linux)
FLAGS="";
[ -e /usr/include/selinux/selinux.h ] && FLAGS="$FLAGS -lselinux";
[ -e /usr/include/systemd/sd-daemon.h ] && FLAGS="$FLAGS -lsystemd-daemon";
echo $FLAGS;
;;
esac
;;
cflags)
case $1 in
windows32)
echo '-DWINVER=0x0501';
;;
BeOS)
echo '-Dsocklen_t=int';
;;
Linux)
FLAGS="";
[ -e /usr/include/selinux/selinux.h ] && FLAGS="$FLAGS -DHAVE_SETCON";
[ -e /usr/include/systemd/sd-daemon.h ] && FLAGS="$FLAGS -DHAVE_SYSTEMD";
echo $FLAGS;
;;
esac
;;
*)
;;
esac

View file

@ -1,26 +0,0 @@
CC = gcc
TEST = test
OBJS = test.o base32.o base64.o common.o read.o dns.o encoding.o login.o user.o fw_query.o
SRCOBJS = ../src/base32.o ../src/base64.o ../src/common.o ../src/read.o ../src/dns.o ../src/encoding.o ../src/login.o ../src/md5.o ../src/user.o ../src/fw_query.o
OS = `uname | tr "a-z" "A-Z"`
CHECK_PATH = /usr/local
LDFLAGS = -L$(CHECK_PATH)/lib `pkg-config check --libs` -lpthread `sh ../src/osflags $(TARGETOS) link`
CFLAGS = -g -Wall -D$(OS) `pkg-config check --cflags` -I../src -I$(CHECK_PATH)/include -pedantic `sh ../src/osflags $(TARGETOS) cflags`
all: $(TEST)
@LD_LIBRARY_PATH=${CHECK_PATH}/lib ./$(TEST)
$(TEST): $(OBJS) $(SRCOBJS)
@echo LD $(TEST)
@$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS)
.c.o:
@echo CC $<
@$(CC) $(CFLAGS) -c $<
clean:
@echo "Cleaning tests/"
@rm -f *~ *.core $(TEST) $(OBJS)