Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cross compiling until we can compile for windows #1135

Merged
merged 12 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,6 @@
run: |
git fetch --force --tags


- name: generate a makefile and use it to install more packages
run: |
# This is a pretty big hammer, but gets the windows compile moving
./scripts/hack_fakeautoconf.sh
make build-dep
shell: bash

- name: Run a configure step
run: |
export CFLAGS="-fprofile-arcs -ftest-coverage"
Expand Down Expand Up @@ -494,13 +486,13 @@
include:
- name: mips_24kc
sdk_ver: 22.03.3
sdk: https://downloads.openwrt.org/releases/22.03.3/targets/lantiq/xrx200/openwrt-sdk-22.03.3-lantiq-xrx200_gcc-11.2.0_musl.Linux-x86_64.tar.xz

Check warning on line 489 in .github/workflows/tests.yml

View workflow job for this annotation

GitHub Actions / Code syntax

489:81 [line-length] line too long (155 > 80 characters)
- name: i386_pentium4
sdk_ver: 22.03.3
sdk: https://downloads.openwrt.org/releases/22.03.3/targets/x86/generic/openwrt-sdk-22.03.3-x86-generic_gcc-11.2.0_musl.Linux-x86_64.tar.xz

Check warning on line 492 in .github/workflows/tests.yml

View workflow job for this annotation

GitHub Actions / Code syntax

492:81 [line-length] line too long (151 > 80 characters)
- name: x86_64
sdk_ver: 22.03.3
sdk: https://downloads.openwrt.org/releases/22.03.3/targets/x86/64/openwrt-sdk-22.03.3-x86-64_gcc-11.2.0_musl.Linux-x86_64.tar.xz

Check warning on line 495 in .github/workflows/tests.yml

View workflow job for this annotation

GitHub Actions / Code syntax

495:81 [line-length] line too long (141 > 80 characters)

defaults:
run:
Expand Down Expand Up @@ -708,16 +700,21 @@
strategy:
fail-fast: true
matrix:
arch:
- arm-linux-gnueabi
include:
- arch: arm-linux-gnueabi
- arch: aarch64-linux-gnu

# Unfortunately, the ubnuts mingw package names dont follow the
# same naming convention as every other cross-compiler.
- arch: x86_64-w64-mingw32
package_suffix: mingw-w64-x86-64

# I assume these architectures produce working code, but this has
# not been directly confirmed.
# They are compiled dynamically against normal libc, so will not
# work on openwrt.
- aarch64-linux-gnu
- mips-linux-gnu
- mipsel-linux-gnu
- arch: mips-linux-gnu
- arch: mipsel-linux-gnu

steps:
- uses: actions/checkout@v3
Expand All @@ -732,8 +729,8 @@
run: |
sudo apt-get update
sudo apt-get install \
binutils-${{ matrix.arch }} \
gcc-${{ matrix.arch }}
binutils-${{ matrix.package_suffix || matrix.arch }} \
gcc-${{ matrix.package_suffix || matrix.arch }}

- name: Configure and Build
shell: bash
Expand Down
85 changes: 35 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ all:

export CC
export AR
export EXE
export CFLAGS
export LDFLAGS
export LDLIBS
export CONFIG_HOST_OS

-include config.mak

Expand Down Expand Up @@ -38,24 +40,6 @@ ifndef UNAME_S
$(error Could not run uname command, cannot continue)
endif

# Any compile environment that needs different flags, libraries, includes or
# other settings will get its own CONFIG_TARGET value. For cross compiling,
# this might be set externally to the Makefile, but if not set we try to
# set a reasonable default.

export CONFIG_TARGET
ifndef CONFIG_TARGET
ifeq ($(shell uname -o),Msys)
CONFIG_TARGET=mingw
else ifeq ($(shell uname -s),Darwin)
CONFIG_TARGET=darwin
else ifeq ($(shell uname), SunOS)
CONFIG_TARGET=sunos
else
CONFIG_TARGET=generic
endif
endif

export MKDIR
export INSTALL
export INSTALL_PROG
Expand All @@ -68,13 +52,9 @@ INSTALL_PROG=$(INSTALL) -m755
INSTALL_DOC=$(INSTALL) -m644

# DESTDIR set in debian make system
PREFIX?=$(DESTDIR)/usr
ifeq ($(CONFIG_TARGET),darwin)
SBINDIR=$(PREFIX)/local/sbin
else
SBINDIR=$(PREFIX)/sbin
endif
PREFIX?=$(DESTDIR)/$(CONFIG_PREFIX)

SBINDIR=$(PREFIX)/sbin
MANDIR?=$(PREFIX)/share/man
MAN1DIR=$(MANDIR)/man1
MAN7DIR=$(MANDIR)/man7
Expand Down Expand Up @@ -158,32 +138,26 @@ LINT_CCODE=\
tools/tests-transform.c \
tools/tests-wire.c \


LDLIBS+=-ln2n
LDLIBS+=$(LDLIBS_EXTRA)

