1 \input texinfo @c -*-texinfo-*-
3 @setfilename omk-manual
4 @documentencoding UTF-8
5 @settitle OMK: Ocera Make System
9 Manual for Ocera Make System (OMK) version
12 Copyright @copyright{} 2007, 2008, 2009, 2010, 2011, 2013 Michal Sojka, Pavel Pisa
16 @title Ocera Make System Manual
18 @vskip 0pt plus 1filll
25 @node Top, Overview, (dir), (dir)
26 @top Ocera Make System
40 @node Overview, User's Manual, Top, Top
44 OMK is an advanced make system written entirely in GNU make. Compiling
45 software using OMK requires only GNU Make and standard UNIX
46 utilities (@command{sh}, @command{sed}, @command{cmp}, ...)
47 installed. OMK aims to be developer friendly; to use OMK, you do not
48 need to understand (sometimes) cryptic syntax of Makefiles.
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, Overview
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
118 @node Quick Start, History, Why to Use OMK?, Overview
121 If you get some sources, which are distributed with OMK, usually the
122 following commands are sufficient to compile the whole project.
131 @noindent To use OMK in your own project, follow these steps:
135 The newest version of OMK can be found at @uref{http://rtime.felk.cvut.cz/omk/}.
137 Take appropriate @file{Makefile.rules} (see @ref{Properties of Specific Makefile.rules}), put it together with leaf @file{Makefile}
138 to the root directory of your project.
140 Create @file{Makefile.omk} files in all directories you want to
141 compile something. Please refer to @ref{User's Manual} to learn
142 what to write in @file{Makefile.omk} files.
144 Run @command{make omkize} in the root directory.
147 @noindent Your project is now ready to compile.
150 @node History, , Quick Start, Overview
153 OMK was originally written by Pavel Píša as a solution to have one
154 common make system for OCERA project, where we needed to compile
155 user-space programs, Linux kernel modules and RT Linux modules in one
156 package. Although this system was not accepted for the whole OCERA
157 project. Several individual developers (mostly from Czech Technical
158 University) liked it and started to use it.
160 As a number of projects using OMK grew it was necessary to modularize
161 the make system to support more ``targets''. Michal Sojka took care
162 about the process of modularization.
164 @node User's Manual, Original README, Overview, Top
165 @chapter User's Manual
170 * Compiling Programs::
171 * Compiling Libraries::
173 * Recursing into Subdirectories::
174 * Dependency Tracking::
175 * Configuration and Conditional Compilation::
176 * Advanced OMK Features::
177 * Properties of Specific Makefile.rules::
178 * Running OMK under Windows OS::
179 * Interfacing OMK to popular IDEs::
183 @node Basic Concepts, Invoking OMK, User's Manual, User's Manual
184 @section Basic Concepts
186 The main concept of OMK is very simple. In the heart of OMK are two
187 files @file{Makefile.rules} and @file{Makefile.omk}. The former one
188 resides in project root directory and contains all compilation rules
189 needed for compilation of the particular project. There are different
190 @file{Makefile.rules} for different platforms (Unix, RTEMS, system-less,
191 ...). @file{Makefile.omk} is stored in every (sub)directory and
192 describes what should @command{make} perform in that directory (e.g.
193 compile a program from several source files). It uses declarative syntax
194 (assign values to variables) similar to Automake files
195 @file{Makefile.am}. The content of @file{Makefile.omk} is described in
196 the following sections.
198 Since @command{make} searches by default for a @file{Makefile} and not
199 for @file{Makefile.rules} or @file{Makefile.omk}, there
200 must@footnote{When USE_LEAF_MAKEFILES is set to @samp{n}, this
201 @file{Makefile} can be omitted in subdirectories.
202 @xref{USE_LEAF_MAKEFILES}.} be a small generic @file{Makefile} in every
203 directory, whose task is only to find @file{Makefile.rules} in the
204 actual or any parent directory and include it. This search is performed
205 only once at the beginning of compilation.
207 @c TODO: Pavel's note about qmake.
210 The compilation process itself is comprised of several @emph{passes}. Every
211 pass traverses the whole directory structure@footnote{In future, we are
212 planning some optimization that allows OMK to traverse the directories
213 only once and thus decrease compilation time.} and does a particular
214 task in every directory of the project. Typically, these passes are:
216 @anchor{include-pass}
218 This pass takes all include files marked for ``export'' and copies
219 (or links) them to the @file{include} directory under
220 @file{_compiled} directory. @xref{Header Files}.
222 Also, during this pass, automatically generated header file are
223 generated according to the current
224 configuration. @xref{Configuration and Conditional Compilation}.
226 During this pass, all include files are in place, so all libraries
229 Finally, programs can be compiled and linked against libraries
230 created in the previous pass.
233 The results of compilation are stored under the @file{_compiled}
234 directory. This directory is structured as a classical Unix file-system
235 (it contains directories like @file{bin}, @file{lib} and @file{include})
236 and can be directly copied to the target device or to some directory on
237 a host computer (e.g. @file{/usr/local}).
239 Besides @file{_compiled} directory, there in a @file{_build}
240 directory. Under this directory are stored some temporary files and
241 intermediate compilation products (object files, dependency files etc.).
243 In the next section, we provide an overview of methods, how to invoke
244 OMK from command line. Section @ref{Interfacing OMK to popular IDEs}
245 covers running of OMK from popular IDEs.
247 Sections @ref{Compiling Programs} through @ref{Configuration and
248 Conditional Compilation} deals with the content of
249 @file{Makefile.omk}. Its syntax in usual cases compatible to GNU
250 Automake's @file{Makefile.am} syntax. Also, the scheme for naming
251 variables was inspired by Automake so most OMK variables have the name
252 like @samp{@var{target}_@var{TYPE}}.
254 @node Invoking OMK, Compiling Programs, Basic Concepts, User's Manual
255 @section Invoking OMK
257 Before using OMK for the first time, you have to call:
259 @command{make default-config}
261 @noindent See @ref{Configuration and Conditional Compilation} for
262 details. If you forget to do this, OMK will notice you.
264 To compile the whole project or only some subtree of the project, call
268 @noindent in the appropriate directory.
270 To clean files in @file{_build} directory but not in @file{_compiled}
276 To clean the compilation completely, you can either remove
277 @file{_compiled} and @file{_build} directories manually, or call
279 @command{make distclean}
281 @noindent which does the same. This command removes these directories
282 even if you call it from a subdirectory.
284 To debug compilation problems, you can use @code{V} variable (see
290 You can also set values of some other variables on command line for
291 temporary change something. The example below compiles the code
292 temporarily with debugging information:
294 @command{make CFLAGS="-g -O0 -Wall"}
297 If your project uses an alternative make-system (e.g. Automake or custom
298 makefiles), it might be useful for you to use the command:
300 @command{make omkize}
302 @noindent This will find all @file{Makefile.omk} files in all subdirectories
303 and copies generic @file{Makefile} from the root directory to that
304 subdirectories. This way you can easily switch your project to use OMK.
310 If this variable equals to @samp{1}, the whole command lines for all
311 executed commands are displayed. When not set or zero, only short
312 messages are printed. Value of @samp{2} displays the whole command lines
313 as with @samp{1} and in addition directory navigation messages are
317 @node Compiling Programs, Compiling Libraries, Invoking OMK, User's Manual
318 @section Compiling Programs
320 To tell OMK to compile a program, you need to set some variables in
321 @file{Makefile.omk} (usually) in the directory where program sources are
324 In the example bellow program @command{test} will be compiled from
325 source @file{test.c}.
328 @verbatiminclude tests/programs/compile-a-single-source-c-program/Makefile.omk
331 @noindent The variables are:
333 @anchor{bin_PROGRAMS}
335 Contains a list of names (whitespace separated) of programs to be
336 compiled in this directory.
339 @anchor{test_PROGRAMS}
340 @defvar test_PROGRAMS
341 Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
342 stored in @file{bin-tests} directory instead of @file{bin}. This
343 variable is intended for various test programs not to be mixed with
347 @defvar utils_PROGRAMS
348 Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
349 stored in @file{bin-utils} directory instead of @file{bin}. This
350 variable is intended for various development utilities not to be mixed
351 with the final product.
355 For every program name @var{xxx} in @code{bin_PROGRAMS},
356 @code{test_PROGRAMS} or @code{utils_PROGRAMS}, this variable contains
357 a list of sources that are needed to compile the program. OMK uses an
358 extension of the filename to determine the compiler to compile this
363 This variable contains a list of libraries the program @var{xxx} will
371 @defvar lib_LOADLIBES
372 This variable contains a list of libraries which needs to be linked to
373 to all programs or shared libraries in this directory.
377 This variable contains a list linker switches to load additional
378 libraries. You usually specify here -L and -l switches.
380 Note: The value of this variable is not used used by OMK for any purpose
381 other than linker invocation. Therefore dependency handling of shared
382 libraries does not work if the library is specified in LOADLIBES
383 instead of lib_LOADLIBES.
386 @node Compiling Libraries, Compiler Flags, Compiling Programs, User's Manual
387 @section Compiling Libraries
390 With OMK, you can easily create statically or dynamically linked
391 libraries. The way of creating libraries is very similar to how programs
392 are created. @xref{Compiling Programs}.
394 In @file{Makefile.omk}, you specify several variables, which defines how
395 the libraries should be compiled. In the example below the library
396 @samp{mylib} (full filename will be @file{libmylib.a}) is created from
397 two sources @file{funca.c} and @file{funcb.c}. Interface of this library
398 is defined in @file{myfunc.h}. Therefore, we export this header for use
402 @verbatiminclude tests/libraries/static-library/Makefile.omk
405 @noindent Variables for use with libraries are:
407 @defvar lib_LIBRARIES
408 Specifies a list of statically linked libraries to be compiled. OMK
409 automatically prepends @code{lib} prefix library names.
412 @defvar shared_LIBRARIES
413 Specifies a list of dynamically linked libraries to be compiled.
417 For every library name @var{xxx} in @code{lib_LIBRARIES} or
418 @code{shared_LIBRARIES}, this variable contains a list of sources that
419 are needed to compile the library. OMK uses an extension of the
420 filename to determine the compiler to compile this source.
427 @node Header Files, , Compiling Libraries, Compiling Libraries
428 @subsection Header Files
430 C and C++ libraries are not very useful without header files. OMK
431 provides several variables that control operations with header files.
433 During compilation, header files are copied (or linked by symbolic
434 links) from source directories to the @file{_compiled} tree (see
435 @ref{include-pass}). Libraries and programs are then compiled against
436 these copies. The following variables control which headers are copied
437 and what is their destination file name.
439 @anchor{include_HEADERS}
440 @defvar include_HEADERS
441 Specifies the list of header files to be exported for use by other
442 libraries/programs. The files are exported directly to the
443 @file{include} directory even if the file is located in a subdirectory
444 (like @file{sci_regs.h} in the example below)
447 include_HEADERS = regs.h periph/sci_regs.h
451 @defvar nobase_include_HEADERS
452 Similar to @ref{include_HEADERS}, but the directory prefix is always
453 kept. To include the file exported by this variable, use
454 @code{#include <@var{prefix}/@var{header.h}>}.
457 @defvar renamed_include_HEADERS
458 Exports the header files under different name. The form of the items
459 in this whitespace separated list is: @var{real name}@code{->}@var{new
463 renamed_include_HEADERS = orte_config_omk_win32.h->orte_config.h
468 If this variable equals to @samp{y}, symbolic links to headers in
469 source directories are used in @file{_compiled} tree instead of
472 Normally, the header files are copied into @file{_compiled} directory
473 to be prepared for transfer into target location afterwards. Copying
474 ensures that resulting libraries are in correspondence with the header
475 files even if the header is changed by a developer but the library is
478 @c Another reason for having single include directory for the whole
479 @c project is tat every component knows where to find header files of
482 On the other side, the copying could make problems during
483 development. Most @acronym{IDE}s, allows you to jump directly to the
484 place, where an error is reported by the compiler. If the error is in
485 a header file, IDE opens you the copy of the header file. If you
486 correct the error there, after the next compilation, your header file
487 will be overwritten by the old version from your source tree.
489 This option is not typically used in @file{Makefile.omk}, but in the
490 top level configuration file @file{config.omk} or on command line.
493 @node Compiler Flags, Recursing into Subdirectories, Compiling Libraries, User's Manual
494 @section Compiler Flags
496 OMK follows the same philosophy for flag variables as does Automake. The
497 variables with AM_ prefix (e.g. AM_CPPFLAGS) are supposed to be used by
498 the package developer and variable without that prefix (e.g. CPPFLAGS)
499 are reserved for the user. The following
502 Preprocessor switches.
511 Directives passed to the C or C++ compiler with additional directories
512 to be searched for header files. In most cases you need to specify an
513 absolute path. To specify a directory relative to the source
514 directory, you can use the @code{$(SOURCES_DIR)} variable, which
515 refers to the directory, where @file{Makefile.omk} is located. This
516 variable applies to all compilations invoked in the current directory.
519 INCLUDES = -I$(SOURCES_DIR)/my_include_dir
524 Directives passed to the C or C++ compiler with preprocessor macro
525 definitions. This variable applies to all compilations invoked in the
533 @c FIXME: INCLUDES variable should not be set by rtlinux rules.
535 @node Recursing into Subdirectories, Dependency Tracking, Compiler Flags, User's Manual
536 @section Recursing into Subdirectories
538 OMK is probably most useful in projects consisting of multiple
539 directories. For such projects, it is not easy to write from scratch
540 classic Makefiles that provides all the needed features.
542 You can instruct OMK to descend to a (sub)directory by setting the
543 @code{SUBDIRS} variable in @file{Makefile.omk}.
547 This variable contains a list of directories, in which compilation
548 must be also invoked. Usually, names of subdirectories are used, but
549 you can use any path specification here.
551 Compilation is invoked in these directories before it is invoked in
552 the current directory.
554 See also @ref{AUTOMATIC_SUBDIRS}.
556 @c TODO: Write tests for this.
558 @anchor{ALL_OMK_SUBDIRS}
559 @defvar ALL_OMK_SUBDIRS
560 This variable is set by OMK and can be used as the value of
561 @code{SUBDIRS} variable. It contains a list of all direct
562 subdirectories, which contain @file{Makefile.omk}. This is especially
563 useful if you are combining several projects or components
564 together. In the root directory of your project, you just create
565 symbolic links the components from other projects and all the linked
566 directories automatically appears as the value of this variable.
569 SUBDIRS = $(ALL_OMK_SUBDIRS)
573 @anchor{AUTOMATIC_SUBDIRS}
574 @defvar AUTOMATIC_SUBDIRS
575 If this variable is set to @samp{y} and @code{SUBDIRS} is not assigned
576 in @file{Makefile.omk}, then @code{SUBDIRS} is assigned a default
577 value @code{$(ALL_OMK_SUBDIRS)}.
580 @node Dependency Tracking, Configuration and Conditional Compilation, Recursing into Subdirectories, User's Manual
581 @section Dependency Tracking
583 OMK automatically tracks dependencies of files in the project.
584 Dependencies of object files are produced with gcc's @option{-M@var{x}}
585 options. This means that whenever a header file is changed, OMK
586 recompiles only those files, which included that file.
588 Dependencies are also maintained for libraries and binaries. To find the
589 dependencies, OMK parses linker map files, so a change to some library
590 causes relinking of all programs using that library.
592 @node Configuration and Conditional Compilation, Advanced OMK Features, Dependency Tracking, User's Manual
593 @section Configuration and Conditional Compilation
595 In many projects, it is necessary to configure the compilation process. By
596 this configuring we mean, setting some parameters that influence the
597 output of compilation process. In GNU projects, @command{configure}
598 script is usually responsible for configuration. User provides some
599 parameters to @command{configure}, which is run before compilation, and
600 this script does all steps needed to configure the sources and
601 make-system in the desired way.
603 OMK has its own configuration mechanism, which is described in this
604 section. For future releases, we plan that this mechanism can make use
605 of GNU Autoconf, but currently there is no directly integrated support
608 There exist three different configuration files
609 @file{config.omk-default}, @file{config.target} and
610 @file{config.omk}. All of these have to be stored in the same directory
611 as @file{Makefile.rules}. During compilation, these files are included
612 in @file{Makefile.rules} in this order which means that variables
613 assigned in the former files are overridden by those from later
614 ones. All settings specified here apply to the whole compilation
615 tree. Each file is intended for a different kind of configuration
618 @item config.omk-default
619 Stores default configuration of compiled components. This file is
620 automatically generated (see below) and should not be edited by users.
622 Stores default configuration for a project or target hardware. This
623 file is intended to be stored in a version control system and should
624 be modified only by the maintainer of the project.
626 For cross compiled projects, this file typically contains settings of
627 variables like @var{CC} and @var{CFLAGS}.
629 This is a file for end users, where any default settings set in the
630 above files can be overridden. This file should not be stored in
631 version control system. The project should compile without having this
635 Besides variables defined in @file{config.target}, @file{Makefile.omk}
636 in any subdirectory can specify some configuration parameters. When
637 @command{make default-config} is run, all these parameters are found and
638 together with their default values are stored as makefile variables in
639 @file{config.omk-default}. This file is included during compilation, so
640 if you don't specify other values, these defaults are used. If you are
641 not satisfied with these defaults, you can override the values of
642 parameters either locally for your build in @file{config.omk} or
643 globally for all people working with the project in
644 @file{config.target}.
647 * Specifying Configuration Parameters::
648 * Using Configuration Parameters::
652 @node Specifying Configuration Parameters, Using Configuration Parameters, Configuration and Conditional Compilation, Configuration and Conditional Compilation
653 @subsection Specifying Configuration Parameters
655 To specify names and default values of configuration parameters use the
656 @code{default_CONFIG} variable in @file{Makefile.omk}.
658 @defvar default_CONFIG
659 This variable contains a list of configuration parameters and their
660 default values. The format of every item in this list is
661 @var{CONFIG_xxxx}=@var{value}. You can name the parameter as you want,
662 but it is good practice to start the name with @samp{CONFIG_} prefix.
664 OMK can automatically generate header files, with C preprocessor macro
665 definitions according to the OMK's configuration parameters. The
666 actual content of generated header files depends on the form of the
667 @var{value}. The possible forms are:
670 @item @samp{y}, @samp{n} or @samp{x}
671 This defines boolean parameters. If the value of the parameter is
672 @samp{y}, the @samp{#define CONFIG_@var{xxx} 1} is generated, if it is
673 @samp{n}, no @code{#define} is generated.
675 @samp{x} is a special value called @emph{recessive 'n'}. The meaning
676 is that this parameter influences the component in the current
677 directory (i.e. the corresponding @code{#define} will be included in
678 @code{LOCAL_CONFIG_H}; see @ref{LOCAL_CONFIG_H}) but the default value
679 is not specified here. If the default value is not specified anywhere,
680 the behavior is the same as if @samp{n} is specified.
682 Numeric parameters. The define looks like @samp{#define CONFIG_@var{xxx} @var{number}}
684 Text without quotes. The define looks like @samp{#define CONFIG_@var{xxx} @var{text}}
686 Text with quotes. The define looks like @samp{#define CONFIG_@var{xxx} "@var{text}"}
690 @noindent Example of using @code{default_CONFIG}. @file{Makefile.omk} reads like:
692 @verbatiminclude tests/default-config/Makefile.omk
694 @noindent and @file{subdir/Makefile.omk} like:
696 @verbatiminclude tests/default-config/subdir/Makefile.omk
699 @noindent After running @command{make default-config}, the content of
700 @file{config.omk-default} will be:
702 @verbatiminclude tests/default-config/config.omk-correct
705 @node Using Configuration Parameters, Common Variables, Specifying Configuration Parameters, Configuration and Conditional Compilation
706 @subsection Using Configuration Parameters
708 Configuration parameters can be used in two ways:
711 as variables in @file{Makefile.omk} and
713 as C/C++ preprocessor macros in OMK generated header files.
716 @noindent For the first use, your @file{Makefile.omk} may contain something like:
718 SUBDIRS = arch/$(CONFIG_ARCH)
720 ifeq ($(CONFIG_DEBUG),y)
721 DEFS += -DUSE_SIMULATOR
725 @noindent For the second use, there are several variables that control
726 the generation of header files with configuration values. These
727 variables are described here:
729 @anchor{LOCAL_CONFIG_H}
730 @defvar LOCAL_CONFIG_H
731 The value of this variable is the name of a header file, which will
732 contain all configuration parameters declared in the current directory
733 by @code{default_CONFIG}. This header file is accessible only by files
734 in the current directory and it should be included like @code{#include
737 In @file{Makefile.omk}, the use of this variable can look like this:
740 LOCAL_CONFIG_H = myconfig.h
744 @defvar config_include_HEADERS
745 This variable is similar to @code{LOCAL_CONFIG_H}. One difference is
746 that the generated header file is accessible to all sub-projects in
747 all directories, not only to the files in the same directory (the
748 header is stored in @file{_compiled} tree). The second difference is
749 that you have to specify, which configuration parameters you want to
750 appear in the header file.
754 This variable determines the configuration parameters that should be
755 stored in a header file specified by
756 @code{config_include_HEADERS}. The @var{xxx} in the name of this
757 variable needs to be the same as the base name (without extension) of
761 @noindent Example of using @code{config_include_HEADERS}:
763 default_CONFIG = CONFIG_LINCAN=y CONFIG_LINCANRTL=n CONFIG_LINCANVME=n
764 config_include_HEADERS = global.h
765 global_DEFINES = CONFIG_OC_LINCAN CONFIG_OC_LINCANRTL
768 @noindent Here, we include only two out of the three configuration
769 parameters defined in the current @file{Makefile.omk}. It is also
770 possible to include configuration parameters defined in a different
773 @node Common Variables, , Using Configuration Parameters, Configuration and Conditional Compilation
774 @subsection Common Variables
776 It is common practice to use @file{config.target} or @file{config.omk}
777 to store project-wide settings. Here is the list of variables, which are
778 commonly set here (but they can also be set elsewhere, e.g. in
779 @file{Makefile.omk}).
781 You can easily ``reconfigure'' your project by changing the
782 @file{config.omk} file. It is useful to have several configurations
783 stored in different files and let @file{config.omk} be a symbolic link
784 to the desired configuration.
788 The name of C compiler.
790 Command line options for C compiler.
792 The name of C++ compiler.
794 Additional parameters (besides @code{CFLAGS}) to by passed to C++
798 @node Advanced OMK Features, Properties of Specific Makefile.rules, Configuration and Conditional Compilation, User's Manual
799 @section Advanced OMK Features
801 In this section we list several OMK features, which are more complicated
802 or rarely used so they were omitted in previous sections.
805 * Organization of the Source Tree::
806 * Additional Variables::
807 * Adding Hooks to Passes::
808 * Integration of Wvtest Framework::
811 @node Organization of the Source Tree, Additional Variables, Advanced OMK Features, Advanced OMK Features
812 @subsection Organization of the Source Tree
816 The @file{_compiled} directory can be shared between multiple projects
817 (by using symbolic links).
820 If you work on a bigger project, you usually don't need to rebuild the
821 whole project and call @command{make} only in a
822 subdirectory. Sometimes, it might be useful to rebuild the whole
823 project. You can either change working directory to the root of your
824 project and call @command{make} there or, as a shortcut, you can use
825 @code{W} variable (see @ref{W}) to compile everything directly from a
832 Searching for @file{Makefile.rules} works such way, that if you get
833 into sources directory over symbolic links, OMK is able to unwind your
834 steps back. This implies you can make links to component directories
835 on read-only media, copy @file{Makefile.rules}, @file{Makefile} and
836 top-level @file{Makefile.omk}, adjust @file{Makefile.omk} to contain
837 only required components and then call @command{make} in the top
838 directory or even in read-only directories after changing working
839 directory from your tree to the readonly media.
845 If this variable equals to @samp{1}, the @b{whole} project is
846 (re)compiled, even if @command{make} is called from a subdirectory.
849 @node Additional Variables, Adding Hooks to Passes, Organization of the Source Tree, Advanced OMK Features
850 @subsection Additional Variables
852 @anchor{USE_LEAF_MAKEFILES}
853 @defvar USE_LEAF_MAKEFILES
854 If this variable equals to @samp{n} (default is unset), then OMK uses
855 the leaf @file{Makefile} only when it is invoked by simple
856 @command{make} command. Later, during recursive directory descent leaf
857 @file{Makefile} is not used and @file{Makefile.rules} is included
860 This feature is useful if you are integrating some non-OMK project into
861 your project. You only add @file{Makefile.omk} files to the non-OMK
862 project and don't need to modify project's original Makefiles.
864 This variable can be set either globally in a @file{config.*} file or
865 locally in some @file{Makefile.omk}. In the latter case, it influences
866 only subdirectories of the directory containing @file{Makefile.omk}.
871 This variable is set internally by OMK and its value is the absolute
872 path to the directory with compiled sources. It can be used if you need
873 to refer to sources files in some custom constructs in
877 include_HEADERS = $(notdir $(wildcard $(SOURCES_DIR)/*.h))
883 The same as @ref{SOURCES_DIR}. Provided for Automake compatibility.
886 @defvar{MAKERULES_DIR}
887 This variable is set internally by OMK and its value is the absolute
888 path to the directory containing @file{Makefile.rules} currently used
892 @defvar{OMK_RULES_TYPE}
893 Identification the type of @file{Makefile.rules} used for
894 compilation. Values are like @samp{linux}, @samp{rtems}, @samp{sysless},
895 ... This variable is automatically generated during creation of
896 @file{Makefile.rules} and can be used in configuration files (see
897 @ref{Configuration and Conditional Compilation}) or in
898 @file{Makefile.omk} to tweak compilation for specific targets.
901 @node Adding Hooks to Passes, Integration of Wvtest Framework, Additional Variables, Advanced OMK Features
902 @subsection Adding Hooks to Passes
904 Sometimes it is necessary to run some special commands as a part of
905 compilation. Typical example might be a tool which generates source
906 files on the fly. OMK supports calling additional commands during
907 compilation by so called @emph{pass hooks}. A pass hook is an ordinary
908 make target which is invoked as part of compilation during a particular
909 pass (see @ref{passes}). Pass hooks can be defined by assigning their
910 names to @code{xxx_HOOKS} variable.
913 Specifies one or more hooks (make targets) which are invoked during pass
914 @var{xxx}. The working directory of commands or this target is under the
917 In the example bellow header file @file{generated_header.h} is created
918 during @samp{include-pass} by @file{convert_data} program. The program
919 takes @file{data_file.txt} in the source directory as the input and
920 creates the header file in the in the correct directory under the
924 include-pass_HOOKS = generated_header.h
926 generated_header.h: $(SOURCES_DIR)/data_file.txt
927 convert_data < $^ > $@@
931 @node Integration of Wvtest Framework, , Adding Hooks to Passes, Advanced OMK Features
932 @subsection Integration of Wvtest Framework
934 OMK has integrated support for
935 @uref{https://github.com/apenwarr/wvtest,Wvtest unit testing framework}.
936 It is a very minimalistic framework whose integration with OMK does not
937 impose almost any particular policy of writing the tests. Wvtest tests
938 are specified by the following two variables:
940 @defvar wvtest_PROGRAMS
941 This variable has the same meaning as @ref{test_PROGRAMS} with two
942 exceptions: (1) the program is automatically linked with the library
943 specified by @code{WVTEST_LIBRARY} variable and (2) the program is
944 automatically executed by @command{make wvtest} (see below).
947 @defvar wvtest_SCRIPTS
948 Defines the name of a script (e.g. shell script) which is executed by
949 @command{make wvtest}. Write the scripts so, that they can be run from
950 arbitrary directory, i.e. in the case of shell scripts ensure that the
951 @file{wvtest.sh} library is sourced like this:
953 @code{. $(dirname $0)/wvtest.sh}
957 @defvar WVTEST_LIBRARY
958 Specifies the name of the library that is automatically linked with
959 @code{wvtest_PROGRAMS}. The default is @file{wvtest}.
962 There is also an OMK pass called @code{wvtest-pass} which consecutively
963 runs all @code{wvtest_PROGRAMS} and @code{wvtest_SCRIPTS} in the
964 traversed subdirectories of the current directory. Every program or
965 script is executed in a temporary directory under @file{_build}
966 directory with @code{PATH} variable modified to include
967 @file{_compiled/bin} as the first component and @code{LD_LIBRARY_PATH}
968 modified to include @file{_compiled/lib} as the first component. This
969 allows the tests to run the @code{bin_PROGRAMS} without explicitly
970 specifying their full path and to use shared libraries without the path
973 When make is invoked as @command{make wvtest} it runs @command{make
974 wvtest-pass} under the control of @file{wvtestrun} script, which must be
975 present in the same directory as @file{Makefile.rules}. This script
976 suppresses the normal output of passed tests and prints only their
977 summary. For failed tests, the full output is shown. Additionally, when
978 the output is written to a terminal, the status of each test is
979 displayed in color for easy inspection.
981 @node Properties of Specific Makefile.rules, Running OMK under Windows OS, Advanced OMK Features, User's Manual
982 @section Properties of Specific Makefile.rules
984 In previous sections, general properties of @file{Makefile.rules} were
985 documented. This section contains documentation to features found only
986 in some particular @file{Makefile.rules}.
994 @node Linux, System-Less, Properties of Specific Makefile.rules, Properties of Specific Makefile.rules
997 This @file{Makefile.rules} is used not only for Linux as the name
998 suggests, but also for other Unices and even for Windows.
1001 The name of the operating system (OS) where make was invoked.
1005 Should specify the name of OS where the resulting binary should be
1006 used. If not specified manually, it equals to BUILD_OS.
1010 Lists subdirectories with QT project (.pro) file. OMK will generate
1011 there @file{Makefile} by calling @command{qmake} with correct
1012 parameters to interface QT application to the rest of the compilation
1013 tree. Then @command{make} is called there to compile QT
1014 application. Variable @samp{QTDIR} must be set to the directory with
1015 QT installation (e.g. /usr/share/qt4 on Debian).
1019 Lists the names of the files (persumably scripts) to be copied to
1020 @file{_compiled/bin}.
1025 @node System-Less, RTEMS, Linux, Properties of Specific Makefile.rules
1026 @subsection System-Less
1028 This @file{Makefile.rules} is designed for compilation of code for
1029 (small) micro-controllers without operating systems. See
1030 @uref{http://rtime.felk.cvut.cz/hw/index.php/System-Less_Framework} for
1031 more information about our framework, which uses this rules.
1033 @node RTEMS, , System-Less, Properties of Specific Makefile.rules
1039 @node Running OMK under Windows OS, Interfacing OMK to popular IDEs, Properties of Specific Makefile.rules, User's Manual
1040 @section Running OMK under Windows OS
1042 It is possible to use OMK under Windows OS with MinGW (see
1043 @uref{http://www.mingw.org/}). Unfortunately, the compilation speed is
1044 much lower than on UNIX systems.
1046 TODO: Is it necessary to install anything special?
1048 @node Interfacing OMK to popular IDEs, Troubleshooting, Running OMK under Windows OS, User's Manual
1049 @section Interfacing OMK to popular IDEs
1057 @node KDevelop, Eclipse/CDT, Interfacing OMK to popular IDEs, Interfacing OMK to popular IDEs
1058 @subsection KDevelop
1060 KDevelop has support for custom build systems. To use KDevelop to
1061 develop projects using OMK follow these steps. These steps are valid for
1062 version 3.5.0 of KDevelop, but for previous versions it doesn't differ
1067 Import project to KDevelop (from menu choose @emph{Project---Import
1068 existing project}). Select the type of project to @emph{Generic C
1069 Application (Custom Buildsystem)}.
1075 Then answer to following dialogs as you want.
1080 @image{kdevelop3} @image{kdevelop4}
1084 If you are working only on some small part of the bigger project, you
1085 usually don't want to recompile the whole project every time. In
1086 @emph{Project---Project Options}, you can specify the subdirectory where to
1093 If you want to switch between several configurations easily (see also
1094 @ref{Configuration and Conditional Compilation}), in the same dialog
1095 you can add @option{-e} to make options. This makes environment variables
1096 have higher precedence than those in @file{config.omk-default}. Then,
1097 you can define several environments with different
1098 @code{CONFIG_@var{xxx}} variables and their values.
1104 You can easily switch the configurations from @emph{Build---Make
1111 @node Eclipse/CDT, Emacs/Vim/etc., KDevelop, Interfacing OMK to popular IDEs
1112 @subsection Eclipse/CDT
1114 @node Emacs/Vim/etc., , Eclipse/CDT, Interfacing OMK to popular IDEs
1115 @subsection Emacs, VIM, etc.
1117 Since OMK compilation is started by executing @command{make} command,
1118 many common editors can work easily with OMK.
1120 Under Emacs, you can use @command{compile} or @command{recompile}
1121 commands as you are used to do.
1123 @node Troubleshooting, , Interfacing OMK to popular IDEs, User's Manual
1124 @section Troubleshooting & Knows Bugs
1128 If you rename some file or directory and then you can't compile your
1129 project, call @command{make clean} in the directory with errors. The
1130 reason for this behavior is that OMK remembers dependencies of every
1131 file. After renaming something, the original name is still stored in
1132 dependencies, but make doesn't know how to create this non-existent
1136 Sometimes, you may want to compile one file the same way as OMK does
1137 it, but run the compilation manually from command line. For example,
1138 you want to debug some preprocessor macros and you only want to
1139 produce preprocessed source instead of an object file.
1141 To compile something manually, you can run OMK by @command{make
1142 V=2}. This will print all commands executed together with directory
1143 navigation messages. Find the command you want to execute manually in
1144 the output. To run it, you need to change the working directory to the
1145 correct one in the @file{_build} tree. The correct directory can be
1146 found in make output on the line @samp{Entering directory} preceding
1147 the desired command.
1150 Currently, C++ sources are supposed to have @file{.cc} or @file{.cxx}
1151 extensions. The @file{.cpp} extension is not supported (yet).
1154 Removing of library source file does not cause the library to be
1155 rebuild. You need to manually delete the library or run @command{make
1156 distclean} before you run @command{make}.
1159 @node Original README, Development, User's Manual, Top
1160 @chapter Original README
1162 Since this manual still doesn't cover all aspects of OMK, we include
1163 here a @file{README.rules} file, which was written for the first version
1166 @b{Important notice:} This make system uses features found in recent
1167 versions of GNU Make program. If you encounter problems with package
1168 building, check, that you use correct version of Make program. The
1169 Make older than version 3.80, could not be used. Even Make version
1170 3.80 has annoying bug which causes building fail with misleading
1171 message "virtual memory exhausted". Please, upgrade at least to
1172 version 3.81 of GNU Make.
1174 There is list of features which we want to solve with our make system:
1177 Central @file{Makefile.rules} for most of components of a bigger project.
1179 FIXME (our CAN framework includes more libraries common with our other
1180 projects, we need to separate some utility libraries etc.)
1182 The rules in more spread Makefiles are way to the hell (update for
1183 different kernel, RT-Linux etc would be nightmare in other case).
1185 Make system should allow to freely move cross-dependant components in
1186 directory structure without need to update users of moved component (I
1187 hate something like @option{-I../../sched/rtlshwq/include} in CAN makefiles for
1188 example. If a component is renamed or version is added to then name,
1189 all Makefiles in CAN will require update).
1191 Make system should be able to compile mutually cross-dependant
1192 libraries and should ensure, that change in one component sources or
1193 headers would result in relink or rebuild in components linked against
1194 that library or including modified header file.
1196 Make system has to enable compilation out of OCERA full source tree
1197 (we would lost many users of particular components in other case).
1199 Compile should be able to do all above work without need to install
1200 any files before successful finish of build.
1202 Because we use some libraries for RT-Linux build and user-space build,
1203 we need to solve how to compile from same sources to both targets.
1205 The build system should allow to call make for particular source
1206 subdirectory. Time of recursive make through all subdirectories is
1209 Make system should enable to build out of sources tree (else clean or
1210 working with CVS sandbox gets fussy and simultaneous multiple targets
1213 It would be good, if there is a possibility to call make from
1214 read-only media sources.
1216 Make system should store results of build in some separate directory
1217 structure to simple install and testing.
1219 Makefiles in sources directories should be simple.
1222 There is probably only one alternative fully supporting above requirements
1223 and it is GNU Autoheader...Automake...Autoconf... system.
1224 But it is complicated and requires big amount of support files.
1225 It would be acceptable if it could be easily used for OCERA framework.
1226 But there are important show stoppers for that system:
1229 It would require deep revision of all OCERA CVS contents and agreement
1230 on this would be problematic
1232 This system is not well prepared for dual compilation for Linux and
1233 RT-Linux sub-targets. It would mean many changes in default autoconf
1234 setup to support this. Probably simplest way would be to rebuild GCC
1235 tool chain for something like i586-elf-rtlinux. This would require
1236 even more space for OCERA development.
1239 The problem calls for some solution, which would have minimal impact
1240 on other components and would be elegant and would be maintainable
1241 and small, because our main goal is components development and not
1242 make systems development.
1244 There is result of our trial. It is OMK make system.
1245 The @file{Makefile} and @file{Makefile.omk} files should be in all source
1246 directories. Common @file{Makefile.rules} file is required in the toplevel
1247 sources directory. Alternatively this file could be moved
1248 to link tree pointing into readonly media or can be anywhere
1249 else if @code{MAKERULES_DIR} and @code{SOURCES_DIR} are specified.
1251 @c !!! tohle tam nejak zmizelo, mozna by to chtelo zkontrolovat, ze to
1252 @c sedi s aktualnim stavem
1255 Syntax of Makefile.omk files is for usual cases compatible
1256 to Automake's Makefile.am descriptions. There are specific targets
1257 for RT-Linux and Linux kernel related stuff
1259 Makefile.omk user defined variables
1262 list of subdirectories intended for make from actual directory
1264 list of the user-space libraries
1265 @item shared_LIBRARIES
1266 list of the user-space shared libraries
1267 @item kernel_LIBRARIES
1268 list of the kernel-space libraries
1269 @item rtlinux_LIBRARIES
1270 list of the RT-Linux kernel-space libraries
1271 @item include_HEADERS
1272 list of the user-space header files
1273 @item nobase_include_HEADERS
1274 headers copied even with directory part
1275 @item kernel_HEADERS
1276 list of the kernel-space header files
1277 @item rtlinux_HEADERS
1278 list of the RT-Linux kernel-space header files
1280 list of the require binary programs
1281 @item utils_PROGRAMS
1282 list of the development utility programs
1283 @item kernel_MODULES
1284 list of the kernel side modules/applications
1285 @item rtlinux_MODULES
1286 list of RT-Linux the kernel side modules/applications
1288 list of specific target sources
1290 additional include directories and defines for user-space
1291 @item kernel_INCLUDES
1292 additional include directories and defines for kernel-space
1293 @item rtlinux_INCLUDES
1294 additional include directories and defines for RT-Linux
1295 @item default_CONFIG
1296 list of default config assignments CONFIG_XXX=y/n ...
1299 The Makefile is same for all sources directories and is only 14 lines
1300 long. It is there only for convenience reasons to enable call "make"
1301 from local directory. It contains code which locates
1302 @file{Makefile.rules} in actual or any parent directory. With standard
1303 BASH environment it works such way, that if you get into sources
1304 directory over symbolic links, it is able to unwind yours steps back
1305 => you can make links to readonly media component directories, copy
1306 @file{Makefile.rules}, Makefile and toplevel Makefile.omk, adjust
1307 Makefile.omk to contain only required components and then call make in
1308 top or even directories after crossing from your tree to readonly
1311 The system compiles all files out of source directories. The actual
1312 version of system is adapted even for OCERA tree mode if
1313 @code{OCERA_DIR} variable is defined in @file{Makefile.rules}
1315 There are next predefined directory name components, which can be
1319 @item BUILD_DIR_NAME = _build
1320 prefix of directory, where temporary build files are stored
1321 @item COMPILED_DIR_NAME = _compiled
1322 prefix of directory, where final compilation results are stored
1323 @item GROUP_DIR_NAME = yyy
1324 this is used for separation of build sub-trees in OCERA environment
1325 where more @file{Makefile.rules} is spread in the tree
1328 Next directories are used:
1331 @item KERN_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern
1332 directory to store intermediate files for kernel-space targets
1333 @item USER_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
1334 directory to store intermediate files for user-space targets
1336 @item USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
1337 directory to store exported include files which should be installed later
1338 on user-space include path
1339 @item USER_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
1340 same for user-pace libraries
1341 @item USER_UTILS_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
1342 utilities for testing, which would not probably be installed
1343 @item USER_BIN_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
1344 binaries, which should go into directory on standard system PATH
1345 (/usr/local/bin, /usr/bin or $(prefix)/bin)
1347 @item KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern
1348 directory to store exported include files which should be installed later
1349 on kernel-space include path
1350 @item KERN_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern
1351 same for kernel-pace libraries
1352 @item KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules
1353 builded modules for Linux kernel or RT-Linux system
1356 There is more recursive passes through directories to enable
1357 mutual dependant libraries and binaries to compile.
1358 Next passes are defined
1361 @item default-config
1362 generates @file{config.omk-default} or xxx-default (FIXME) configuration file
1364 checks and creates required build directories
1366 copies header files to @code{USER_INCLUDE_DIR} and @code{KERN_INCLUDE_DIR}
1368 builds objects in USER_BUILD_DIR/@var{relative path} and creates libraries
1370 @item binary-pass and utils-pass
1371 links respective binaries in USER_@{BIN,UTILS@}_DIR directory. If some
1372 object file is missing it compiles it in USER_BUILD_DIR/@var{relative path}
1373 @item kernel-lib-pass
1374 builds libraries for kernel space targets
1376 builds kernel modules
1379 The amount of passes is relatively high and consumes some time. But
1380 only other way to support all required features is to assemble one big
1381 toplevel Makefile, which would contain all components and targets
1384 Drawbacks of designed make system
1387 the system is not as fast as we would like
1389 it lacks Autoconf and configure extensive support for many systems
1390 from UNIX to DOS and WINDOWS
1392 it does not contain support for checking existence of target
1393 libraries and functionalities as GNU Autoconf
1395 it is heavily dependant on GNU MAKE program. But it would not be big
1396 problem, because even many commercial applications distribute GNU MAKE
1397 with them to be able to work in non-friendly systems
1399 the key drawback is dependence on recent MAKE version 3.80 and better
1400 and even version 3.80 of MAKE has important bug, which has been
1401 corrected in newer sources (FIXME)
1404 The last point is critical. I have not noticed it first, because
1405 I use Slackware-9.2 and it contains latest released version
1406 of MAKE (version 3.80).
1407 The problem appears when I have tried to build bigger libraries.
1408 There is bug in version 3.80, which results in misleading
1409 error "Virtual memory exhausted". It is known bug with ID 1517
1412 * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
1416 I have optimized some rules to not push memory to the edge,
1417 but there could be still issues with 3.80 version.
1419 I have downloaded latest MAKE CVS sources. The compilation required
1420 separate lookup and download for .po files and full Autoheader... cycle.
1421 I have put together package similar to release. Only ./configure --prefix=...
1422 and make is required. CVS sources contains version 3.81beta1.
1423 You can download prepared sources archive from
1424 @uref{http://paulandlesley.org/make/make-3.81beta1.tar.bz2}
1425 Or you can get our local copy from
1426 @uref{http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz}
1428 The archive contains even "make" binary build by me, which should work
1429 on other Linux distributions as well. Older version of MAKE (3.79.x
1430 released about year 2000) found on Mandrake and RedHat are not
1431 sufficient and do not support eval feature. I do not expect, that
1432 Debian would be more up-to-date or contain fixes to MAKE vm exhausted
1435 The local CTU archive with our CAN components prepared for inclusion
1436 into OCERA SF CVS could be found in my "can" directory
1438 @uref{http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz}
1440 The code should build for user-space with new make on most of Linux distros
1441 when make is updated.
1443 If you want to test compile for RT-Linux targets, line
1446 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
1449 in @file{Makefile.rules} has to be activated and updated
1450 to point RT-Linux directory containing "rtl.mk".
1451 There is only one library ("ulutrtl") and test utility compiled for RT-Linux
1452 (@file{can/utils/ulut/ul_rtlchk.c}).
1454 The next line, if enabled, controls compilation in OCERA project tree
1457 #OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
1460 The LinCAN driver has been updated to compile out of source directories.
1462 Please, check, if you could compile CAN package and help us with integration
1463 into OCERA SF CVS. Send your comments and objections.
1465 The OMK system has been adapted to support actual OCERA configuration process.
1466 I am not happy with ocera.mk mix of defines and poor two or three rules,
1467 but OMK is able to overcome that.
1469 The OMK system has integrated rules (default-config) to build default
1470 configuration file. The file is named @file{config.omk-default} for
1471 the stand-alone compilation. The name corresponds to OCERA config +
1472 "-default" if OCERA_DIR is defined. This file contains statements
1473 from all @code{default_CONFIG} lines in all @file{Makefile.omk}. The
1474 file should be used for building of own @file{config.omk} file, or as
1475 list for all options if Kconfig is used.
1477 @c @chapter OMK Reference
1479 @node Development, Variable Index, Original README, Top
1480 @chapter Development
1482 This section is far from complete. Its purpose is to document internals
1483 of @file{Makefile.rules} as well as other things needed only by people
1484 who hack OMK itself.
1488 A pass is created by instantiation of @code{omk_pass_template} with
1489 @var{pass-name} as one of arguments. This defines several targets which
1493 @item @var{pass-name}
1494 Target used to invoke the individual pass either from command line or
1495 from inside of @file{Makefile.rules}.
1497 @item @var{pass-name}-submakes
1498 Invoked recursively from @var{pass-name}. The reason for this is the
1501 @item @var{pass-name}-this-dir
1502 This target calls make recursively once again with @var{pass-name}-local
1503 target, which does the real-work. Make's working directory is set to the
1504 corresponding directory in @file{_build} tree and the -local
1506 @item @var{pass-name}-@var{dirname}-subdir
1507 This target is responsible for recursive invocation of @command{make} in
1508 subdirectories specified in @code{@ref{SUBDIRS}} variable.
1511 @node Variable Index, , Development, Top
1512 @unnumbered Variable Index
1516 @c @node Concept Index, , Variable Index, Top
1517 @c @unnumbered Concept Index