1 \input texinfo @c -*-texinfo-*-
3 @setfilename omk-manual
4 @settitle OMK: Ocera Make System
8 Manual for Ocera Make System (OMK)
10 Copyright @copyright{} 2007 Michal Sojka, Pavel Pisa
14 @title Ocera Make System Manual
16 @vskip 0pt plus 1filll
23 @node Top, Overview of OMK, (dir), (dir)
24 @top Ocera Make System
38 @node Overview of OMK, OMK User's Manual, Top, Top
42 OMK is an advanced make system written entirely in GNU make. Compiling
43 software using OMK requires only GNU make binary and standard UNIX
44 utilities (@command{sh}, @command{sed}, @command{cmp} and
45 @command{tr}@footnote{@command{tr} is needed only for OMK to be
46 compatible with MinGW.}) installed. OMK aims to be developer friendly;
47 to use OMK, you do not need to understand (sometimes) cryptic syntax of
50 You can use OMK on all platforms where you can run GNU Make including
51 Cygwin and MinGW. MS DOS was not tested.
57 @c Easy to use for beginners.
59 @c Automatic handling of dependencies.
61 @c Supported host platforms: all Un*x operating system including Linux,
62 @c Cygwin, MS DOS and maybe others.
71 @node Why to Use OMK?, Quick Start, Overview of OMK, Overview of OMK
72 @section Why to Use OMK?
74 Here we list some of OMK features, which we think are important for
75 choosing of a make system.
80 Makefile in source directories are usually very @b{simple}.
82 There is only @b{one} @file{Makefile.rules} for most of components of
85 OMK greatly simplifies compilation of projects, where source files are
86 spread between @b{multiple directories}.
88 OMK handles properly @b{dependencies} of source files and libraries,
89 so it is not necessary to recompile the whole project if only several
92 OMK allows to freely @b{move} cross-dependant components @b{in
93 directory structure} without the need to update users of moved
94 component. I hate something like
95 @option{-I../../sched/rtlshwq/include} in makefiles for example. If a
96 component is renamed or version is added to the name, many Makefiles
97 in the project would require an update.
99 The above feature is very helpful in @b{combining components}
100 (libraries) from different projects/developers to a single project by
101 simply creating symbolic links to external components.
103 Compilation of an OMK based projects don't require to install any
104 files before successful finish of build.
106 OMK allows to call @command{make} for a particular subdirectory in the
109 Under OMK all products of compilation are stored @b{out of source
110 directories}. This simplifies work with version control systems and
111 helps when simultaneous compilation for multiple targets/platforms is
116 @node Quick Start, History, Why to Use OMK?, Overview of OMK
119 If you get some sources, which are distributed with OMK, usually the
120 following commands are sufficient to compile the whole project.
129 @noindent To use OMK in your own project, follow these steps:
133 Take appropriate @file{Makefile.rules}, put it together with leaf
134 @file{Makefile} to the root directory of your project.
136 Create @file{Makefile.omk} files in all directories you want to
137 compile something. Please refer to @ref{OMK User's Manual} to learn
138 what to write in @file{Makefile.omk} files.
140 Run @command{make omkize} in the root directory.
143 @noindent Your project is now ready to compile.
146 @node History, , Quick Start, Overview of OMK
149 OMK was originally written by Pavel Pisa as a solution to have one
150 common make system for OCERA project, where we needed to compile
151 user-space programs, Linux kernel modules and RT Linux modules in one
152 package. Although this system was not accepted for the whole OCERA
153 project. Several individual developers (mostly from Czech Technical
154 University) liked it and started to use it.
156 As a number of projects using OMK grew it was necessary to modularize
157 the make system to support more ``targets''. Michal Sojka took care
158 about the process of modularization.
160 @node OMK User's Manual, Original README, Overview of OMK, Top
161 @chapter OMK User's Manual
166 * Compiling Programs::
168 * Multiple Directories::
169 * Dependency Tracking::
170 * Configuration and Conditional Compilation::
171 * Advanced OMK Features::
172 * Properties of Specific Makefile.rules::
173 * Running OMK under Windows OS::
174 * Interfacing OMK to popular IDEs::
178 @node Basic Concepts, Invoking OMK, OMK User's Manual, OMK User's Manual
179 @section Basic Concepts
181 The main concept of OMK is very simple. In the root directory of the
182 projects resides a file called @file{Makefile.rules}. This file contains
183 all compilation rules needed for compilation of a particular
184 project. There are different @file{Makefile.rules} for different
185 platforms (Unix, RTEMS, system-less, ...). In every subdirectory a
186 @file{Makefile.omk} is stored. This file determines what should be done
187 in the respective directory (e.g. compile a program from several source
188 files). Its syntax is very simple -- see the following sections.
190 Since make searches by default for a @file{Makefile} and not for
191 @file{Makefile.rules} or @file{Makefile.omk}, there must@footnote{When
192 USE_LEAF_MAKEFILES is set to @samp{n}, this @file{Makefile} can be
193 omitted in subdirectories. @xref{USE_LEAF_MAKEFILES}.} be a small
194 generic @file{Makefile} in every directory, whose task is only to find
195 @file{Makefile.rules} in the actual or any parent directory and include
196 it. This search is performed only once at the beginning of compilation.
198 @c TODO: Pavel's note about qmake.
201 The compilation process itself is comprised of several @emph{passes}. Every
202 pass traverses the whole directory structure@footnote{In future, we are
203 planning some optimization that allows OMK to traverse the directories
204 only once and thus decrease compilation time.} and does a particular
205 task in every directory of the project. Typically, these passes are:
207 @anchor{include-pass}
209 This pass takes all include files marked for ``export'' and copies
210 (or links) them to the @file{include} directory under
211 @file{_compiled} directory. @xref{Header Files}.
213 Also, during this pass, automatically generated header file are
214 generated according to the current
215 configuration. @xref{Configuration and Conditional Compilation}.
217 During this pass, all include files are in place, so all libraries
220 Finally, programs can be compiled and linked against libraries
221 created in the previous pass.
224 The results of compilation are stored under the @file{_compiled}
225 directory. This directory is structured as a classical Unix file-system
226 (it contains directories like @file{bin}, @file{lib} and @file{include})
227 and can be directly copied to the target device or to some directory on
228 a host computer (e.g. @file{/usr/local}).
230 Besides @file{_compiled} directory, there in a @file{_build}
231 directory. Under this directory are stored some temporary files and
232 intermediate compilation products (object files, dependency files etc.).
234 In the next section, we provide an overview of methods, how to invoke
235 OMK from command line. Section @ref{Interfacing OMK to popular IDEs}
236 covers running of OMK from popular IDEs.
238 Sections @ref{Compiling Programs} through @ref{Configuration and
239 Conditional Compilation} deals with the content of
240 @file{Makefile.omk}. Its syntax in usual cases compatible to GNU
241 Automake's @file{Makefile.am} syntax. Also, the scheme for naming
242 variables was inspired by Automake so most OMK variables have the name
243 like @samp{@var{target}_@var{TYPE}}.
245 @node Invoking OMK, Compiling Programs, Basic Concepts, OMK User's Manual
246 @section Invoking OMK
248 Before using OMK for the first time, you have to call:
250 @command{make default-config}
252 @noindent See @ref{Configuration and Conditional Compilation} for
253 details. If you forget to do this, OMK will notice you.
255 To compile the whole project or only some subtree of the project, call
259 @noindent in the appropriate directory.
261 To clean files in @file{_build} directory but not in @file{_compiled}
267 To clean the compilation completely, you can either remove
268 @file{_compiled} and @file{_build} directories manually, or call
270 @command{make distclean}
272 @noindent which does the same. This command removes these directories
273 even if you call it from a subdirectory.
275 To debug compilation problems, you can use @code{V} variable (see
281 You can also set values of some other variables on command line for
282 temporary change something. The example below compiles the code
283 temporarily with debugging information:
285 @command{make CFLAGS="-g -O0 -Wall"}
288 If your project uses an alternative make-system (e.g. Automake or custom
289 makefiles), it might be useful for you to use the command:
291 @command{make omkize}
293 @noindent This will find all @file{Makefile.omk} files in all subdirectories
294 and copies generic @file{Makefile} from the root directory to that
295 subdirectories. This way you can easily switch your project to use OMK.
301 If this variable equals to @samp{1}, the whole command lines for all
302 executed commands are displayed. When not set or zero, only short
303 messages are printed. Value of @samp{2} displays the whole command lines
304 as with @samp{1} and in addition directory navigation messages are
308 @node Compiling Programs, Libraries, Invoking OMK, OMK User's Manual
309 @section Compiling Programs
311 To tell OMK to compile a program, you need to set some variables in
312 @file{Makefile.omk} (usually) in the directory where program sources are
315 In the example bellow a program @command{test} will be compiled from
316 source @file{test.c}.
319 @verbatiminclude ../tests/programs/Makefile.omk
322 @noindent The variables are:
324 @anchor{bin_PROGRAMS}
326 Contains a list of names (whitespace separated) of programs to be
327 compiled in this directory.
330 @defvar test_PROGRAMS
331 Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
332 stored in @file{bin-tests} directory instead of @file{bin}. This
333 variable is intended for various test programs not to be mixed with
337 @defvar utils_PROGRAMS
338 Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
339 stored in @file{bin-utils} directory instead of @file{bin}. This
340 variable is intended for various development utilities not to be mixed
341 with the final product.
345 For every program name @var{xxx} in @code{bin_PROGRAMS},
346 @code{test_PROGRAMS} or @code{utils_PROGRAMS}, this variable contains
347 a list of sources that are needed to compile the program. OMK uses an
348 extension of the filename to determine the compiler to compile this
353 This variable contains a list of libraries the program @var{xxx} will
362 This variable contains a list of libraries all programs in this
363 directory needs to be linked to.
367 Directives passed to the C or C++ compiler with additional directories
368 to be searched for header files. In most cases you need to specify an
369 absolute path. To specify a directory relative to the source
370 directory, you can use the @code{$(SOURCES_DIR)} variable, which
371 refers to the directory, where @file{Makefile.omk} is located. This
372 variable applies to all compilations invoked in the current directory.
375 INCLUDES = -I$(SOURCES_DIR)/my_include_dir
380 Directives passed to the C or C++ compiler with preprocessor macro
381 definitions. This variable applies to all compilations invoked in the
390 @c FIXME: INCLUDES variable should not be set by rtlinux rules.
392 @node Libraries, Multiple Directories, Compiling Programs, OMK User's Manual
396 With OMK, you can easily create statically or dynamically linked
397 libraries. The way of creating libraries is very similar to how programs
398 are created. @xref{Compiling Programs}.
400 In @file{Makefile.omk}, you specify several variables, which defines how
401 the libraries should be compiled. In the example below the library
402 @samp{mylib} (full filename will be @file{libmylib.a}) is created from
403 two sources @file{funca.c} and @file{funcb.c}. Interface of this library
404 is defined in @file{myfunc.h}. Therfore, we export this header for use
408 @verbatiminclude ../tests/libraries/Makefile.omk
411 @noindent Variables for use with libraries are:
413 @defvar lib_LIBRARIES
414 Specifies a list of statically linked libraries to be compiled. OMK
415 automaticvally prepends @code{lib} prefix library names.
418 @defvar shared_LIBRARIES
419 Specifies a list of dynamically linked libraries to be compiled.
423 For every library name @var{xxx} in @code{lib_LIBRARIES} or
424 @code{shared_LIBRARIES}, this variable contains a list of sources that
425 are needed to compile the library. OMK uses an extension of the
426 filename to determine the compiler to compile this source.
433 @node Header Files, , Libraries, Libraries
434 @subsection Header Files
436 C and C++ libraries are not very useful without header files. OMK
437 provides several variables that specify activities on header files.
439 During compilation, header files are copied (or linked) from source
440 directories to the @file{_compiled} tree
441 (see @ref{include-pass}). Libraries and programs are then compiled against
444 @anchor{include_HEADERS}
445 @defvar include_HEADERS
446 Specifies the list of header files to be exported for use by other
447 libraries/programs. The files are exported directly to the
448 @file{include} directory even if the file is located in a subdirectory
449 (like @file{sci_regs.h} in the example below)
452 include_HEADERS = regs.h periph/sci_regs.h
456 @defvar nobase_include_HEADERS
457 Similar to @ref{include_HEADERS}, but the directory prefix is always
458 kept. To include the file exported by this variable, use
459 @code{#include <@var{prefix}/@var{header.h}>}.
462 @defvar renamed_include_HEADERS
463 Exports the header files under different name. The form of the items
464 in this whitespace separated list is: @var{real name}@code{->}@var{new
468 renamed_include_HEADERS = orte_config_omk_win32.h->orte_config.h
473 If this variable equals to @samp{y}, symbolic links to headers in
474 source directories are used in @file{_compiled} tree instead of
477 Normally, the header files are copied into @file{_compiled} directory
478 to be prepared for transfer into target location afterwards. Copying
479 ensures that resulting libraries are in correspondence with the header
480 files even if the header is changed by a developer but the library is
483 @c Another reason for having single include directory for the whole
484 @c project is tat every component knows where to find header files of
487 On the other side, the copying could make problems during
488 development. Most @acronym{IDE}s, allows you to jump directly to the
489 place, where an error is reported by the compiler. If the error is in
490 a header file, IDE opens you the copy of the header file. If you
491 correct the error there, after the next compilation, your header file
492 will be overwritten by the old version from your source tree.
494 This option is not typically used in @file{Makefile.omk}, but in the
495 top level configuration file @file{config.omk} or on command line.
498 @node Multiple Directories, Dependency Tracking, Libraries, OMK User's Manual
499 @section Multiple Directories
501 OMK is probably most useful in projects consisting of multiple
502 directories. For such projects, it is not easy to write from scratch
503 classic Makefiles that provides all the needed features.
505 You can instruct OMK to descend to a (sub)directory by setting the
506 @code{SUBDIRS} variable in @file{Makefile.omk}.
509 This variable contains a list of directories, in which compilation
510 must be also invoked. Usually, names of subdirectories are used, but
511 you can use any path specification here.
513 Compilation is invoked in these directories before it is invoked in
514 the current directory.
516 @c TODO: Write tests for this.
518 @defvar ALL_OMK_SUBDIRS
519 This variable is set by OMK and can be used as the value of
520 @code{SUBDIRS} variable. It contains a list of all direct
521 subdirectories, which contain @file{Makefile.omk}. This is especially
522 useful if you are combining several projects or components
523 together. In the root directory of your project, you just create
524 symbolic links the components from other projects and all the linked
525 directories automatically appears as the value of this variable.
528 SUBDIRS = $(ALL_OMK_SUBDIRS)
532 @node Dependency Tracking, Configuration and Conditional Compilation, Multiple Directories, OMK User's Manual
533 @section Dependency Tracking
535 OMK automatically handles tracking of dependencies of files in compiled
536 projects. It uses gcc's @option{-M@var{x}} options to do this for object
537 files. This way, whenever you change some header file, OMK recompiles
538 only those files, where the changed header was really included.
540 Dependencies are also maintained for libraries and binaries. To find the
541 dependencies, OMK parses linker map files, so a change to some library
542 causes recompilation of all programs using that library.
544 @node Configuration and Conditional Compilation, Advanced OMK Features, Dependency Tracking, OMK User's Manual
545 @section Configuration and Conditional Compilation
547 In many projects, it is necessary to configure the compilation process. By
548 this configuring we mean, setting some parameters that influence the
549 output of compilation process. In GNU projects, @command{configure}
550 script is usually responsible for configuration. User provides some
551 parameters to @command{configure}, which is run before compilation, and
552 this script does all steps needed to configure the sources and
553 make-system in the desired way.
555 OMK has its own configuration mechanism, which is described in this
556 section. For future releases, we plan that this mechanism can make use
557 of GNU Autoconf, but currently there is no directly integrated support
560 There exist three different configuration files
561 @file{config.omk-default}, @file{config.target} and
562 @file{config.omk}. All of these have to be stored in the same directory
563 as @file{Makefile.rules}. During compilation, these files are included
564 in @file{Makefile.rules} in this order which means that variables
565 assigned in the former files are overridden by those from later
566 ones. All settings specified here apply to the whole compilation
567 tree. Each file is intended for a different kind of configuration
570 @item config.omk-default
571 Stores default configuration of compiled components. This file is
572 automatically generated (see below) and should not be edited by users.
574 Stores default configuration for a project or target hardware. This
575 file is intended to be stored in a version control system and should
576 be modified only by the maintainer of the project.
578 For cross compiled projects, this file typically contains settings of
579 variables like @var{CC} and @var{CFLAGS}.
581 This is a file for end users, where any default settings set in the
582 above files can be overridden. This file should not be stored in
583 version control system. The project should compile without having this
587 Besides variables defined in @file{config.target}, @file{Makefile.omk}
588 in any subdirectory can specify some configuration parameters. When
589 @command{make default-config} is run, all these parameters are found and
590 together with their default values are stored as makefile variables in
591 @file{config.omk-default}. This file is included during compilation, so
592 if you don't specify other values, these defaults are used. If you are
593 not satisfied with these defaults, you can override the values of
594 parameters either locally for your build in @file{config.omk} or
595 globally for all people working with the project in
596 @file{config.target}.
599 * Specifying Configuration Parameters::
600 * Using Configuration Parameters::
604 @node Specifying Configuration Parameters, Using Configuration Parameters, Configuration and Conditional Compilation, Configuration and Conditional Compilation
605 @subsection Specifying Configuration Parameters
607 To specify names and default values of configuration parameters use the
608 @code{default_CONFIG} variable in @file{Makefile.omk}.
610 @defvar default_CONFIG
611 This variable contains a list of configuration parameters and their
612 default values. The format of every item in this list is
613 @var{CONFIG_xxxx}=@var{value}. You can name the parameter as you want,
614 but it is good practice to start the name with @samp{CONFIG_} prefix.
616 OMK can automatically generate header files, with C preprocessor macro
617 definitions according to the OMK's configuration parameters. The
618 actual content of generated header files depends on the form of the
619 @var{value}. The possible forms are:
622 @item @samp{y}, @samp{n} or @samp{x}
623 This defines boolean parameters. If the value of the parameter is
624 @samp{y}, the @samp{#define CONFIG_@var{xxx} 1} is generated, if it is
625 @samp{n}, no @code{#define} is generated.
627 @samp{x} is a special value called @emph{recessive 'n'}. The meaning
628 is that this parameter influences the component in the current
629 directory (i.e. the corresponding @code{#define} will be included in
630 @code{LOCAL_CONFIG_H}; see @ref{LOCAL_CONFIG_H}) but the default value
631 is not specified here. If the default value is not specified anywhere,
632 the behavior is the same as if @samp{n} is specified.
634 Numeric parameters. The define looks like @samp{#define CONFIG_@var{xxx} @var{number}}
636 Text without quotes. The define looks like @samp{#define CONFIG_@var{xxx} @var{text}}
638 Text with quotes. The define looks like @samp{#define CONFIG_@var{xxx} "@var{text}"}
642 @noindent Example of using @code{default_CONFIG}. @file{Makefile.omk} reads like:
644 @verbatiminclude ../tests/config/default/Makefile.omk
646 @noindent and @file{subdir/Makefile.omk} like:
648 @verbatiminclude ../tests/config/default/subdir/Makefile.omk
651 @noindent After running @command{make default-config}, the content of
652 @file{config.omk-default} will be:
654 @verbatiminclude ../tests/config/default/config.omk-correct
657 @node Using Configuration Parameters, Common Variables, Specifying Configuration Parameters, Configuration and Conditional Compilation
658 @subsection Using Configuration Parameters
660 Configuration parameters can be used in two ways:
663 as variables in @file{Makefile.omk} and
665 as C/C++ preprocessor macros in OMK generated header files.
668 @noindent For the first use, your @file{Makefile.omk} may contain something like:
670 SUBDIRS = arch/$(CONFIG_ARCH)
672 ifeq ($(CONFIG_DEBUG),y)
673 DEFS += -DUSE_SIMULATOR
677 @noindent For the second use, there are several variables that control
678 the generation of header files with configuration values. These
679 variables are described here:
681 @anchor{LOCAL_CONFIG_H}
682 @defvar LOCAL_CONFIG_H
683 The value of this variable is the name of a header file, which will
684 contain all configuration parameters declared in the current directory
685 by @code{default_CONFIG}. This header file is accessible only by files
686 in the current directory and it should be included like @code{#include
689 In @file{Makefile.omk}, the use of this variable can look like this:
692 LOCAL_CONFIG_H = myconfig.h
696 @defvar config_include_HEADERS
697 This variable is similar to @code{LOCAL_CONFIG_H}. One difference is
698 that the generated header file is accessible to all sub-projects in
699 all directories, not only to the files in the same directory (the
700 header is stored in @file{_compiled} tree). The second difference is
701 that you have to specify, which configuration parameters you want to
702 appear in the header file.
706 This variable determines the configuration parameters that should be
707 stored in a header file specified by
708 @code{config_include_HEADERS}. The @var{xxx} in the name of this
709 variable needs to be the same as the base name (without extension) of
713 @noindent Example of using @code{config_include_HEADERS}:
715 default_CONFIG = CONFIG_LINCAN=y CONFIG_LINCANRTL=n CONFIG_LINCANVME=n
716 config_include_HEADERS = global.h
717 global_DEFINES = CONFIG_OC_LINCAN CONFIG_OC_LINCANRTL
720 @noindent Here, we include only two out of the three configuration
721 parameters defined in the current @file{Makefile.omk}. It is also
722 possible to include configuration parameters defined in a different
725 @node Common Variables, , Using Configuration Parameters, Configuration and Conditional Compilation
726 @subsection Common Variables
728 It is common practice to use @file{config.omk} to store project-wide
729 settings. Here is the list of variables, which are commonly set here
730 (but they can also be set elsewhere, e.g. in @file{Makefile.omk}).
732 You can easily ``reconfigure'' your project by changing the
733 @file{config.omk} file. It is useful to have several configurations
734 stored in different files and let @file{config.omk} be a symbolic link
735 to the desired configuration.
739 The name of C compiler.
741 Command line options for C compiler.
743 The name of C++ compiler.
745 Additional parameters (besides @code{CFLAGS}) to by passed to C++
749 @node Advanced OMK Features, Properties of Specific Makefile.rules, Configuration and Conditional Compilation, OMK User's Manual
750 @section Advanced OMK Features
752 In this section we list several OMK features, which are more complicated
753 or rarely used so they were omitted in previous sections.
756 * Organization of the Source Tree::
757 * Additional Variables::
758 * Adding Hooks to Passes::
761 @node Organization of the Source Tree, Additional Variables, Advanced OMK Features, Advanced OMK Features
762 @subsection Organization of the Source Tree
766 The @file{_compiled} directory can be shared between multiple projects
767 (by using symbolic links).
770 If you work on a bigger project, you usually don't need to rebuild the
771 whole project and call @command{make} only in a
772 subdirectory. Sometimes, it might be useful to rebuild the whole
773 project. You can either change working directory to the root of your
774 project and call @command{make} there or, as a shortcut, you can use
775 @code{W} variable (see @ref{W}) to compile everything directly from a
782 Searching for @file{Makefile.rules} works such way, that if you get
783 into sources directory over symbolic links, OMK is able to unwind your
784 steps back. This implies you can make links to component directories
785 on read-only media, copy @file{Makefile.rules}, @file{Makefile} and
786 top-level @file{Makefile.omk}, adjust @file{Makefile.omk} to contain
787 only required components and then call @command{make} in the top
788 directory or even in read-only directories after changing working
789 directory from your tree to the readonly media.
795 If this variable equals to @samp{1}, the @b{whole} project is
796 (re)compiled, even if @command{make} is called from a subdirectory.
799 @node Additional Variables, Adding Hooks to Passes, Organization of the Source Tree, Advanced OMK Features
800 @subsection Additional Variables
802 @anchor{USE_LEAF_MAKEFILES}
803 @defvar USE_LEAF_MAKEFILES
804 If this variable equals to @samp{n} (default is unset), then OMK uses
805 the leaf @file{Makefile} only when it is invoked by simple
806 @command{make} command. Later, during recursive directory descent leaf
807 @file{Makefile} is not used and @file{Makefile.rules} is included
810 This feature is useful if you are integrating some non-OMK project into
811 your project. You only add @file{Makefile.omk} files to the non-OMK
812 project and don't need to modify project's original Makefiles.
814 This variable can be set either globally in a @file{config.*} file or
815 locally in some @file{Makefile.omk}. In the latter case, it influences
816 only subdirectories of the directory containing @file{Makefile.omk}.
821 This variable is set internally by OMK and its value is the absolute
822 path to the directory with compiled sources. It can be used if you need
823 to refer to sources files in some custom constructs in
827 include_HEADERS = $(notdir $(wildcard $(SOURCES_DIR)/*.h))
833 The same as @ref{SOURCES_DIR}. Provided for Automake compatibility.
836 @defvar{MAKERULES_DIR}
837 This variable is set internally by OMK and its value is the absolute
838 path to the directory containing @file{Makefile.rules} currently used
842 @defvar{OMK_RULES_TYPE}
843 Identification the type of @file{Makefile.rules} used for
844 compilation. Values are like @samp{linux}, @samp{rtems}, @samp{sysless},
845 ... This variable is automatically generated during creation of
846 @file{Makefile.rules} and can be used in configuration files (see
847 @ref{Configuration and Conditional Compilation}) or in
848 @file{Makefile.omk} to tweak compilation for specific targets.
851 @node Adding Hooks to Passes, , Additional Variables, Advanced OMK Features
852 @subsection Adding Hooks to Passes
854 Sometimes it is necessary to run some special commands as a part of
855 compilation. Typical example might be a tool which generates source
856 files on the fly. OMK supports calling additional commands during
857 compilation by so called @emph{pass hooks}. A pass hook is an ordinary
858 make target which is invoked as part of compilation during a particular
859 pass (see @ref{passes}). Pass hooks can be defined by assigning their
860 names to @code{xxx_HOOKS} variable.
863 Specifies one or more hooks (make targets) which are invoked during pass
864 @var{xxx}. The working directory of commands or this target is under the
867 In the example bellow header file @file{generated_header.h} is created
868 during @samp{include-pass} by @file{convert_data} program. The program
869 takes @file{data_file.txt} in the source directory as the input and
870 creates the header file in the in the correct directory under the
874 include-pass_HOOKS = generated_header.h
876 generated_header.h: $(SOURCES_DIR)/data_file.txt
877 convert_data < $^ > $@@
881 @node Properties of Specific Makefile.rules, Running OMK under Windows OS, Advanced OMK Features, OMK User's Manual
882 @section Properties of Specific Makefile.rules
884 In previous sections, general properties of @file{Makefile.rules} were
885 documented. This section contains documentation to features found only
886 in some particular @file{Makefile.rules}.
894 @node Linux, System-Less, Properties of Specific Makefile.rules, Properties of Specific Makefile.rules
897 This @file{Makefile.rules} is used not only for Linux as the name
898 sugest, but also for other Unices and even for Windows.
901 The name of the operating system (OS) where make was invoked.
905 Should specify the name of OS where the resulting binary should be
906 used. If not specified manually, it equals to BUILD_OS.
910 Lists subdirectories with QT project (.pro) file. OMK will generate
911 there @file{Makefile} by calling @command{qmake} with correct
912 parameters to interface QT application to the rest of the compilation
913 tree. Then @command{make} is called there to compile QT
914 application. Variable @samp{QTDIR} must be set to the directory with
915 QT installation (e.g. /usr/share/qt4 on Debian).
919 @node System-Less, RTEMS, Linux, Properties of Specific Makefile.rules
920 @subsection System-Less
922 This @file{Makefile.rules} is deigned for compilation of code for
923 (small) micro-controllers without operating systems. See
924 @uref{http://rtime.felk.cvut.cz/hw/index.php/System-Less_Framework} for
925 more information about our framework, which uses this rules.
927 @node RTEMS, , System-Less, Properties of Specific Makefile.rules
933 @node Running OMK under Windows OS, Interfacing OMK to popular IDEs, Properties of Specific Makefile.rules, OMK User's Manual
934 @section Running OMK under Windows OS
936 It is possible to use OMK under Windows OS with MinGW (see
937 @uref{http://www.mingw.org/}). Unfortunately, the compilation speed is
938 much lower than on UNIX systems.
940 TODO: Is it necessary to install anything special?
942 @node Interfacing OMK to popular IDEs, Troubleshooting, Running OMK under Windows OS, OMK User's Manual
943 @section Interfacing OMK to popular IDEs
951 @node KDevelop, Eclipse/CDT, Interfacing OMK to popular IDEs, Interfacing OMK to popular IDEs
954 KDevelop has support for custom build systems. To use KDevelop to
955 develop projects using OMK follow these steps. These steps are valid for
956 version 3.5.0 of KDevelop, but for previous versions it doesn't differ
961 Import project to KDevelop (from menu choose @emph{Project---Import
962 existing project}). Select the type of project to @emph{Generic C
963 Application (Custom Buildsystem)}.
969 Then answer to following dialogs as you want.
974 @image{kdevelop3} @image{kdevelop4}
978 If you are working only on some small part of the bigger project, you
979 usually don't want to recompile the whole project every time. In
980 @emph{Project---Project Options}, you can specify the subdirectory where to
987 If you want to switch between several configurations easily (see also
988 @ref{Configuration and Conditional Compilation}), in the same dialog
989 you can add @option{-e} to make options. This makes environment variables
990 have higher precedence than those in @file{config.omk-default}. Then,
991 you can define several environments with different
992 @code{CONFIG_@var{xxx}} variables and their values.
998 You can easily switch the configurations from @emph{Build---Make
1005 @node Eclipse/CDT, Emacs/Vim/etc., KDevelop, Interfacing OMK to popular IDEs
1006 @subsection Eclipse/CDT
1008 @node Emacs/Vim/etc., , Eclipse/CDT, Interfacing OMK to popular IDEs
1009 @subsection Emacs, VIM, etc.
1011 Since OMK compilation is started by executing @command{make} command,
1012 many common editors can work easily with OMK.
1014 Under Emacs, you can use @command{compile} or @command{recompile}
1015 commands as you are used to do.
1017 @node Troubleshooting, , Interfacing OMK to popular IDEs, OMK User's Manual
1018 @section Troubleshooting
1022 If you rename some file or directory and then you can't compile your
1023 project, call @command{make clean} in the directory with errors. The
1024 reason for this behavior is that OMK remembers dependencies of every
1025 file. After renaming something, the original name is still stored in
1026 dependencies, but make doesn't know how to create this non-existent
1030 Sometimes, you may want to compile one file the same way as OMK does
1031 it, but run the compilation manually from command line. For example,
1032 you want to debug some preprocessor macros and you only want to
1033 produce preprocessed source instead of an object file.
1035 To compile something manually, you can run OMK by @command{make
1036 V=2}. This will print all commands executed together with directory
1037 navigation messages. Find the command you want to execute manually in
1038 the output. To run it, you need to change the working directory to the
1039 correct one in the @file{_build} tree. The correct directory can be
1040 found in make output on the line @samp{Entering directory} preceding
1041 the desired command.
1044 Currently, C++ sources are supposed to have @file{.cc} or @file{.cxx}
1045 extensions. The @file{.cpp} extension is not supported (yet).
1048 @node Original README, OMK Development, OMK User's Manual, Top
1049 @chapter Original README
1051 Since this manual still doesn't cover all aspects of OMK, we include
1052 here a @file{README.rules} file, which was written for the first version
1055 @b{Important notice:} This make system uses features found in recent
1056 versions of GNU Make program. If you encounter problems with package
1057 building, check, that you use correct version of Make program. The
1058 Make older than version 3.80, could not be used. Even Make version
1059 3.80 has annoying bug which causes building fail with misleading
1060 message "virtual memory exhausted". Please, upgrade at least to
1061 version 3.81 of GNU Make.
1063 There is list of features which we want to solve with our make system:
1066 Central @file{Makefile.rules} for most of components of a bigger project.
1068 FIXME (our CAN framework includes more libraries common with our other
1069 projects, we need to separate some utility libraries etc.)
1071 The rules in more spread Makefiles are way to the hell (update for
1072 different kernel, RT-Linux etc would be nightmare in other case).
1074 Make system should allow to freely move cross-dependant components in
1075 directory structure without need to update users of moved component (I
1076 hate something like @option{-I../../sched/rtlshwq/include} in CAN makefiles for
1077 example. If a component is renamed or version is added to then name,
1078 all Makefiles in CAN will require update).
1080 Make system should be able to compile mutually cross-dependant
1081 libraries and should ensure, that change in one component sources or
1082 headers would result in relink or rebuild in components linked against
1083 that library or including modified header file.
1085 Make system has to enable compilation out of OCERA full source tree
1086 (we would lost many users of particular components in other case).
1088 Compile should be able to do all above work without need to install
1089 any files before successful finish of build.
1091 Because we use some libraries for RT-Linux build and user-space build,
1092 we need to solve how to compile from same sources to both targets.
1094 The build system should allow to call make for particular source
1095 subdirectory. Time of recursive make through all subdirectories is
1098 Make system should enable to build out of sources tree (else clean or
1099 working with CVS sandbox gets fussy and simultaneous multiple targets
1102 It would be good, if there is a possibility to call make from
1103 read-only media sources.
1105 Make system should store results of build in some separate directory
1106 structure to simple install and testing.
1108 Makefiles in sources directories should be simple.
1111 There is probably only one alternative fully supporting above requirements
1112 and it is GNU Autoheader...Automake...Autoconf... system.
1113 But it is complicated and requires big amount of support files.
1114 It would be acceptable if it could be easily used for OCERA framework.
1115 But there are important show stoppers for that system:
1118 It would require deep revision of all OCERA CVS contents and agreement
1119 on this would be problematic
1121 This system is not well prepared for dual compilation for Linux and
1122 RT-Linux sub-targets. It would mean many changes in default autoconf
1123 setup to support this. Probably simplest way would be to rebuild GCC
1124 tool chain for something like i586-elf-rtlinux. This would require
1125 even more space for OCERA development.
1128 The problem calls for some solution, which would have minimal impact
1129 on other components and would be elegant and would be maintainable
1130 and small, because our main goal is components development and not
1131 make systems development.
1133 There is result of our trial. It is OMK make system.
1134 The @file{Makefile} and @file{Makefile.omk} files should be in all source
1135 directories. Common @file{Makefile.rules} file is required in the toplevel
1136 sources directory. Alternatively this file could be moved
1137 to link tree pointing into readonly media or can be anywhere
1138 else if @code{MAKERULES_DIR} and @code{SOURCES_DIR} are specified.
1140 @c !!! tohle tam nejak zmizelo, mozna by to chtelo zkontrolovat, ze to
1141 @c sedi s aktualnim stavem
1144 Syntax of Makefile.omk files is for usual cases compatible
1145 to Automake's Makefile.am descriptions. There are specific targets
1146 for RT-Linux and Linux kernel related stuff
1148 Makefile.omk user defined variables
1151 list of subdirectories intended for make from actual directory
1153 list of the user-space libraries
1154 @item shared_LIBRARIES
1155 list of the user-space shared libraries
1156 @item kernel_LIBRARIES
1157 list of the kernel-space libraries
1158 @item rtlinux_LIBRARIES
1159 list of the RT-Linux kernel-space libraries
1160 @item include_HEADERS
1161 list of the user-space header files
1162 @item nobase_include_HEADERS
1163 headers copied even with directory part
1164 @item kernel_HEADERS
1165 list of the kernel-space header files
1166 @item rtlinux_HEADERS
1167 list of the RT-Linux kernel-space header files
1169 list of the require binary programs
1170 @item utils_PROGRAMS
1171 list of the development utility programs
1172 @item kernel_MODULES
1173 list of the kernel side modules/applications
1174 @item rtlinux_MODULES
1175 list of RT-Linux the kernel side modules/applications
1177 list of specific target sources
1179 additional include directories and defines for user-space
1180 @item kernel_INCLUDES
1181 additional include directories and defines for kernel-space
1182 @item rtlinux_INCLUDES
1183 additional include directories and defines for RT-Linux
1184 @item default_CONFIG
1185 list of default config assignments CONFIG_XXX=y/n ...
1188 The Makefile is same for all sources directories and is only 14 lines
1189 long. It is there only for convenience reasons to enable call "make"
1190 from local directory. It contains code which locates
1191 @file{Makefile.rules} in actual or any parent directory. With standard
1192 BASH environment it works such way, that if you get into sources
1193 directory over symbolic links, it is able to unwind yours steps back
1194 => you can make links to readonly media component directories, copy
1195 @file{Makefile.rules}, Makefile and toplevel Makefile.omk, adjust
1196 Makefile.omk to contain only required components and then call make in
1197 top or even directories after crossing from your tree to readonly
1200 The system compiles all files out of source directories. The actual
1201 version of system is adapted even for OCERA tree mode if
1202 @code{OCERA_DIR} variable is defined in @file{Makefile.rules}
1204 There are next predefined directory name components, which can be
1208 @item BUILD_DIR_NAME = _build
1209 prefix of directory, where temporary build files are stored
1210 @item COMPILED_DIR_NAME = _compiled
1211 prefix of directory, where final compilation results are stored
1212 @item GROUP_DIR_NAME = yyy
1213 this is used for separation of build sub-trees in OCERA environment
1214 where more @file{Makefile.rules} is spread in the tree
1217 Next directories are used:
1220 @item KERN_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern
1221 directory to store intermediate files for kernel-space targets
1222 @item USER_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
1223 directory to store intermediate files for user-space targets
1225 @item USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
1226 directory to store exported include files which should be installed later
1227 on user-space include path
1228 @item USER_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
1229 same for user-pace libraries
1230 @item USER_UTILS_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
1231 utilities for testing, which would not probably be installed
1232 @item USER_BIN_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
1233 binaries, which should go into directory on standard system PATH
1234 (/usr/local/bin, /usr/bin or $(prefix)/bin)
1236 @item KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern
1237 directory to store exported include files which should be installed later
1238 on kernel-space include path
1239 @item KERN_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern
1240 same for kernel-pace libraries
1241 @item KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules
1242 builded modules for Linux kernel or RT-Linux system
1245 There is more recursive passes through directories to enable
1246 mutual dependant libraries and binaries to compile.
1247 Next passes are defined
1250 @item default-config
1251 generates @file{config.omk-default} or xxx-default (FIXME) configuration file
1253 checks and creates required build directories
1255 copies header files to @code{USER_INCLUDE_DIR} and @code{KERN_INCLUDE_DIR}
1257 builds objects in USER_BUILD_DIR/@var{relative path} and creates libraries
1259 @item binary-pass and utils-pass
1260 links respective binaries in USER_@{BIN,UTILS@}_DIR directory. If some
1261 object file is missing it compiles it in USER_BUILD_DIR/@var{relative path}
1262 @item kernel-lib-pass
1263 builds libraries for kernel space targets
1265 builds kernel modules
1268 The amount of passes is relatively high and consumes some time. But
1269 only other way to support all required features is to assemble one big
1270 toplevel Makefile, which would contain all components and targets
1273 Drawbacks of designed make system
1276 the system is not as fast as we would like
1278 it lacks Autoconf and configure extensive support for many systems
1279 from UNIX to DOS and WINDOWS
1281 it does not contain support for checking existence of target
1282 libraries and functionalities as GNU Autoconf
1284 it is heavily dependant on GNU MAKE program. But it would not be big
1285 problem, because even many commercial applications distribute GNU MAKE
1286 with them to be able to work in non-friendly systems
1288 the key drawback is dependence on recent MAKE version 3.80 and better
1289 and even version 3.80 of MAKE has important bug, which has been
1290 corrected in newer sources (FIXME)
1293 The last point is critical. I have not noticed it first, because
1294 I use Slackware-9.2 and it contains latest released version
1295 of MAKE (version 3.80).
1296 The problem appears when I have tried to build bigger libraries.
1297 There is bug in version 3.80, which results in misleading
1298 error "Virtual memory exhausted". It is known bug with ID 1517
1301 * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
1305 I have optimized some rules to not push memory to the edge,
1306 but there could be still issues with 3.80 version.
1308 I have downloaded latest MAKE CVS sources. The compilation required
1309 separate lookup and download for .po files and full Autoheader... cycle.
1310 I have put together package similar to release. Only ./configure --prefix=...
1311 and make is required. CVS sources contains version 3.81beta1.
1312 You can download prepared sources archive from
1313 @indicateurl{http://paulandlesley.org/make/make-3.81beta1.tar.bz2}
1314 Or you can get our local copy from
1315 @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz}
1317 The archive contains even "make" binary build by me, which should work
1318 on other Linux distributions as well. Older version of MAKE (3.79.x
1319 released about year 2000) found on Mandrake and RedHat are not
1320 sufficient and do not support eval feature. I do not expect, that
1321 Debian would be more up-to-date or contain fixes to MAKE vm exhausted
1324 The local CTU archive with our CAN components prepared for inclusion
1325 into OCERA SF CVS could be found in my "can" directory
1327 @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz}
1329 The code should build for user-space with new make on most of Linux distros
1330 when make is updated.
1332 If you want to test compile for RT-Linux targets, line
1335 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
1338 in @file{Makefile.rules} has to be activated and updated
1339 to point RT-Linux directory containing "rtl.mk".
1340 There is only one library ("ulutrtl") and test utility compiled for RT-Linux
1341 (@file{can/utils/ulut/ul_rtlchk.c}).
1343 The next line, if enabled, controls compilation in OCERA project tree
1346 #OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
1349 The LinCAN driver has been updated to compile out of source directories.
1351 Please, check, if you could compile CAN package and help us with integration
1352 into OCERA SF CVS. Send your comments and objections.
1354 The OMK system has been adapted to support actual OCERA configuration process.
1355 I am not happy with ocera.mk mix of defines and poor two or three rules,
1356 but OMK is able to overcome that.
1358 The OMK system has integrated rules (default-config) to build default
1359 configuration file. The file is named @file{config.omk-default} for
1360 the stand-alone compilation. The name corresponds to OCERA config +
1361 "-default" if OCERA_DIR is defined. This file contains statements
1362 from all @code{default_CONFIG} lines in all @file{Makefile.omk}. The
1363 file should be used for building of own @file{config.omk} file, or as
1364 list for all options if Kconfig is used.
1366 @c @chapter OMK Reference
1368 @node OMK Development, Variable Index, Original README, Top
1369 @chapter OMK Development
1373 @node Variable Index, , OMK Development, Top
1374 @unnumbered Variable Index
1378 @c @node Concept Index, , Variable Index, Top
1379 @c @unnumbered Concept Index