#For OpenSolaris (Solaris too?)
ifeq ($(CONFIG_TARGET), sunos)
LDLIBS+=-lsocket -lnsl
ifneq (,$(findstring mingw,$(CONFIG_HOST_OS)))
LDLIBS+=$(abspath win32/n2n_win32.a)
endif
LDLIBS+=$(LDLIBS_EXTRA)

ifeq ($(CONFIG_TARGET),mingw)
CFLAGS+=-I. -I./win32
LDLIBS+=$(abspath win32/n2n_win32.a)
LDLIBS+=-lnetapi32 -lws2_32 -liphlpapi
ifneq (,$(findstring mingw,$(CONFIG_HOST_OS)))
N2N_DEPS+=win32/n2n_win32.a
SUBDIRS+=win32
endif

APPS=edge
APPS+=supernode
APPS+=example_edge_embed_quick_edge_init
APPS+=example_edge_embed
APPS+=example_sn_embed
APPS=edge$(EXE)
APPS+=supernode$(EXE)
APPS+=example_edge_embed_quick_edge_init$(EXE)
APPS+=example_edge_embed$(EXE)
APPS+=example_sn_embed$(EXE)

DOCS=edge.8.gz supernode.1.gz n2n.7.gz

# This is the superset of all packages that might be needed during the build.
# This is the list of Debian/Ubuntu packages that are needed during the build.
# Mostly of use in automated build systems.
BUILD_DEP:=\
autoconf \
Expand Down Expand Up @@ -233,8 +207,13 @@ src/example_edge_embed_quick_edge_init: $(N2N_LIB)
src/example_sn_embed: $(N2N_LIB)
src/example_edge_embed: $(N2N_LIB)

ifeq ($(CONFIG_TARGET), mingw)
ifneq (,$(findstring mingw,$(CONFIG_HOST_OS)))
src/edge: win32/edge_rc.o
src/edge.exe: src/edge
src/supernode.exe: src/supernode
src/example_edge_embed_quick_edge_init.exe: src/example_edge_embed_quick_edge_init
src/example_sn_embed.exe: src/example_sn_embed
src/example_edge_embed.exe: src/example_edge_embed
endif

%: src/%
Expand Down Expand Up @@ -293,15 +272,21 @@ gcov:

# This is a convinent target to use during development or from a CI/CD system
.PHONY: build-dep
build-dep:
ifeq ($(CONFIG_TARGET),generic)
sudo apt install $(BUILD_DEP)
else ifeq ($(CONFIG_TARGET),darwin)
brew install automake gcovr

ifneq (,$(findstring darwin,$(CONFIG_HOST_OS)))
build-dep: build-dep-brew
else
echo Not attempting to install dependancies for system $(CONFIG_TARGET)
build-dep: build-dep-dpkg
endif

.PHONY: build-dep-dpkg
build-dep-dpkg:
sudo apt install $(BUILD_DEP)

.PHONY: build-dep-brew
build-dep-brew:
brew install automake gcovr

.PHONY: clean
clean:
rm -f src/edge.o src/supernode.o src/example_edge_embed.o src/example_edge_embed_quick_edge_init.o src/example_sn_embed.o
Expand All @@ -321,11 +306,11 @@ distclean:
rm -f $(addprefix src/,$(APPS))

.PHONY: install
install: edge supernode edge.8.gz supernode.1.gz n2n.7.gz
install: edge$(EXE) supernode$(EXE) edge.8.gz supernode.1.gz n2n.7.gz
echo "MANDIR=$(MANDIR)"
$(MKDIR) $(SBINDIR) $(MAN1DIR) $(MAN7DIR) $(MAN8DIR)
$(INSTALL_PROG) supernode $(SBINDIR)/
$(INSTALL_PROG) edge $(SBINDIR)/
$(INSTALL_PROG) supernode$(EXE) $(SBINDIR)/
$(INSTALL_PROG) edge$(EXE) $(SBINDIR)/
$(INSTALL_DOC) edge.8.gz $(MAN8DIR)/
$(INSTALL_DOC) supernode.1.gz $(MAN1DIR)/
$(INSTALL_DOC) n2n.7.gz $(MAN7DIR)/
Expand Down
6 changes: 6 additions & 0 deletions config.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
# @configure_input@

CONFIG_HOST=@host@
CONFIG_HOST_OS=@host_os@
CONFIG_PREFIX=@prefix@

PACKAGE_VERSION=@PACKAGE_VERSION@

CC=@CC@
AR=@AR@
WINDRES=@WINDRES@
EXE=@EXE@

CFLAGS=@CFLAGS@
LDFLAGS=@LDFLAGS@
LDLIBS_EXTRA=@LIBS@
28 changes: 28 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ AC_PROG_CC
AC_CHECK_TOOL([AR], [ar], [false])
AC_CHECK_TOOL([WINDRES], [windres], [windres])

case "$host_os" in
solaris*)
# Was in Makefile with the test `uname` -eq "SunOS"
# and comment "For OpenSolaris (Solaris too?)"
LIBS="-lsocket -lnsl $LIBS"
;;
mingw*)
LIBS="-lnetapi32 -lws2_32 -liphlpapi $LIBS"
EXE=".exe"
;;
*)
EXE=""
;;
esac

