Skip to content

Instantly share code, notes, and snippets.

@tfwio
Last active August 29, 2015 14:07
Show Gist options
  • Save tfwio/998ae63b68d94210ed8d to your computer and use it in GitHub Desktop.
Save tfwio/998ae63b68d94210ed8d to your computer and use it in GitHub Desktop.
a simple download script w/patches where useful for custom mingw-w64 builds using a "/mingw/x64_86-w64-mingw32" or "/mingw/i686-w64-mingw32" (symbolic link) junctioned as "/mingw/mingw32"

This is just a collection of notes and bash (or sh) scripting dedicated to setting up a custom build environment around a mingw-w32 or few. This would probably not be of any interest to any particular individual as compared to other much better team driven scripts and/or projects out there like github.com/Alexpux/MINGW-packages—which I encountered a short time after writing much of this script.

  • First we would do a git checkout ...
  • download the patch
  • apply the patch
  • make ; make install

After patching, a bash process might look something like:

# MISSING:
# -----------
# `function enforce_dir () # $1=pathname`
# `git_patch function () # url destination-file-name`
#- `$output_directory`, `$bin_directory`


if [[ ! -d "${output_directory}/glfw/" ]]; then
  echo Please run get glfw
  echo ...this will get the latest github snapshot.
  exit 1
