Skip to content

Build MinGW with OSX

Cecil Coupe edited this page Jun 20, 2018 · 16 revisions

I'm using OracleBox on a Mac Mini but you could do in anything that has a VM capability. I'm not going to discuss how to set up the VM in any detail

Install Mint 18.3 Xfce 64 in VM

It's an Ubuntu Xenial based distro because I like apt-get and synaptic and Xfce because I don't like Unity or Gnome desktops.

  1. Install Guest Additions
  2. reboot

Install updates and synaptic if your like it.

  1. software updater
  2. reboot

install packages

  • build-essential
  • libgtk-3-dev
  • libyaml-dev
  • librsvg2-dev
  • libjpeg-dev
  • libgif-dev
  • git

Where to put things?

git clone or network mount

Network Mount

  1. mkdir ~/Projects
  2. sudo apt-get install nfs-common
  3. sudo mount -t nfs 192.168.1.2:/Projects /home/ccoupe/Projects
  4. Test
  5. modify /etc/fstab 192.168.1.2:/Projects /home/ccoupe/Projects nfs auto,noatime,nolock,bg,intr ,tcp,actimeo=1800 0 0
  6. reboot and test

Build ruby 2.3.7 from source.

Download Missing libraries

     apt-get install libgdbm-dev, libssl-dev, libreadline-dev libcurl4-openssl-dev
   mkdir ~/src; cd ~/src
    mv ../Downloads/ruby-2.3.7.tar.gz .
   tar xf ruby-2.3.7.tar.gz
   cd ruby-2.3.7
   ./configure --enable-shared --enable-load-relative --disable-install-doc
   make
   sudo make install

Close terminal. Open new terminal to get updates to $PATH

$ which ruby
/usr/local/bin/ruby
$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-linux]

Update gems

get the latest Ruby gems, untar it (in src)

mv Downloads/rubygems-2.7.7.tgz src/
cd src
tar xf rubygems-2.7.7.tgz
cd rubygems-2.7.7 
$ sudo ruby setup.rb --no-document
$ gem -v
2.7.7

Get Shoes

There are two ways to move forward. The first method applies to using a NFS mount which has the Shoes source and prebuilt gems. The second method doesn't use a network drive.

For networks:

$ cd Projects/shoes3
ccoupe@mintvm ~/Projects/shoes3 $ rake -T
mkdir -p minlin
rake bsd:setup:freebsd     # freebsd 11.1 x86_64
rake bsd:setup:minbsd      # freebsd minimal
rake build                 # Build using your OS setup
rake clean                 # Remove any temporary products
rake clobber               # Remove any generated file
rake default               # Same as `rake build'
rake install               # Not Recommended! Install min Shoes in your ~/....
rake linux:setup:lin64     # chroot build for x86_64 (64bit linux)
rake linux:setup:minlin    # build non-portable linux
rake linux:setup:rpi       # Native Raspberry Pi build - 2+
rake linux:setup:xwin7     # Cross compile with  MingW32
rake osx:setup:xmavericks  # Setup to build Shoes for 10.9+ from 10.10+
rake osx:setup:yosemite    # Setup to build Shoes for 10.10+ from 10.10
rake package               # Package Shoes for distribution
rake version               # create VERSION.txt
rake win32:setup:msys2     # Windows build with msys2
rake win32:setup:win7      # Winodws build with devkit
ccoupe@mintvm ~/Projects/shoes3 $ 

Good enough for now. Shoes wants some gems installed in that Ruby before we can build Shoes or we can point to a location that has the gems already compiled for us. We tell the Shoes build where things are with a custom.yaml - since we want to build the lin64 target we need a lin64-custom.yaml

$ more lin64-custom.yaml 
Ruby: /usr/local
Deps: 
Gemloc: /home/ccoupe/Projects/gems/rb23
Extloc: /home/ccoupe/Projects/gems/rb23
Exts:
Gems:
InclGems: 
  - chipmunk-6.1.3.4
  - sqlite3-1.3.13
  - mini_portile2-2.2.0
  - nokogiri-1.8.0
  - rb-readline-0.5.4
  - byebug-9.0.6
  - ffi-1.9.18
    # picky needs:
  - activesupport-5.1.2
  - concurrent-ruby-1.0.5
  - i18n-0.8.6
  - multi_json-1.12.1
  - picky-4.31.3
  - rack_fast_escape-2009.06.24
  - thread_safe-0.3.6
  - tzinfo-1.2.3
  - url_escape-2009.06.24
  - yajl-ruby-1.3.0
  # typhoeus
  - ethon-0.10.1
  - typhoeus-1.1.2
Debug: false
Deprecations: false

Notice how the yaml tells the Rakefile where ruby is (/usr/local/) and where the gems are and what version numbers of the gem to use. You can get a copy

No network drive

$ sudo gem install --no-doc

Build Shoes and test

rake lin64-custom-yaml

  1. Cross Compile Shoes for Windows

outdated instructions:

I picked Debian because the UI is simple, old school and we don't want to fight GUI's just to get a couple of command line terminals. I prefer apt to other package managers.