# This replicates the old config logic from the Makefile.
# TODO: remove all this and just use the autotools default prefix
# (which is "/usr/local")
case "$host_os" in
darwin*)
;;
*)
AC_PREFIX_DEFAULT(/usr)
;;
esac

# TODO: ideally, should use AC_ARG_ENABLE
AC_ARG_WITH([edgex],
AS_HELP_STRING([--with-edgex], [Build for Ubiquity-X]),
Expand Down Expand Up @@ -91,6 +117,8 @@ AS_IF([test "x$enable_pthread" != xno],


AC_SUBST(host)
AC_SUBST(host_os)
AC_SUBST(EXE)
AC_SUBST(WINDRES)
AC_CONFIG_HEADERS(include/config.h)
AC_CONFIG_FILES(config.mak)
Expand Down
1 change: 0 additions & 1 deletion include/n2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
#include <lmapibuf.h> /* for privilege check in tools/n2n-route */
#include <sys/stat.h>
#include <windows.h> /* for privilege check in tools/n2n-route */
#include "wintap.h"
#define SHUT_RDWR SD_BOTH /* for tcp */
#endif /* #ifdef _WIN32 */

Expand Down
4 changes: 2 additions & 2 deletions include/n2n_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ typedef int ssize_t;

typedef unsigned long in_addr_t;

#include "n2n_win32.h"
// FIXME - the above include is from a different subdir
#include "../win32/n2n_win32.h"
// FIXME - continue untangling the build and includes - dont have a ".." here

#endif /* #if defined(_MSC_VER) || defined(__MINGW32__) */

Expand Down
6 changes: 2 additions & 4 deletions include/n2n_wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
#include <stdint.h>
#endif

#ifdef _WIN32
#include "n2n_win32.h"
#else /* #ifdef _WIN32 */
#ifndef _WIN32
#include <netinet/in.h>
#include <sys/socket.h> /* AF_INET and AF_INET6 */
#endif /* #ifdef _WIN32 */
#endif /* #ifndef _WIN32 */

#include "sn_selection.h"

Expand Down
5 changes: 4 additions & 1 deletion scripts/hack_fakeautoconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ chmod a+x configure

cat >config.mak <<EOF
CONFIG_HOST=x86_64-w64-mingw32
CONFIG_HOST_OS=mingw32
CONFIG_PREFIX=/usr/local

CC=gcc
AR=ar
WINDRES=windres
CFLAGS=$CFLAGS -g -O2
LDFLAGS=$LDFLAGS
LDLIBS_EXTRA=$LDLIBS
LDLIBS_EXTRA=-lnetapi32 -lws2_32 -liphlpapi
EOF

cat <<EOF >include/config.h
Expand Down
32 changes: 27 additions & 5 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@ DEBUG?=-g3
HEADERS=$(wildcard include/*.h)
CFLAGS+=-I../include

ifeq ($(CONFIG_TARGET),mingw)
ifneq (,$(findstring mingw,$(CONFIG_HOST_OS)))
CFLAGS+=-I../win32
endif
CFLAGS+=$(DEBUG)
LDFLAGS+=-L..

N2N_LIB=../libn2n.a

TOOLS=n2n-benchmark n2n-keygen n2n-route n2n-portfwd n2n-decode
TOOLS+=n2n-benchmark$(EXE)
TOOLS+=n2n-keygen$(EXE)
TOOLS+=n2n-route$(EXE)
TOOLS+=n2n-portfwd$(EXE)
TOOLS+=n2n-decode$(EXE)

TESTS=tests-compress tests-elliptic tests-hashing tests-transform
TESTS+=tests-wire
TESTS+=tests-auth
TESTS=tests-compress$(EXE)
TESTS+=tests-elliptic$(EXE)
TESTS+=tests-hashing$(EXE)
TESTS+=tests-transform$(EXE)
TESTS+=tests-wire$(EXE)
TESTS+=tests-auth$(EXE)

.PHONY: all clean install
all: $(TOOLS) $(TESTS)
Expand All @@ -30,6 +37,21 @@ n2n-route.o: $(N2N_LIB) $(HEADERS) ../config.mak
n2n-portfwd.o: $(N2N_LIB) $(HEADERS) ../config.mak
n2n-decode.o: $(N2N_LIB) $(HEADERS) ../config.mak

ifneq (,$(findstring mingw,$(CONFIG_HOST_OS)))
# HACK for windows.
n2n-benchmark.exe: n2n-benchmark
n2n-keygen.exe: n2n-keygen
n2n-route.exe: n2n-route
n2n-portfwd.exe: n2n-portfwd
n2n-decode.exe: n2n-decode
tests-compress.exe: tests-compress
tests-elliptic.exe: tests-elliptic
tests-hashing.exe: tests-hashing
tests-transform.exe: tests-transform
tests-wire.exe: tests-wire
tests-auth.exe: tests-auth
endif

# See comments in the topdir Makefile about how to generate coverage
# data.
gcov:
Expand Down