Skip to content

Commit

Permalink
Merge pull request #153 from xerial/docker-win
Browse files Browse the repository at this point in the history
Build windows librariles with docker cross compiler image
  • Loading branch information
xerial authored Sep 23, 2016
2 parents 0230efd + 5707004 commit 4821a1d
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ $(NATIVE_DLL): $(SQLITE_OUT)/$(LIBNAME)
cp $< $(NATIVE_TARGET_DIR)/$(LIBNAME)

# for cross-compilation on Ubuntu, install the g++-mingw-w64-i686 package
win32:
$(MAKE) native CROSS_PREFIX=i686-w64-mingw32- OS_NAME=Windows OS_ARCH=x86
win32: $(SQLITE_UNPACKED) jni-header
./docker/dockcross-windows-x86 bash -c 'make native CROSS_PREFIX=i686-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86'

# for cross-compilation on Ubuntu, install the g++-mingw-w64-x86-64 package
win64:
$(MAKE) native CROSS_PREFIX=x86_64-w64-mingw32- OS_NAME=Windows OS_ARCH=x86_64
win64: $(SQLITE_UNPACKED) jni-header
./docker/dockcross-windows-x64 bash -c 'make native CROSS_PREFIX=x86_64-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86_64'

linux32:
$(MAKE) native OS_NAME=Linux OS_ARCH=x86
Expand Down
8 changes: 4 additions & 4 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ Mac-x86_64_LINKFLAGS := -dynamiclib
Mac-x86_64_LIBNAME := libsqlitejdbc.jnilib
Mac-x86_64_SQLITE_FLAGS :=

Windows-x86_CC := i686-w64-mingw32-gcc
Windows-x86_STRIP := i686-w64-mingw32-strip
Windows-x86_CC := $(CROSS_PREFIX)gcc
Windows-x86_STRIP := $(CROSS_PREFIX)strip
Windows-x86_CCFLAGS := -D_JNI_IMPLEMENTATION_ -Ilib/inc_win -O2
Windows-x86_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
Windows-x86_LIBNAME := sqlitejdbc.dll
Windows-x86_SQLITE_FLAGS :=

Windows-x86_64_CC := x86_64-w64-mingw32-gcc
Windows-x86_64_STRIP := x86_64-w64-mingw32-strip
Windows-x86_64_CC := $(CROSS_PREFIX)gcc
Windows-x86_64_STRIP := $(CROSS_PREFIX)strip
Windows-x86_64_CCFLAGS := -D_JNI_IMPLEMENTATION_ -Ilib/inc_win -O2
Windows-x86_64_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
Windows-x86_64_LIBNAME := sqlitejdbc.dll
Expand Down
200 changes: 200 additions & 0 deletions docker/dockcross-windows-x64
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#!/bin/bash

DEFAULT_DOCKCROSS_IMAGE=dockcross/windows-x64

#------------------------------------------------------------------------------
# Helpers
#
err() {
echo -e >&2 ERROR: $@\\n
}

die() {
err $@
exit 1
}

has() {
# eg. has command update
local kind=$1
local name=$2

type -t $kind:$name | grep -q function
}

#------------------------------------------------------------------------------
# Command handlers
#
command:update-image() {
docker pull $FINAL_IMAGE
}

help:update-image() {
echo Pull the latest $FINAL_IMAGE .
}

command:update-script() {
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
echo $0 is up to date
else
echo -n Updating $0 '... '
docker run $FINAL_IMAGE > $0 && echo ok
fi
}

help:update-image() {
echo Update $0 from $FINAL_IMAGE .
}

command:update() {
command:update-image
command:update-script
}

help:update() {
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
}

command:help() {
if [[ $# != 0 ]]; then
if ! has command $1; then
err \"$1\" is not an dockcross command
command:help
elif ! has help $1; then
err No help found for \"$1\"
else
help:$1
fi
else
cat >&2 <<ENDHELP
Usage: dockcross [options] [--] command [args]
By default, run the given *command* in an dockcross Docker container.
The *options* can be one of:
--args|-a Extra args to the *docker run* command
--image|-i Docker cross-compiler image to use
--config|-c Bash script to source before running this script
Additionally, there are special update commands:
update-image
update-script
update
For update command help use: $0 help <command>
ENDHELP
exit 1
fi
}

#------------------------------------------------------------------------------
# Option processing
#
special_update_command=''
while [[ $# != 0 ]]; do
case $1 in

--)
break
;;

--args|-a)
ARG_ARGS="$2"
shift 2
;;

--config|-c)
ARG_CONFIG="$2"
shift 2
;;

--image|-i)
ARG_IMAGE="$2"
shift 2
;;
update|update-image|update-script)
special_update_command=$1
break
;;
-*)
err Unknown option \"$1\"
command:help
exit
;;

*)
break
;;

esac
done

# The precedence for options is:
# 1. command-line arguments
# 2. environment variables
# 3. defaults

# Source the config file if it exists
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}

[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"

# Set the docker image
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}

# Handle special update command
if [ "$special_update_command" != "" ]; then
case $special_update_command in

update)
command:update
exit $?
;;

update-image)
command:update-image
exit $?
;;

update-script)
command:update-script
exit $?
;;

esac
fi

# Set the docker run extra args (if any)
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}

# If we are not running via boot2docker
if [ -z $DOCKER_HOST ]; then
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
fi

#------------------------------------------------------------------------------
# Now, finally, run the command in a container
#
docker run --rm \
-v $PWD:/work \
$USER_IDS \
$FINAL_ARGS \
$FINAL_IMAGE "$@"

################################################################################
#
# This image is not intended to be run manually.
#
# To create a dockcross helper script for the
# dockcross/linux-armv7 image, run:
#
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
# chmod +x dockcross-linux-armv7
#
# You may then wish to move the dockcross script to your PATH.
#
################################################################################
Loading

0 comments on commit 4821a1d

Please sign in to comment.