The EMC2 build system is complex. in addition to conventional user space programs, it needs to build kernel modules. And it needs to do so on systems ranging from kernel 2.2 thru 2.6 (and eventually beyond). The kernel build system was totally revamped for version 2.6, so our build system needs to deal with two completely different ways of doing kernel modules.
So, despite its title, this page does _not_ attempt to explain how the EMC2 makefiles work. What it _will_ do is explain how to do some useful things, such as add a new HAL component, or a new userspace program.
This page assumes that you already have a checkout of the source code. Instructions for doing that are at Installing EMC2 (see section 2).
Assuming you want to add a new component "foo". Your source file would be "src/hal/components/foo.c".
In "src/Makefile", find the section that starts with the comment "# Subdirectory: hal/components". At the end of that section, add the following two lines:
obj-$(CONFIG_FOO) += foo.o foo-objs := hal/components/foo.o $(MATHSTUB)
Find the section that starts with the comment "# Rules to make .o (object) files". After the long list of lines starting with "../rtlib", add:
../rtlib/foo.o: $(addprefix objects/rt,$(foo-objs))
Then, in "src/Makefile.inc.in", find the section that starts with the comment "# HAL components". At the end of that section, add:
Then re-run ./configure and make.
If you are creating a driver instead of a component, substitute "drivers" for "components" in the instructions above.
hal/components hal/drivers hal/user_comps/vcp hal/user_comps/devices \
hal/user_comps hal/classicladder hal/foofolder hal/utils hal \
The default optimizer flag is -Os (optimize for size) which might be inconvenient for debugging as code rearrangement and optimized-out variables get in the way; to turn off all optimization for easier debugging, call make as 'make OPT=-O0' (disable optimization)
non-standard compiler flags: pass via a DEBUG= argument to make (default is currently = '-g -Wall' - see DEBUG= in src/Makefile?)
non-standard linker flags: pass via a LDFLAGS= argument to make (see LDFLAGS= in src/Makefile?)
for instance, compile and link for gprof profiling, which involves adding '-pg' to compile and link phases:
. scripts/emc-environment make V=1 DEBUG='-g -Wall -pg' LDFLAGS="-L"$LD_LIBRARY_PATH" -Wl,-rpath,"$LD_LIBRARY_PATH" -pg"