A makefile-based build system for Swift

I'm currently playing with Swift, outside of Xcode (but of course, you need to have Xcode installed to have swiftc installed...), when I have a few spare cycles and building more than just a few files was getting so painful I started working on a minimal build structure. Since it's working pretty well and it was not always easy to figure out what to do, I've decided to share it.

First, clone the following git and copy the swiftbuild directory you'll find inside to your project's top directory: git clone https://github.com/therealglazou/swift-makefiles.git

Then tweak the swift/config.mk according to your wishes (in the repository, it's for a macosx x86_64 target).

Finally, add a Makefile file to each directory inside your project. Each file should look as following:

# TOPSRCDIR is a relative path to the top directory of your project
# for instance:
TOPSRCDIR = ../../..

# if you have subdirs to build, list them in DIRS. They will be built
# before the files directly in your directory
# for instance:
DIRS = public src

# if you're building a module from the swift files in this directory
# name your module in MODULE_NAME
# for instance:
MODULE_NAME = MyProjectCore

# if your directory contains your main.swift (mandatory for a
# standalone executable), give your app's name in APP_NAME
# for instance:

# now, always include $(TOPSRCDIR)/swiftbuild/config.mk
include $(TOPSRCDIR)/swiftbuild/config.mk

# your swift sources should go into SOURCES
# for instance:
SOURCES = foo.swift bar.swift

# if you need to import modules outside of your project
# use IMPORTS to list the paths, of course prepended by -I
# for instance:
IMPORTS =-I /Users/myname/trees/myotherproject/modules/

# if you need some dylibs to build your module or your app,
# then use LD_FLAGS (always +=) and LIBS; for instance:
LDFLAGS += -L/Users/myname/trees/myotherproject/lib
LIBS = -lfooCore

# and finally always include $(TOPSRCDIR)/swiftbuild/rules.mk
include $(TOPSRCDIR)/swiftbuild/rules.mk

And that's it, you're now good to make build, make clean and make clobber. The first one will build everything, your dylibs and app being in $(OBJDIR) at the end of the build while your modules are in $(OBJDIR)/modules. The second one will delete all dylibs, *.o and build remains from your directories but will preserve $(OBJDIR). The last one performs a clean and deletes $(OBJDIR) too.

Let me know if it's useful please. And I'm of course accepting pull requests. Next steps: static linking and build of a complete foo.app OS X application...