We'll start with getting a Debian netinst iso. Download The 7.8 64 bit..

Create a 64 bit VM and Mount the .iso in the VM manager so the new VM will boot from the iso. Go through the delightful old time installer. It even knows its in a VM! It does take some time to download but we the time to plan the next steps. We'll probably have to remove the dvd (iso) and reboot. Then we'll have login, find a terminal, find a webrowser and check that we are communicating. I'll want to change the VM screen size to be a bit larger. Sounds simple. It was. I chose to only allocated 128MB to the video system which isn't enough for the fancy gnome3 system to run so I got the fallback GUI. Yay!

We have gcc-4.7.2.5. We don't have sudo but we do have su

  • enable sudo -- google for instruction

Lets get a Ruby

  • sudo apt-get install git
  • sudo apt-get install build-essentials
  • sudo apt-get install ruby # this got me 1.9.3
  • sudo apt-get install curl # because rvm says to
  • Install rvm Follow these instructions. You'll have to deal with .bashrc/.profile mess yourself

Tight Shoes

  • rvm install 2.1.5 -C --enable-load-relative --enable-shared
  • rvm use 2.1.5 --default
  • sudo apt-get install libgtk2.0-dev libungif4-dev libjpeg8-dev
  • git clone https://github.com/Shoes3/shoes3.git
  • cd shoes3
  • rake
  • test with dist/shoes``

Now you have Loose Shoes. You can run from ~/shoes3/dist/shoes or you could install it into the menu with a 'rake install'. I had to log out and back in for Shoes to show in the Programming menu (debian)

Cross Compile

Now we want to setup for Tight Shoes - a Shoes you can distribute. In this example we want to go more extreme we want to build for Windows, not Linux. We have several tasks ahead. We'll need to cross compile Ruby and before we do that we have to cross compile some libraries that Ruby wants. Then we have to get the Shoes dependent libs (gtk2, gif, jpeg) built for Windows and finally we can build Shoes for Windows. Don't despair. It's not that hard.

Let's get the gcc cross compiler.

sudo apt-get install gcc-mingw-w64-i686 That's gcc 4.6.3 - we might need to know that.

Set up the cross building directories

We need a directory that the mingw compiler and the Shoes rakefiles can use to find all the stuff that might be in Linux /usr. Places like /usr/bin and /usr/include and /usr/lib. Only we don't it to be /usr because that's what we are running on and is write protected from us stuffing mingw libs in a running Linux system.

mkdir -p /home/ccoupe/shoesdeps/mingw

I strongly suggest you use the gtk+-bundle_2.24.10-20120208_win32.zip from gnome or my copy.. Download it, move it into that shoesdeps/mingw directory and unzip it. It should look like

ccoupe@d78:~/shoesdeps/mingw$ ls
bin  gtk+-bundle_2.24.10-20120208_win32.README.txt  include  man       share
etc  gtk+-bundle_2.24.10-20120208_win32.zip         lib      manifest  src

There's all the bin, lib, and soon. Windows style (.dll's are in bin/, for example).

We also need a directory to download all the source code libraries to and then when we build them, they'll get installed to the --/prefix. We are going to use that src directory.

mkdir -p /home/ccoupe/deps-src cd /home/ccoupe/deps-src

Get Source code

What do we need? Ruby 2.1.5 - we want to compile it for Windows. The build process for Ruby will check for certain libraries and if they don't exist it will leave that feature out of the new Ruby. For example Tk wouldn't make sense for Shoes whereas yaml is important for Shoes. You can find the source on the web. For convenience, I've put up copies you can download. You should download the *cfg.sh files to see what is needed even if you decide to get your source code from somewhere else. If you value your time, you will want to get the gdbm-1.8.3.patched.bin.tgz. I recommend you just grab it all because we know it works.

You'll have to move the download files into the deps-src directory. Mine looks like:

ccoupe@d78:~/deps-src$ ls
cjc-ffi-cfg.sh      cjc-yaml-cfg.sh             openssl-1.0.2.tar.gz
cjc-gdbm-cfg.sh     gdbm-1.8.3.patched.bin.tgz  patch-gdbm-1.8.3
cjc-iconv-cfg.sh    gdbm-1.8.3.tar.gz           ruby-2.1.5.tar.gz
cjc-openssl-cfg.sh  libffi-3.0.9.tar.gz         yaml-0.1.4.tar.gz
cjc-ruby-2.1.4.sh   libiconv-1.14.tar.gz

Now we have to unzip one, modify the cfg.sh , run it, and then make; make install. Ruby will be last. I'll show one example, ffi.

ccoupe@d78:~$ cd deps-src/
ccoupe@d78:~/deps-src$ tar zxf libffi-3.0.9.tar.gz 
ccoupe@d78:~/deps-src$ cd libffi-3.0.9/
ccoupe@d78:~/deps-src/libffi-3.0.9$ vi ../cjc-ffi-cfg.sh

Of course you can use pico or any other text editor that you like (or tolerate). The script is pretty simple.

