[Home]MakefileDeMystified

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Difference (from prior author revision) (major diff)

Added: 49a50,52
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)


Purpose

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.

Getting Started

This page assumes that you already have a checkout of the source code. Instructions for doing that are at Installing EMC2 (see section 2).

Adding a new Real Time HAL module

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:

 CONFIG_FOO=m

Then re-run ./configure and make.

If you are creating a driver instead of a component, substitute "drivers" for "components" in the instructions above.

Adding a new userspace program

In "src/Makefile", find the section that starts with the comment "# Submakefiles from each of these directories will be included if they exist" In that section, add the information to find the submakefile:
Eg. for a submakefile in "hal/foofolder"
<snip>
    \
hal/components hal/drivers hal/user_comps/vcp hal/user_comps/devices \
hal/user_comps hal/classicladder hal/foofolder hal/utils hal \
\
<snip>
Now add a submakefile and your source code into the foofolder
look at submakefile.skel in the src folder for more information about how to write a submakefile

Passing flags to the Makefile

to see actual compilation commands:
  make V=1

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"

Adding a new source file to "task"


LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited July 20, 2011 1:01 pm by MichaelHaberler (diff)
Search:
Published under a Creative Commons License