Building a project - lih/Alpha GitHub Wiki

The first question you encounter when starting a project is how to compile, run, test, debug, and deploy it and how to structure your project so that these tasks are easily accomplished.

On this page, I will show you a way to structure your project that obeys to all those constraints, and provide you with scripts in order to let you get started quickly.

The directory structure

As Alpha creates and maintains some intermediary files in order to allow for modularity and speed up compilation times (among other things), it may be wise to redirect Alpha's output to a separate directory so as not to clutter the root of our project.

For pretty much the same reasons, I like to isolate the source tree into a separate directory in order to keep only relevant files in the project root (README, LICENSE, Makefile, documentation,...).

Lastly, I like to use a Makefile for every project I create, for several reasons. Makefiles are pretty much universal, and they provide a simple and consistent interface on a full range of platforms for a wide variety of tasks.

To sum up, I often end up with the following directory structure for my projects :

MyProject/
  src/      -- The source directory
  obj/      -- The object file directory (trash)
  Makefile  -- Or any project management tool config file that you prefer
  README, LICENSE, DOCS, TODO, ... 

The Makefile

Alpha already handles all dependencies concerning module, source and binary files. Thus, the rules will be very simple (almost trivial) and our Makefile very concise.

Name:=MyAwesomeProject
Entry:=main
SourceDir:=src
LangDir:=obj
Flags:=

.PHONY: build
build: bin/$(Entry)

Flags+=-S$(SourceDir) -L$(LangDir)
bin/%:
	alpha $(Flags) -Dbin $(Name):$(@:bin/%=%)
run/%:
	alpha $(Flags) <<< "lang_$(Name); $(@:run/%=%)()"

Notice the 'run/%' target. It is a piece of evil trickery that allows you to run any Alpha verb from your Makefile, but doesn't actually create any files (hence the evilness). Let's say you want to run tests before shipping your program, all you have to do is implement a 'tests' verb and run the command 'make run/tests'.

You may also download this simple script that creates the structure and initializes the project. Run it like ./mkproj.sh Awesome and it will create a directory named Awesome and initialize it with the above structure.