fi
cd ${output_directory}/glfw/
git clean -dfx
git_patch "https://gist.githubusercontent.com/tfwio/998ae63b68d94210ed8d/raw/c306204ab8eba68bc7263d2f8d68f9ba8895a166/x86_64-w64-mingw32.cmake.diff" "x86_64-w64-mingw32.cmake.diff"
cmake -G "MSYS Makefiles" -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake -DCMAKE_INSTALL_PREFIX=${bin_path} .
enforce_dir docs/CMakeFiles/docs
enforce_dir docs/CMakeFiles/docs.dir
enforce_dir docs/CMakeFiles/docs.dir/all
make
make install
#/bin/bash setup-tools.sh
# It would eventually be significant to supply the tool-chain that we're working with.
# For example, we might inherit some options such as $PFIX
# Use of this script is not advisable
# ...check out https://github.com/Alexpux/MINGW-packages
#
PFIX=$PFIX
# http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
# tar -zxvf test123.tar.gz #z -- unzip #x -- extract the file #v -- verbose #f -- forcefully done
##echo
##for x in $@ ; do
## case "${x/=*}" in
## "--prefix" )
## echo "* Assign the output_directory to: \"${x/--prefix=/}\""
## ;;
## "help" ) echo "* LCASE \"$x\"" ;;
## "HELP" ) echo "* user specified \"$x\"" ;;
## *)
## echo "- $x (unhandled param) ${x/=*}"
## ;;
## esac
##done
# VARIABLES
#################################################
export initial_path=${PWD}
export package_directory="${initial_path}/packages"
export output_directory="${initial_path}/build"
export bin_path=${initial_path}/${PFIX}/bin
## arch_jsoncpp="json-cpp" "0.6.0-rc2" "tar" "https://github.com/open-source-parsers/jsoncpp/archive/svn-release-0.6.0-rc2.tar.gz"
## arch_scons= "scons-local" "1.2.0" "tar" "http://downloads.sourceforge.net/project/scons/scons-local/1.2.0/scons-local-1.2.0.tar.gz" "${output_directory}/jsoncpp-svn-release-0.6.0-rc2"
###############################################################################
## Libname is something like libfmodex.a (minus the '.a')
## Filename is something like fmodex64.dll
###############################################################################
function make_a_from_lib ()
{
filename=$1 ; libname=$2 ; shift 2
gendef "${filename}" # produces
dlltool -k --output-lib "${libname}" --def
}
###############################################################################
###############################################################################
###############################################################################
function enforce_dir() # CREATE Directory if it does not exist
{
echo creating directory: $1
if [[ ! -d $1 ]] ; then
mkdir "./$1"
fi
}
function unpack() # 1_type 2_package 3_override_directory
{
# parameters one and two are manditory
# parameter three is optional
echo we recieved $# parameters
case $# in
3) echo three parameters ;;
2) echo two parameters ;;
1) echo one parameter ;;
esac
if [[ ! -f "$2" ]] ; then
echo
echo "package $2 does not exist"
echo skipping
echo
exit 1
fi
if [[ ! -d "$3" ]] ; then
case $1 in
tar)
if [[ ! -z "$3" ]]; then
echo "Extracting $2" to $PWD
$1 -zxf "$2" -C $3
else
echo "Extracting $2" to $PWD
$1 -zxf "$2"
fi
;;
unzip)
if [[ ! -z "$3" ]]; then
echo "Extracting $2" to $PWD
$1 "$2" -d $3
else
echo "Extracting $2" to $PWD
unzip $2
fi
;;
7za)
echo "un7zipping $2" to $PWD
echo unzipping
7za e $2
;;
esac
else
echo "Skip extracting. Files present."
fi
}
function getnamefor ()
{
# this method exports the following variables
# dl sext sfnet
export dl=${1/\/download}
export sext=$(basename ${dl/*.tar.gz})
if [[ "$(basename $1)" == "download" ]] ; then export sfnet=true ; else export sfnet=false ; fi
}
function download_unpack() # 1 url 2 exported directory-name 3 tar|unzip 3 (optional) [path] | f 4 (prior arg was 'f') [path]
{
echo download_unpack...
echo --------------------
local url=$1
local nam=$(basename $url)
local path=$2
local tool=$3
local downloadfile
shift 3
local nin=$#
case $nin in
1 ) echo one more ;;
2 ) echo two more ;;
* ) echo no more input ;;
esac
echo Getting Name Info - Leftover = $nin
echo
getnamefor $url
if [[ ${nam} == "download" ]] ; then
nam=$(basename ${url/\/download})
fi
# check
if [[ "x$1" == "xf" ]] ; then
shift
local downloadfile=$1
fi
echo DOWNLOAD FILE = ${downloadfile}
echo DOWNLOAD NAME = ${nam}
echo DOWNLOAD PATH = ${path}
dir=$1
# download #
echo name: ${nam}, ext: ${tool}
cd "${package_directory}"
#echo exiting $nam ; exit 1
# tar -zxvf test123.tar.gz #z -- unzip #x -- extract the file #v -- verbose #f -- forcefully done
if [[ ! -f "$nam" ]]; then
# -L tells curl to follow the redirect.
# -O says to use the download's original download-file-name
if [[ ! -z "$downloadfile" ]]; then
# -o says to use filename specified.
curl -Lo $1 $url || exit 1
else
curl -LO $url || exit 1
fi
else
echo "File ${nam} exists --- skipping"
fi
#
# Extract Part
#################################################
cd ${output_directory}
#################################################
if [[ ! -z "$dir" ]]; then unpack ${tool} "${package_directory}/${nam}" "$dir"
elif [[ ! -z "$downloadfile" ]]; then unpack ${tool} "${package_directory}/${downloadfile}"
else unpack ${tool} "${package_directory}/${nam}"
fi
#
cd "${initial_path}"
unset nin
}
function enforcer ()
{
enforce_dir "${package_directory}"
enforce_dir "${output_directory}"
enforce_dir "${bin_path}"
}
function get_git_project () # 1=name 2=url
{
echo $1
echo ----------------------------------
echo
cd ${output_directory}
git clone $2
}
###############################################################################
###############################################################################
###############################################################################
function get_jsoncpp() {
jcd=jsoncpp-svn-release-0.6.0-rc2
download_unpack "https://github.com/open-source-parsers/jsoncpp/archive/svn-release-0.6.0-rc2.tar.gz" "jsoncpp-svn-release-0.6.0-rc2" tar
download_unpack "http://downloads.sourceforge.net/project/scons/scons-local/1.2.0/scons-local-1.2.0.tar.gz" "scons-local-1.2.0" tar "${output_directory}/jsoncpp-svn-release-0.6.0-rc2"
echo finished downloading jsoncpp
}
#
# JSONC
###########################################################
function get_jsonc()
{
echo get_jsonc
echo --------------------
download_unpack https://s3.amazonaws.com/json-c_releases/releases/json-c-0.10.tar.gz json-c-0.10 tar
}
function make_jsonc ()
{
cd ${output_directory}/jsoncpp-svn-release-0.6.0-rc2/
python scons.py platform=mingw
python amalgamate.py
}
#
# JANSSON
###########################################################
function get_jansson ()
{
local arch_jansson_v=2.7
local arch_jansson_x=tar.gz
local arch_jansson_n=jansson
local arch_jansson_fn=jansson-2.7
local arch_jansson_u=http://www.digip.org/jansson/releases
local arch_jansson=${arch_jansson_u}/${arch_jansson_fn}.${arch_jansson_x}
download_unpack "${arch_jansson}" "${arch_jansson_fn}" tar
## We first have to download
##if [[ -f ]]
# local CC=${PFIX}-gcc
## cd ${output_directory}/json-c-0.10
## ./configure --prefix=${bin_path}
## make
## make check
## make install
#unset CC
unset arch_jansson_v
unset arch_jansson_x
unset arch_jansson_n
unset arch_jansson_fn
unset arch_jansson_u
unset arch_jansson
}
function make_jansson ()
{
echo make jansson
echo ------------------------
#http://www.digip.org/jansson/releases/jansson-2.7.tar.gz
get_jansson
## We first have to download
##if [[ -f ]]
# local CC=${PFIX}-gcc
cd ${output_directory}/jansson-2.7
./configure --prefix=${bin_path}
make
make check
make install
}
#
# BOOST
###########################################################
function get_boost ()
{
export xnam=boost
export xver=1.56.0
export xext=tar.bz2
export xpat=${xnam}-${xver}
export xfil=${xpat}.${xext}
echo exported tar.bz2 should be ${xfil}
echo -------------------------------------------------
cd $package_directory
if [[ ! -f ${fpak} ]]; then
# -L tells curl to follow the redirect.
# -O says to use the download's original download-file-name
download_unpack "http://sourceforge.net/projects/boost/files/boost/1.56.0/boost_1_56_0.tar.gz/download" "${xfil}" tar f "${package_directory}/${xfil}"
fi
#cd ${output_directory}
#echo unpacking ${fname}
#tar -zxf "${fpak}"
unset xnam xver xext xpat xfil
}
function unpack_boost ()
{
export xnam=boost
export xver=1.56.0
export xext=tar.gz
export xpat=${xnam}-${xver}
export xfil=${xpat}.${xext}
## the name of the extracted directory
export xto=boost_1_56_0
cd ${output_directory}
echo unpacking ${fname}
tar -zxf "${package_directory}/${xfil}"
unset xnam xver xext xpat xfil
}
function help_boost ()
{
echo
echo "See the provded link or the following
BOOST_REGEX_MATCH_EXTRA
- http://boost.2283326.n4.nabble.com/How-to-compile-boost-regex-td2596250.html
BOOST_REGEX_RECURSIVE
- http://lists.boost.org/boost-users/2009/03/45884.php
- When compiling boost libraries (regex) you have to specificy BOOST_REGEX_RECURSIVE if you want to use that feature.
Alternatively, you might configure a call such as
- Note that the following options were copied from the provided link.
b2.exe
-sICU_PATH=... \
define=BOOST_REGEX_MATCH_EXTRA=1 \
define=BOOST_REGEX_RECURSIVE=1 \
toolset=gcc \
threading=multi \
python-debugging=on \
link=shared variant=debug --without-mpi"
}
#
# CURL
###########################################################
function get_curl ()
{
local curlv=7.38
local curlx=tar.gz
local curln=curl-${curlv}
local curlf=${curln}.${curlx}
local curlurl=http://curl.haxx.se/download/curl-7.38.0.tar.gz
download_unpack "${curlurl}" "${curln}" tar
unset curlv curlx curln curlf curlurl
}
#
# FAAD
###########################################################
function get_and_make_faad ()
{
# http://faac.cvs.sourceforge.net/viewvc/faac/faad2/
local fname=faad-2.0
local ftar=${fname}.tar.gz
local ftarget=${package_directory}/${ftar}
# extracted is 'faad2'
if [[ ! -f "${ftarget}" ]]; then
curl "http://faac.cvs.sourceforge.net/viewvc/faac/faad2/?view=tar" -o "${package_directory}/${ftar}"
else
echo file present -- skipping
fi
#
# make
#--------------------------------------------------------
cd ${output_directory}
echo unpacking ${fname}
tar -zxf "${package_directory}/${ftar}"
# extracted is 'faad2'
cd ${output_directory}/faad2
autoreconf -vif
./configure --prefix=${bin_path}
# ./bootstrap
# ./configure --prefix=${bin_path}
make
make install
unset fname ftar ftarget
}
function get_fmodex ()
{
download_unpack "http://www.fmod.org/download/fmodex/api/Win/fmodapi44446win-installer.exe" fmodapi44446win-installer tar
#download_unpack http://www.fmod.org/download/fmodex/api/Win/fmodapi44446win-installer.exe fmodapi44446win-installer 7za
# we want dlls first
# - /api/fmodex.dll
# - /api/fmodex64.dll
# - /api/fmodexL.dll
# - /api/fmodexL64.dll
# then of course the header files.
#
#
#
#
## First we want to download http://www.fmod.org/download/fmodstudio/api/Win/fmodstudioapi10503win-installer.exe
}
function make_glfw () {
if [[ ! -d "${output_directory}/glfw/" ]]; then echo Please run get glfw ; echo ...this will get the latest github snapshot. ; exit 1 ; fi
cd ${output_directory}/glfw/
git clean -dfx
git_patch "https://gist.githubusercontent.com/tfwio/998ae63b68d94210ed8d/raw/c306204ab8eba68bc7263d2f8d68f9ba8895a166/x86_64-w64-mingw32.cmake.diff" "x86_64-w64-mingw32.cmake.diff"
cmake -G "MSYS Makefiles" -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake -DCMAKE_INSTALL_PREFIX=${bin_path} .
enforce_dir docs/CMakeFiles/docs
enforce_dir docs/CMakeFiles/docs.dir
enforce_dir docs/CMakeFiles/docs.dir/all
make
make install
}
#
# ICU
###########################################################
function get_icu ()
{
echo getting icu4c 54.1
echo ----------------------------------
echo
local xnam=icu4c
local xver=54.1
local xext=tgz
local xpat=${xnam}-${xver}
local xfil=${xpat}.${xext}
if [[ ! -d "${output_directory}/icu/" ]] ; then
# icu4c54_1
download_unpack "http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.tgz" "icu4c-54_1-src" tar
fi
unset xnam xver xext xpat xfil
}
function make_icu ()
{
cd "${output_directory}/icu/source"
./configure --enable-static --prefix=${bin_path}
make
make install
}
#
# OPENFRAMEWORKS
###########################################################
function get_of ()
{
cd ${output_directory}
git clone https://github.com/openframeworks/openFrameworks
}
#
# PORTAUDIO
###########################################################
function get_portaudio ()
{
echo get portaudio
echo ------------------------
# this writes: "./build/portaudio"
download_unpack "http://alleg.sourceforge.net/files/dx9mgw.zip" dx9mgw unzip
if [[ ! -f "${package_directory}/pa_stable_v19_20140130.tgz" ]]; then
download_unpack "http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz" "portaudio-19-20140130" tar
fi
if [ ! -d "${output_directory}/portaudio-19" ]; then
mv ${output_directory}/portaudio ${output_directory}/portaudio-19
fi
}
function make_portaudio ()
{
echo make portaudio
echo ------------------------
if [[ -d "${output_directory}/portaudio-19" ]]; then
echo
echo "Directory exists: {output_directory}/portaudio-19/\""
else
echo " Directory not found." && exit 1
fi
cd ${output_directory}/portaudio-19
./configure --prefix=${bin_path} --with-winapi=directx,wmme --with-dxdir=${output_directory}/dx9mgw
make
make install
cd ${initial_path}
}
#
# XML2
###########################################################
function get_xml2 ()
{
#output-directory:libxml2-2.9.0
# local PACKAGEDIR="${package_directory}/libxml2-2.9.0"
if [[ ! -f "${package_directory}/libxml2-sources-2.9.0.tar.gz" ]] ; then
download_unpack "ftp://xmlsoft.org/libxml2/libxml2-sources-2.9.0.tar.gz" "libxml2-2.9.0" tar
else
echo the directory exists --- no need to unpack.
fi
}
function make_xml2 ()
{
local PACKAGEDIR=${output_directory}/libxml2-2.9.0
cd "${PACKAGEDIR}"
if [[ -d "${PACKAGEDIR}" ]] ; then
./configure --prefix=${bin_path}
#make -f Makefile.mingw
#make -f Makefile.mingw install
fi
unset PACKAGEDIR
}
#
#
#function get_mp ()
#{
#}
function make_mp ()
{
local PACKAGEDIR=${output_directory}/$1
cd ${PACKAGEDIR}
make clean
make $2
}
###############################################################################
# NOTE
# We should check if we have a build and package-directory.
###############################################################################
function test_targets ()
{
vars=${@}
echo this is a test...
echo "(calculated) targets are..."
while [[ ! -z "$1" ]]; do
echo "- $1" ; shift
done
}
function git_patch ()
{
local patch_url=$1
local patch_file=$2
if [[ -f "${patch_file}" ]]; then rm -f "${patch_file}" ; fi
echo executing curl...
echo curl "${patch_url}" -o "${patch_file}"
echo -------------------------------------------
curl "${patch_url}" -o "${patch_file}"
git apply "${patch_file}"
unset patch_url patch_file
}
function get_make ()
{
if [[ $# == 2 ]] ; then
echo `${1}_${2}`
fi
}
function print_help ()
{
<<EOF
--------------------------------------------------------
The option labeled tar is just means that this is an
extraction method. It *may* apply to tar unzip 7z
and git extracts.
MinGW-w64 takes the complication out of providing
several dev-packs. This just makes up for some of
the things I thought I might play with.
get tar make help
========================================================
name g t m h
========================================================
assimp | x | | | Asset Import Library - various 3D mesh formats
boost |x|x|x|x| Boost Frameworks
cinder |x| | | | no support
faad | x | | FAAD - Advanced Audio Decoder
glfw | x |x| |
icu | x |x| | ICU4C
of | x | | | OpenFrameworks -- notcurrently supported by mingw.
jansson | x | | |
jsoncpp | x |x| |
portaudio | x |x| |
mp | | TODO:libModplug
xml2 | x |x| | libXml2
xerces | x |x| | TODO:The xml lib that wishes it were Persian?
========================================================
so what we have are sets of cmmands such as:
--------------------------------------------------------
setup-tools.sh help boost
setup-tools.sh get boost
setup-tools.sh tar boost
setup-tools.sh get portaudio
setup-tools.sh make portaudio
========================================================
EOF
}
###############################################################################
# IT STARTS!
# There are three basic commands built in:
###############################################################################
function get_options ()
{
case $1 in
getmake ) get_options get $2 ; get_options make $2 ;;
"faad") get_and_make_faad ;;
"get") enforcer ; echo "GETTING: $2"
case $2 in
"7z" ) download_unpack "https://drive.google.com/uc?export=download&id=0B3zU6tYfj4ZHSE5kNm5kLVNXUVk" 7z.zip unzip f "${package_directory}/7z.zip" ;;
"assimp" ) get_git_project "Asset Import Library (assimp)" "https://github.com/assimp/assimp" ;;
"boost" ) echo "boost is to be done in 3 steps" ; echo "This is Step #1" ; get_boost ; echo "#2 next, you can \"tar boost\" to unpack" ; echo "#3 Then you can \"make boost\"" ;;
"cinder" ) get_git_project "Cinder" "https://github.com/cinder/Cinder" ;;
"fmodex" ) get_fmodex ;;
"glfw" ) get_git_project "GLFW Snapshot" https://github.com/glfw/glfw ;;
"icu" ) get_icu ;;
"jsonc" ) get_jsonc ;;
"jsoncpp" ) get_jsoncpp ;;
"of" ) get_git_project "OpenFrameworks Snapshot" https://github.com/openframeworks/openFrameworks ;;
"portaudio" ) get_portaudio ;;
"mp" ) download_unpack "http://sourceforge.net/projects/modplug-xmms/files/libmodplug/0.8.8.5/libmodplug-0.8.8.5.tar.gz/download" "libmodplug-0.8.8.5.tar.gz" tar f "${package_directory}/libmodplug-0.8.8.5.tar.gz" ;;
"xml2" ) get_xml2 ;;
"st-dev" ) download_unpack http://sourceforge.net/p/soundtouch/code/HEAD/tarball?path=/trunk soundtouch-trunk.tar.gz tar ;;
soundtouch ) download_unpack http://www.surina.net/soundtouch/soundtouch-1.8.0.tar.gz soundtouch-1.8.0 tar ;;
* ) echo no option to provide response to. ;;
# Xerces
esac
;;
"make") enforcer ; echo $2
case $2 in
"glfw" ) make_glfw ;;
"jsonc" ) make_jsonc ;;
"jsoncpp" ) cd ${output_directory}/json-c-0.10 ; ./configure --prefix=${bin_path} ; make ; make check ; make install ;;
"jansson" ) make_jansson ;;
"portaudio" ) make_portaudio ;;
"mp" ) make_mp "libmodplug-0.8.8.5.tar" ;;
"xml2" ) make_xml2 ;;
soundtouch )
cd ${output_directory}/soundtouch
./bootstrap --clean ; ./bootstrap ; ./configure --help
echo ; echo
./configure --prefix=${bin_path}
echo we haven\'t defined rules yet to make soundtouch.
;;
* ) echo no option to provide response to. ;;
esac
;;
"tar")
case $2 in
"boost" ) unpack_boost ;;
* ) echo no option to provide response to. ;;
esac
;;
"help")
case $2 in
"boost" ) help_boost ;;
* ) print_help ;;
esac
;;
* ) print_help ;;
esac
}
# This is a test
export maketargets="jsoncpp jsonc something_else"
# header
#####################################################
CAT <<EOF
This script is for mingw32-w64 and mingw32-w64_86 4.8.x series
-----------------------------------------
EOF
get_options $*
echo we found $# options
#### 'help'
#### -------------------------------------
###if [[ $1 == ohcrap ]]; then
### VARX=$(echo $PATH | tr ":" "\n")
### export foundem=false
### for i in $VARX ; do
### echo "--$i"
### if [[ -f "$i/cmake.exe" ]] ; then
### foundem=true
### fi
### done
###
### echo found=$foundem
###
### test_targets $maketargets
### #cd ${output_directory}/jsoncpp-svn-release-0.6.0-rc2/
### #python scons.py platform=mingw-w32
### #python amalgamate.py
### cd
###fi
CMake/x86_64-w64-mingw32.cmake | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/CMake/x86_64-w64-mingw32.cmake b/CMake/x86_64-w64-mingw32.cmake
index 84b2c70..43de1ca 100644
--- a/CMake/x86_64-w64-mingw32.cmake
+++ b/CMake/x86_64-w64-mingw32.cmake
@@ -1,13 +1,14 @@
# Define the environment for cross compiling from Linux to Win32
SET(CMAKE_SYSTEM_NAME Windows) # Target system name
SET(CMAKE_SYSTEM_VERSION 1)
-SET(CMAKE_C_COMPILER "x86_64-w64-mingw32-gcc")
-SET(CMAKE_CXX_COMPILER "x86_64-w64-mingw32-g++")
-SET(CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres")
-SET(CMAKE_RANLIB "x86_64-w64-mingw32-ranlib")
+SET(CMAKE_C_COMPILER "gcc")
+SET(CMAKE_CXX_COMPILER "g++")
+SET(CMAKE_RC_COMPILER "windres")
+SET(CMAKE_RANLIB "ranlib")
+SET(CMAKE_AR "ar")
# Configure the behaviour of the find commands
-SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32")
+SET(CMAKE_FIND_ROOT_PATH "/mingw/mingw32")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment