Cross-Platform Builds
Posted in Development Tools, Software on April 5th, 2010 by Chris – 2 CommentsFor a while now I've been getting worried about the amount of boilerplate source code I'm copying around from one project to another, so yesterday I refactored all the general-interest code out of my current mini-project and wrote a cross-platform build infrastructure which can build and test each mini-library in isolation, and automatically integrate with github for fetching dependencies. Doing such a thing in a language like Java is very easy, but doing it in C is far harder.
Firstly the directory structure. Each project lives in a structure like this:
src
|
+-apps
| |
| +-nanduinoJtag
|
+-libs
| |
| +-argtypes
| +-buffer
| +-dump
| +-hexreader
| +-usbwrap
|
+-3rd
|
+-argtable2-12
+-LUFA091223
+-UnitTest++
The idea is to maintain a clear separation between 3rd-party ("3rd") code, my own library ("libs") code and my own application ("apps") code, and to automatically fetch any dependencies, downloading my own libs if necessary from github and building them, and downloading 3rd-party libs and tools from wherever and building them.
The build infrastructure itself is based on GNU make, and it supports Linux and Windows builds.
Windows Builds
The Windows platform introduces some unique challenges. Tooling on Windows is characterised by large-scale tools, usually relying heavily on IDE integration, rather than the more expressive Unix environment which is based on a large number of small-scale tools which cooperate with eachother. So to get off the ground on Windows you will need a couple of prerequisites:
- A functional GNU environment. I do a lot of stuff using Atmel AVR microcontrollers, so I have WinAVR installed, which comes with such an environment, but you will probably get away with a more minimal cygwin or mingw installation, so long as it has basic stuff like
make,tar,mv,cp,wget, etc. - An installation of Microsoft Visual C++ 2008 Express Edition which is available from Microsoft as a free download. The 2010 edition will not work because
vcbuild.exehas been deprecated.
Once you have the prerequisites you can go ahead and build an application (this one really does need WinAVR since it contains AVR code)...
C:\temp>mkdir foo-src
C:\temp>cd foo-src
C:\temp\foo-src>mkdir apps
C:\temp\foo-src>cd apps
C:\temp\foo-src\apps>wget http://github.com/makestuff/nanduinoJtag/tarball/master
C:\temp\foo-src\apps>tar xvzf makestuff-nanduinoJtag-*.tar.gz
C:\temp\foo-src\apps>cd makestuff-nanduinoJtag-*
C:\temp\foo-src\apps\makestuff-nanduinoJtag-c9d3c67>make -f Makefile.win32
C:\temp\foo-src\apps\makestuff-nanduinoJtag-c9d3c67>cd ..\..
C:\temp\foo-src>find . -maxdepth 2 -type d
.
./3rd
./3rd/argtable2-12
./3rd/libusb-win32-device-bin-0.1.12.2
./3rd/LUFA091223
./3rd/UnitTest++
./3rd/unz600
./apps
./apps/makestuff-nanduinoJtag-c9d3c67
./libs
./libs/argtypes
./libs/buffer
./libs/dump
./libs/hexreader
./libs/usbwrap
After the build completes you will notice that the requisite dependencies for this particular project have been downloaded and built for you. Where possible I have used the vcbuild tool rather than invoking the compiler and linker directly, so you should be able to run the apps in the Visual Studio IDE without problems.
Linux Builds
Achieving the same thing on Linux is considerably simpler. The requisite tools are usually already installed, and if not can easily be installed using your favourite package manager.
> mkdir foo-src
> cd foo-src/
> mkdir apps
> cd apps/
> wget http://github.com/makestuff/nanduinoJtag/tarball/master
> tar xvzf makestuff-nanduinoJtag-*.tar.gz
> cd makestuff-nanduinoJtag-*
> make -f Makefile.linux
> cd ../..
> find . -maxdepth 2 -type d
.
./apps
./apps/makestuff-nanduinoJtag-c9d3c67
./libs
./libs/dump
./libs/usbwrap
./libs/hexreader
./libs/buffer
./libs/argtypes
./3rd
./3rd/UnitTest++
./3rd/argtable2-12
./3rd/LUFA091223
After the build completes you will notice that the requisite dependencies for this particular project have been downloaded and built for you.
Great stuff, but I hope you switch over to a newer LUFA distribution than 091223. The latest releases carry many more fixes, which may benefit you with your applications.
- Dean
Hi Dean,
Yup, I will definitely upgrade. The project I used as an example for describing this build stuff was a JTAG dongle implemented on an AT90USB162. At the time, LUFA/091223 was quite recent, but time, tide and Dean Camera wait for no man...
Chris