#! /bin/bash
# copy this to the ruby dir or soft link it.
# execute it instead of ./configure
export CC=i686-w64-mingw32-gcc
export CPPFLAGS="-I/srv/chroot/mingwgtk2/include"
export LDFLAGS="-L/srv/chroot/mingwgtk2/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=i686-w64-mingw32 \
  --prefix="/srv/chroot/mingwgtk2"

We need to set CPPFLAGS and LDFLAGS and we need to change that --prefix line to point to where things are. Do not fool with the --build and --host unless you know enough that you're not even reading this. It's important to use absolute paths. no .. or ~.

I modified to look like

#! /bin/bash
# copy this to the ruby dir or soft link it.
# execute it instead of ./configure
export CC=i686-w64-mingw32-gcc
export CPPFLAGS="-I/home/ccoupe/shoesdeps/mingw/include"
export LDFLAGS="-L/home/ccoupe/shoesdeps/mingw/lib"
./configure \
  --build=x86_64-linux-gnu \
  --host=i686-w64-mingw32 \
  --prefix="/home/ccoupe/shoesdeps/mingw"

Lets run the configure and see what happens.

ccoupe@d78:~/deps-src/libffi-3.0.9$ chmod +x ../cjc-ffi-cfg.sh 
ccoupe@d78:~/deps-src/libffi-3.0.9$ ../cjc-ffi-cfg.sh 

There will be an error message if it fails and a long list of checks. Look for checking whether the C compiler works... yes That means build and host are setup properly. now its just a make. If it seems OK, try make install. Look for the line

Libraries have been installed in:
   /home/ccoupe/shoesdeps/mingw/lib

NOTE: any tests will fail (because we aren't running the test in Windows). Carry on. Do a check if your are unsure.

ls -ld /home/ccoupe/shoesdeps/mingw/lib/libffi*
ls -ld /home/ccoupe/shoesdeps/mingw/bin/libffi-5.dll

Now, we just repeat the process for all the other Ruby dependencies. Except for Ruby. Make sure you use the gdbm-patched.tgz and you should make clean in it before configuring.

You might notice that a lot of the *-cfg.sh are almost identical and you could write a master shell script to do them all. You could. I've seen it. Here's a secret. I've only had to do twice in once in a year and the second time was only for this tutorial. You just won't be reconfiguring often enough to get all systematic about it.

open-ssl uses Configure not configure. A fine example of why you want individual configure scripts. If you get open-ssl to compile and install it gets easier from here.

Lets build Ruby

It's similar. untar, cd into ruby-2.1.5, edit ../cjc-ruby-2.1.4.sh (yes its not named with 2.1.5). Notice it installs into /home/ccoupe/shoesdeps/mingw/usr/local - this gets sorted out in the Shoes rake files. Lets configure: ../cjc-ruby-2.1.4 and make It's going to take some time. Watch for the configure phase to see if it picks up fiddle, gdbm, openssl, and psych which are our dependent libs ffi, gdbm, openssl and yaml. I had trouble with ffi on Debian 7.8 but Ubuntu 14.04 is fine. Shoes doesn't use fiddle/ffi so I'm going to move on, for tutorial purposes. make install

You can't test it on Linux - don't waste your time with Wine.

Rubygems update

Shoes

Shoes dependencies

We need to build libgif, libjpeg and sqlite3 dlls and install them into ? /home/ccoupe/shoesdeps/ming/! Download them from my location or whatever place you like. You'll notice the pattern, a tgz to expand, a shell script to do the configure, make, make install. Sqlilte is different. So, download them and move them from ~/Downloads to ~/deps-src

tar -jxf giflib-4.2.3.tar.bz2
cd giflib-4.2.3/
vi ../cross-gif.sh  # edit for your locations
 ../cross-gif.sh
make
make install

Repeat for jpeg.

Untar the sqlite3-min.tgz and cd into sqlite3. You'll notice there is no source to build. The zip inside is from the sqlite website - the latest binary download for Windows. I've already expanded it. We just just need to copy the .dll to bin an the *.h to include.

cp sqlite3.dll /home/ccoupe/shoesdeps/mingw/bin/
cp *.h /home/ccoupe/shoesdeps/mingw/include/

Shoes

Now that we have all the dependencies in /home/ccoupe/shoesdeps/mingw we are ready to build Shoes. Let cd into that shoes3 directory. rake -T will list all we can do. We want rake linux:setup:mingw32

That tells the Rakefile what we want build for and what set of subsidiary set of rake files with be used for build, clean, stub, and package tasks. We have to edit the make/xmingw32/env.rb to it where those dependencies are are. Find the line that sets CHROOT if it's for 'gtk2' (it is).

if ENV['GTK'] == "gtk+-2.0"
  CHROOT = "/srv/chroot/mingwgtk2"

change that CHROOT to point to "/home/ccoupe/shoesdeps/mingw" or where ever you have them. Just one more change. A few lines below we have EXT_RUBY = "/srv/chroot/mingwgtk2/usr/local" set that to "/home/ccoupe/shoesdeps/mingw/usr/local"

If there were no mistakes then a simple rake will build Shoes.

Clone this wiki locally