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 $Id$
11 Copyright @copyright{} 2007, 2008 Michal Sojka, Pavel Pisa
15 @title Ocera Make System Manual
17 @vskip 0pt plus 1filll
24 @node Top, Overview of OMK, (dir), (dir)
25 @top Ocera Make System
39 @node Overview of OMK, OMK User's Manual, Top, Top
43 OMK is an advanced make system written entirely in GNU make. Compiling
44 software using OMK requires only GNU Make and standard UNIX
45 utilities (@command{sh}, @command{sed}, @command{cmp}, ...)
46 installed. OMK aims to be developer friendly; to use OMK, you do not
47 need to understand (sometimes) cryptic syntax of Makefiles.
49 You can use OMK on all platforms where you can run GNU Make including
50 Cygwin and MinGW. MS DOS was not tested.
56 @c Easy to use for beginners.
58 @c Automatic handling of dependencies.
60 @c Supported host platforms: all Un*x operating system including Linux,
61 @c Cygwin, MS DOS and maybe others.
70 @node Why to Use OMK?, Quick Start, Overview of OMK, Overview of OMK
71 @section Why to Use OMK?
73 Here we list some of OMK features, which we think are important for
74 choosing of a make system.
79 Makefile in source directories are usually very @b{simple}.
81 There is only @b{one} @file{Makefile.rules} for most of components of
84 OMK greatly simplifies compilation of projects, where source files are
85 spread between @b{multiple directories}.
87 OMK handles properly @b{dependencies} of source files and libraries,
88 so it is not necessary to recompile the whole project if only several
91 OMK allows to freely @b{move} cross-dependant components @b{in
92 directory structure} without the need to update users of moved
93 component. I hate something like
94 @option{-I../../sched/rtlshwq/include} in makefiles for example. If a
95 component is renamed or version is added to the name, many Makefiles
96 in the project would require an update.
98 The above feature is very helpful in @b{combining components}
99 (libraries) from different projects/developers to a single project by
100 simply creating symbolic links to external components.
102 Compilation of an OMK based projects don't require to install any
103 files before successful finish of build.
105 OMK allows to call @command{make} for a particular subdirectory in the
108 Under OMK all products of compilation are stored @b{out of source
109 directories}. This simplifies work with version control systems and
110 helps when simultaneous compilation for multiple targets/platforms is
117 @node Quick Start, History, Why to Use OMK?, Overview of OMK
120 If you get some sources, which are distributed with OMK, usually the
121 following commands are sufficient to compile the whole project.
130 @noindent To use OMK in your own project, follow these steps:
134 The newest version of OMK can be found at @uref{http://rtime.felk.cvut.cz/omk/}.
136 Take appropriate @file{Makefile.rules} (see @ref{Properties of
137 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{OMK 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 of OMK
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 OMK User's Manual, Original README, Overview of OMK, Top
165 @chapter OMK User's Manual
170 * Compiling Programs::
172 * Multiple Directories::
173 * Dependency Tracking::
174 * Configuration and Conditional Compilation::
175 * Advanced OMK Features::
176 * Properties of Specific Makefile.rules::
177 * Running OMK under Windows OS::
178 * Interfacing OMK to popular IDEs::
182 @node Basic Concepts, Invoking OMK, OMK User's Manual, OMK User's Manual
183 @section Basic Concepts
185 The main concept of OMK is very simple. In the root directory of the
186 projects resides a file called @file{Makefile.rules}. This file contains
187 all compilation rules needed for compilation of a particular
188 project. There are different @file{Makefile.rules} for different
189 platforms (Unix, RTEMS, system-less, ...). In every subdirectory a
190 @file{Makefile.omk} is stored. This file determines what should be done
191 in the respective directory (e.g. compile a program from several source
192 files). Its syntax is very simple -- see the following sections.
194 Since make searches by default for a @file{Makefile} and not for
195 @file{Makefile.rules} or @file{Makefile.omk}, there must@footnote{When
196 USE_LEAF_MAKEFILES is set to @samp{n}, this @file{Makefile} can be
197 omitted in subdirectories. @xref{USE_LEAF_MAKEFILES}.} be a small
198 generic @file{Makefile} in every directory, whose task is only to find
199 @file{Makefile.rules} in the actual or any parent directory and include
200 it. This search is performed only once at the beginning of compilation.
202 @c TODO: Pavel's note about qmake.
205 The compilation process itself is comprised of several @emph{passes}. Every
206 pass traverses the whole directory structure@footnote{In future, we are
207 planning some optimization that allows OMK to traverse the directories
208 only once and thus decrease compilation time.} and does a particular
209 task in every directory of the project. Typically, these passes are:
211 @anchor{include-pass}
213 This pass takes all include files marked for ``export'' and copies
214 (or links) them to the @file{include} directory under
215 @file{_compiled} directory. @xref{Header Files}.
217 Also, during this pass, automatically generated header file are
218 generated according to the current
219 configuration. @xref{Configuration and Conditional Compilation}.
221 During this pass, all include files are in place, so all libraries
224 Finally, programs can be compiled and linked against libraries
225 created in the previous pass.
228 The results of compilation are stored under the @file{_compiled}
229 directory. This directory is structured as a classical Unix file-system
230 (it contains directories like @file{bin}, @file{lib} and @file{include})
231 and can be directly copied to the target device or to some directory on
232 a host computer (e.g. @file{/usr/local}).
234 Besides @file{_compiled} directory, there in a @file{_build}
235 directory. Under this directory are stored some temporary files and
236 intermediate compilation products (object files, dependency files etc.).
238 In the next section, we provide an overview of methods, how to invoke
239 OMK from command line. Section @ref{Interfacing OMK to popular IDEs}
240 covers running of OMK from popular IDEs.
242 Sections @ref{Compiling Programs} through @ref{Configuration and
243 Conditional Compilation} deals with the content of
244 @file{Makefile.omk}. Its syntax in usual cases compatible to GNU
245 Automake's @file{Makefile.am} syntax. Also, the scheme for naming
246 variables was inspired by Automake so most OMK variables have the name
247 like @samp{@var{target}_@var{TYPE}}.
249 @node Invoking OMK, Compiling Programs, Basic Concepts, OMK User's Manual
250 @section Invoking OMK
252 Before using OMK for the first time, you have to call:
254 @command{make default-config}
256 @noindent See @ref{Configuration and Conditional Compilation} for
257 details. If you forget to do this, OMK will notice you.
259 To compile the whole project or only some subtree of the project, call
263 @noindent in the appropriate directory.
265 To clean files in @file{_build} directory but not in @file{_compiled}
271 To clean the compilation completely, you can either remove
272 @file{_compiled} and @file{_build} directories manually, or call
274 @command{make distclean}
276 @noindent which does the same. This command removes these directories
277 even if you call it from a subdirectory.
279 To debug compilation problems, you can use @code{V} variable (see
285 You can also set values of some other variables on command line for
286 temporary change something. The example below compiles the code
287 temporarily with debugging information:
289 @command{make CFLAGS="-g -O0 -Wall"}
292 If your project uses an alternative make-system (e.g. Automake or custom
293 makefiles), it might be useful for you to use the command:
295 @command{make omkize}
297 @noindent This will find all @file{Makefile.omk} files in all subdirectories
298 and copies generic @file{Makefile} from the root directory to that
299 subdirectories. This way you can easily switch your project to use OMK.
305 If this variable equals to @samp{1}, the whole command lines for all
306 executed commands are displayed. When not set or zero, only short
307 messages are printed. Value of @samp{2} displays the whole command lines
308 as with @samp{1} and in addition directory navigation messages are
312 @node Compiling Programs, Libraries, Invoking OMK, OMK User's Manual
313 @section Compiling Programs
315 To tell OMK to compile a program, you need to set some variables in
316 @file{Makefile.omk} (usually) in the directory where program sources are
319 In the example bellow a program @command{test} will be compiled from
320 source @file{test.c}.
323 @verbatiminclude ../tests/programs/Makefile.omk
326 @noindent The variables are:
328 @anchor{bin_PROGRAMS}
330 Contains a list of names (whitespace separated) of programs to be
331 compiled in this directory.
334 @defvar test_PROGRAMS
335 Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
336 stored in @file{bin-tests} directory instead of @file{bin}. This
337 variable is intended for various test programs not to be mixed with
341 @defvar utils_PROGRAMS
342 Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
343 stored in @file{bin-utils} directory instead of @file{bin}. This
344 variable is intended for various development utilities not to be mixed
345 with the final product.
349 For every program name @var{xxx} in @code{bin_PROGRAMS},
350 @code{test_PROGRAMS} or @code{utils_PROGRAMS}, this variable contains
351 a list of sources that are needed to compile the program. OMK uses an
352 extension of the filename to determine the compiler to compile this
357 This variable contains a list of libraries the program @var{xxx} will
366 This variable contains a list of libraries all programs in this
367 directory needs to be linked to.
371 Directives passed to the C or C++ compiler with additional directories
372 to be searched for header files. In most cases you need to specify an
373 absolute path. To specify a directory relative to the source
374 directory, you can use the @code{$(SOURCES_DIR)} variable, which
375 refers to the directory, where @file{Makefile.omk} is located. This
376 variable applies to all compilations invoked in the current directory.
379 INCLUDES = -I$(SOURCES_DIR)/my_include_dir
384 Directives passed to the C or C++ compiler with preprocessor macro
385 definitions. This variable applies to all compilations invoked in the
394 @c FIXME: INCLUDES variable should not be set by rtlinux rules.
396 @node Libraries, Multiple Directories, Compiling Programs, OMK User's Manual
400 With OMK, you can easily create statically or dynamically linked
401 libraries. The way of creating libraries is very similar to how programs
402 are created. @xref{Compiling Programs}.
404 In @file{Makefile.omk}, you specify several variables, which defines how
405 the libraries should be compiled. In the example below the library
406 @samp{mylib} (full filename will be @file{libmylib.a}) is created from
407 two sources @file{funca.c} and @file{funcb.c}. Interface of this library
408 is defined in @file{myfunc.h}. Therefore, we export this header for use
412 @verbatiminclude ../tests/libraries/Makefile.omk
415 @noindent Variables for use with libraries are:
417 @defvar lib_LIBRARIES
418 Specifies a list of statically linked libraries to be compiled. OMK
419 automatically prepends @code{lib} prefix library names.
422 @defvar shared_LIBRARIES
423 Specifies a list of dynamically linked libraries to be compiled.
427 For every library name @var{xxx} in @code{lib_LIBRARIES} or
428 @code{shared_LIBRARIES}, this variable contains a list of sources that
429 are needed to compile the library. OMK uses an extension of the
430 filename to determine the compiler to compile this source.
437 @node Header Files, , Libraries, Libraries
438 @subsection Header Files
440 C and C++ libraries are not very useful without header files. OMK
441 provides several variables that specify activities on header files.
443 During compilation, header files are copied (or linked) from source
444 directories to the @file{_compiled} tree
445 (see @ref{include-pass}). Libraries and programs are then compiled against
448 @anchor{include_HEADERS}
449 @defvar include_HEADERS
450 Specifies the list of header files to be exported for use by other
451 libraries/programs. The files are exported directly to the
452 @file{include} directory even if the file is located in a subdirectory
453 (like @file{sci_regs.h} in the example below)
456 include_HEADERS = regs.h periph/sci_regs.h
460 @defvar nobase_include_HEADERS
461 Similar to @ref{include_HEADERS}, but the directory prefix is always
462 kept. To include the file exported by this variable, use
463 @code{#include <@var{prefix}/@var{header.h}>}.
466 @defvar renamed_include_HEADERS
467 Exports the header files under different name. The form of the items
468 in this whitespace separated list is: @var{real name}@code{->}@var{new
472 renamed_include_HEADERS = orte_config_omk_win32.h->orte_config.h
477 If this variable equals to @samp{y}, symbolic links to headers in
478 source directories are used in @file{_compiled} tree instead of
481 Normally, the header files are copied into @file{_compiled} directory
482 to be prepared for transfer into target location afterwards. Copying
483 ensures that resulting libraries are in correspondence with the header
484 files even if the header is changed by a developer but the library is
487 @c Another reason for having single include directory for the whole
488 @c project is tat every component knows where to find header files of
491 On the other side, the copying could make problems during
492 development. Most @acronym{IDE}s, allows you to jump directly to the
493 place, where an error is reported by the compiler. If the error is in
494 a header file, IDE opens you the copy of the header file. If you
495 correct the error there, after the next compilation, your header file
496 will be overwritten by the old version from your source tree.
498 This option is not typically used in @file{Makefile.omk}, but in the
499 top level configuration file @file{config.omk} or on command line.
502 @node Multiple Directories, Dependency Tracking, Libraries, OMK User's Manual
503 @section Multiple Directories
505 OMK is probably most useful in projects consisting of multiple
506 directories. For such projects, it is not easy to write from scratch
507 classic Makefiles that provides all the needed features.
509 You can instruct OMK to descend to a (sub)directory by setting the
510 @code{SUBDIRS} variable in @file{Makefile.omk}.
514 This variable contains a list of directories, in which compilation
515 must be also invoked. Usually, names of subdirectories are used, but
516 you can use any path specification here.
518 Compilation is invoked in these directories before it is invoked in
519 the current directory.
521 See also @ref{AUTOMATIC_SUBDIRS}.
523 @c TODO: Write tests for this.
525 @anchor{ALL_OMK_SUBDIRS}
526 @defvar ALL_OMK_SUBDIRS
527 This variable is set by OMK and can be used as the value of
528 @code{SUBDIRS} variable. It contains a list of all direct
529 subdirectories, which contain @file{Makefile.omk}. This is especially
530 useful if you are combining several projects or components
531 together. In the root directory of your project, you just create
532 symbolic links the components from other projects and all the linked
533 directories automatically appears as the value of this variable.
536 SUBDIRS = $(ALL_OMK_SUBDIRS)
540 @anchor{AUTOMATIC_SUBDIRS}
541 @defvar AUTOMATIC_SUBDIRS
542 If this variable is set to @samp{y} and @code{SUBDIRS} is not assigned
543 in @file{Makefile.omk}, then @code{SUBDIRS} is assigned a default
544 value @code{$(ALL_OMK_SUBDIRS)}.
547 @node Dependency Tracking, Configuration and Conditional Compilation, Multiple Directories, OMK User's Manual
548 @section Dependency Tracking
550 OMK automatically handles tracking of dependencies of files in compiled
551 projects. It uses gcc's @option{-M@var{x}} options to do this for object
552 files. This way, whenever you change some header file, OMK recompiles
553 only those files, where the changed header was really included.
555 Dependencies are also maintained for libraries and binaries. To find the
556 dependencies, OMK parses linker map files, so a change to some library
557 causes recompilation of all programs using that library.
559 @node Configuration and Conditional Compilation, Advanced OMK Features, Dependency Tracking, OMK User's Manual
560 @section Configuration and Conditional Compilation
562 In many projects, it is necessary to configure the compilation process. By
563 this configuring we mean, setting some parameters that influence the
564 output of compilation process. In GNU projects, @command{configure}
565 script is usually responsible for configuration. User provides some
566 parameters to @command{configure}, which is run before compilation, and
567 this script does all steps needed to configure the sources and
568 make-system in the desired way.
570 OMK has its own configuration mechanism, which is described in this
571 section. For future releases, we plan that this mechanism can make use
572 of GNU Autoconf, but currently there is no directly integrated support
575 There exist three different configuration files
576 @file{config.omk-default}, @file{config.target} and
577 @file{config.omk}. All of these have to be stored in the same directory
578 as @file{Makefile.rules}. During compilation, these files are included
579 in @file{Makefile.rules} in this order which means that variables
580 assigned in the former files are overridden by those from later
581 ones. All settings specified here apply to the whole compilation
582 tree. Each file is intended for a different kind of configuration
585 @item config.omk-default
586 Stores default configuration of compiled components. This file is
587 automatically generated (see below) and should not be edited by users.
589 Stores default configuration for a project or target hardware. This
590 file is intended to be stored in a version control system and should
591 be modified only by the maintainer of the project.
593 For cross compiled projects, this file typically contains settings of
594 variables like @var{CC} and @var{CFLAGS}.
596 This is a file for end users, where any default settings set in the
597 above files can be overridden. This file should not be stored in
598 version control system. The project should compile without having this
602 Besides variables defined in @file{config.target}, @file{Makefile.omk}
603 in any subdirectory can specify some configuration parameters. When
604 @command{make default-config} is run, all these parameters are found and
605 together with their default values are stored as makefile variables in
606 @file{config.omk-default}. This file is included during compilation, so
607 if you don't specify other values, these defaults are used. If you are
608 not satisfied with these defaults, you can override the values of
609 parameters either locally for your build in @file{config.omk} or
610 globally for all people working with the project in
611 @file{config.target}.
614 * Specifying Configuration Parameters::
615 * Using Configuration Parameters::
619 @node Specifying Configuration Parameters, Using Configuration Parameters, Configuration and Conditional Compilation, Configuration and Conditional Compilation
620 @subsection Specifying Configuration Parameters
622 To specify names and default values of configuration parameters use the
623 @code{default_CONFIG} variable in @file{Makefile.omk}.
625 @defvar default_CONFIG
626 This variable contains a list of configuration parameters and their
627 default values. The format of every item in this list is
628 @var{CONFIG_xxxx}=@var{value}. You can name the parameter as you want,
629 but it is good practice to start the name with @samp{CONFIG_} prefix.
631 OMK can automatically generate header files, with C preprocessor macro
632 definitions according to the OMK's configuration parameters. The
633 actual content of generated header files depends on the form of the
634 @var{value}. The possible forms are:
637 @item @samp{y}, @samp{n} or @samp{x}
638 This defines boolean parameters. If the value of the parameter is
639 @samp{y}, the @samp{#define CONFIG_@var{xxx} 1} is generated, if it is
640 @samp{n}, no @code{#define} is generated.
642 @samp{x} is a special value called @emph{recessive 'n'}. The meaning
643 is that this parameter influences the component in the current
644 directory (i.e. the corresponding @code{#define} will be included in
645 @code{LOCAL_CONFIG_H}; see @ref{LOCAL_CONFIG_H}) but the default value
646 is not specified here. If the default value is not specified anywhere,
647 the behavior is the same as if @samp{n} is specified.
649 Numeric parameters. The define looks like @samp{#define CONFIG_@var{xxx} @var{number}}
651 Text without quotes. The define looks like @samp{#define CONFIG_@var{xxx} @var{text}}
653 Text with quotes. The define looks like @samp{#define CONFIG_@var{xxx} "@var{text}"}
657 @noindent Example of using @code{default_CONFIG}. @file{Makefile.omk} reads like:
659 @verbatiminclude ../tests/config/default/Makefile.omk
661 @noindent and @file{subdir/Makefile.omk} like:
663 @verbatiminclude ../tests/config/default/subdir/Makefile.omk
666 @noindent After running @command{make default-config}, the content of
667 @file{config.omk-default} will be:
669 @verbatiminclude ../tests/config/default/config.omk-correct
672 @node Using Configuration Parameters, Common Variables, Specifying Configuration Parameters, Configuration and Conditional Compilation
673 @subsection Using Configuration Parameters
675 Configuration parameters can be used in two ways:
678 as variables in @file{Makefile.omk} and
680 as C/C++ preprocessor macros in OMK generated header files.
683 @noindent For the first use, your @file{Makefile.omk} may contain something like:
685 SUBDIRS = arch/$(CONFIG_ARCH)
687 ifeq ($(CONFIG_DEBUG),y)
688 DEFS += -DUSE_SIMULATOR
692 @noindent For the second use, there are several variables that control
693 the generation of header files with configuration values. These
694 variables are described here:
696 @anchor{LOCAL_CONFIG_H}
697 @defvar LOCAL_CONFIG_H
698 The value of this variable is the name of a header file, which will
699 contain all configuration parameters declared in the current directory
700 by @code{default_CONFIG}. This header file is accessible only by files
701 in the current directory and it should be included like @code{#include
704 In @file{Makefile.omk}, the use of this variable can look like this:
707 LOCAL_CONFIG_H = myconfig.h
711 @defvar config_include_HEADERS
712 This variable is similar to @code{LOCAL_CONFIG_H}. One difference is
713 that the generated header file is accessible to all sub-projects in
714 all directories, not only to the files in the same directory (the
715 header is stored in @file{_compiled} tree). The second difference is
716 that you have to specify, which configuration parameters you want to
717 appear in the header file.
721 This variable determines the configuration parameters that should be
722 stored in a header file specified by
723 @code{config_include_HEADERS}. The @var{xxx} in the name of this
724 variable needs to be the same as the base name (without extension) of
728 @noindent Example of using @code{config_include_HEADERS}:
730 default_CONFIG = CONFIG_LINCAN=y CONFIG_LINCANRTL=n CONFIG_LINCANVME=n
731 config_include_HEADERS = global.h
732 global_DEFINES = CONFIG_OC_LINCAN CONFIG_OC_LINCANRTL
735 @noindent Here, we include only two out of the three configuration
736 parameters defined in the current @file{Makefile.omk}. It is also
737 possible to include configuration parameters defined in a different
740 @node Common Variables, , Using Configuration Parameters, Configuration and Conditional Compilation
741 @subsection Common Variables
743 It is common practice to use @file{config.omk} to store project-wide
744 settings. Here is the list of variables, which are commonly set here
745 (but they can also be set elsewhere, e.g. in @file{Makefile.omk}).
747 You can easily ``reconfigure'' your project by changing the
748 @file{config.omk} file. It is useful to have several configurations
749 stored in different files and let @file{config.omk} be a symbolic link
750 to the desired configuration.
754 The name of C compiler.
756 Command line options for C compiler.
758 The name of C++ compiler.
760 Additional parameters (besides @code{CFLAGS}) to by passed to C++
764 @node Advanced OMK Features, Properties of Specific Makefile.rules, Configuration and Conditional Compilation, OMK User's Manual
765 @section Advanced OMK Features
767 In this section we list several OMK features, which are more complicated
768 or rarely used so they were omitted in previous sections.
771 * Organization of the Source Tree::
772 * Additional Variables::
773 * Adding Hooks to Passes::
776 @node Organization of the Source Tree, Additional Variables, Advanced OMK Features, Advanced OMK Features
777 @subsection Organization of the Source Tree
781 The @file{_compiled} directory can be shared between multiple projects
782 (by using symbolic links).
785 If you work on a bigger project, you usually don't need to rebuild the
786 whole project and call @command{make} only in a
787 subdirectory. Sometimes, it might be useful to rebuild the whole
788 project. You can either change working directory to the root of your
789 project and call @command{make} there or, as a shortcut, you can use
790 @code{W} variable (see @ref{W}) to compile everything directly from a
797 Searching for @file{Makefile.rules} works such way, that if you get
798 into sources directory over symbolic links, OMK is able to unwind your
799 steps back. This implies you can make links to component directories
800 on read-only media, copy @file{Makefile.rules}, @file{Makefile} and
801 top-level @file{Makefile.omk}, adjust @file{Makefile.omk} to contain
802 only required components and then call @command{make} in the top
803 directory or even in read-only directories after changing working
804 directory from your tree to the readonly media.
810 If this variable equals to @samp{1}, the @b{whole} project is
811 (re)compiled, even if @command{make} is called from a subdirectory.
814 @node Additional Variables, Adding Hooks to Passes, Organization of the Source Tree, Advanced OMK Features
815 @subsection Additional Variables
817 @anchor{USE_LEAF_MAKEFILES}
818 @defvar USE_LEAF_MAKEFILES
819 If this variable equals to @samp{n} (default is unset), then OMK uses
820 the leaf @file{Makefile} only when it is invoked by simple
821 @command{make} command. Later, during recursive directory descent leaf
822 @file{Makefile} is not used and @file{Makefile.rules} is included
825 This feature is useful if you are integrating some non-OMK project into
826 your project. You only add @file{Makefile.omk} files to the non-OMK
827 project and don't need to modify project's original Makefiles.
829 This variable can be set either globally in a @file{config.*} file or
830 locally in some @file{Makefile.omk}. In the latter case, it influences
831 only subdirectories of the directory containing @file{Makefile.omk}.
836 This variable is set internally by OMK and its value is the absolute
837 path to the directory with compiled sources. It can be used if you need
838 to refer to sources files in some custom constructs in
842 include_HEADERS = $(notdir $(wildcard $(SOURCES_DIR)/*.h))
848 The same as @ref{SOURCES_DIR}. Provided for Automake compatibility.
851 @defvar{MAKERULES_DIR}
852 This variable is set internally by OMK and its value is the absolute
853 path to the directory containing @file{Makefile.rules} currently used
857 @defvar{OMK_RULES_TYPE}
858 Identification the type of @file{Makefile.rules} used for
859 compilation. Values are like @samp{linux}, @samp{rtems}, @samp{sysless},
860 ... This variable is automatically generated during creation of
861 @file{Makefile.rules} and can be used in configuration files (see
862 @ref{Configuration and Conditional Compilation}) or in
863 @file{Makefile.omk} to tweak compilation for specific targets.
866 @node Adding Hooks to Passes, , Additional Variables, Advanced OMK Features
867 @subsection Adding Hooks to Passes
869 Sometimes it is necessary to run some special commands as a part of
870 compilation. Typical example might be a tool which generates source
871 files on the fly. OMK supports calling additional commands during
872 compilation by so called @emph{pass hooks}. A pass hook is an ordinary
873 make target which is invoked as part of compilation during a particular
874 pass (see @ref{passes}). Pass hooks can be defined by assigning their
875 names to @code{xxx_HOOKS} variable.
878 Specifies one or more hooks (make targets) which are invoked during pass
879 @var{xxx}. The working directory of commands or this target is under the
882 In the example bellow header file @file{generated_header.h} is created
883 during @samp{include-pass} by @file{convert_data} program. The program
884 takes @file{data_file.txt} in the source directory as the input and
885 creates the header file in the in the correct directory under the
889 include-pass_HOOKS = generated_header.h
891 generated_header.h: $(SOURCES_DIR)/data_file.txt
892 convert_data < $^ > $@@
896 @node Properties of Specific Makefile.rules, Running OMK under Windows OS, Advanced OMK Features, OMK User's Manual
897 @section Properties of Specific Makefile.rules
899 In previous sections, general properties of @file{Makefile.rules} were
900 documented. This section contains documentation to features found only
901 in some particular @file{Makefile.rules}.
909 @node Linux, System-Less, Properties of Specific Makefile.rules, Properties of Specific Makefile.rules
912 This @file{Makefile.rules} is used not only for Linux as the name
913 suggests, but also for other Unices and even for Windows.
916 The name of the operating system (OS) where make was invoked.
920 Should specify the name of OS where the resulting binary should be
921 used. If not specified manually, it equals to BUILD_OS.
925 Lists subdirectories with QT project (.pro) file. OMK will generate
926 there @file{Makefile} by calling @command{qmake} with correct
927 parameters to interface QT application to the rest of the compilation
928 tree. Then @command{make} is called there to compile QT
929 application. Variable @samp{QTDIR} must be set to the directory with
930 QT installation (e.g. /usr/share/qt4 on Debian).
934 @node System-Less, RTEMS, Linux, Properties of Specific Makefile.rules
935 @subsection System-Less
937 This @file{Makefile.rules} is designed for compilation of code for
938 (small) micro-controllers without operating systems. See
939 @uref{http://rtime.felk.cvut.cz/hw/index.php/System-Less_Framework} for
940 more information about our framework, which uses this rules.
942 @node RTEMS, , System-Less, Properties of Specific Makefile.rules
948 @node Running OMK under Windows OS, Interfacing OMK to popular IDEs, Properties of Specific Makefile.rules, OMK User's Manual
949 @section Running OMK under Windows OS
951 It is possible to use OMK under Windows OS with MinGW (see
952 @uref{http://www.mingw.org/}). Unfortunately, the compilation speed is
953 much lower than on UNIX systems.
955 TODO: Is it necessary to install anything special?
957 @node Interfacing OMK to popular IDEs, Troubleshooting, Running OMK under Windows OS, OMK User's Manual
958 @section Interfacing OMK to popular IDEs
966 @node KDevelop, Eclipse/CDT, Interfacing OMK to popular IDEs, Interfacing OMK to popular IDEs
969 KDevelop has support for custom build systems. To use KDevelop to
970 develop projects using OMK follow these steps. These steps are valid for
971 version 3.5.0 of KDevelop, but for previous versions it doesn't differ
976 Import project to KDevelop (from menu choose @emph{Project---Import
977 existing project}). Select the type of project to @emph{Generic C
978 Application (Custom Buildsystem)}.
984 Then answer to following dialogs as you want.
989 @image{kdevelop3} @image{kdevelop4}
993 If you are working only on some small part of the bigger project, you
994 usually don't want to recompile the whole project every time. In
995 @emph{Project---Project Options}, you can specify the subdirectory where to
1002 If you want to switch between several configurations easily (see also
1003 @ref{Configuration and Conditional Compilation}), in the same dialog
1004 you can add @option{-e} to make options. This makes environment variables
1005 have higher precedence than those in @file{config.omk-default}. Then,
1006 you can define several environments with different
1007 @code{CONFIG_@var{xxx}} variables and their values.
1013 You can easily switch the configurations from @emph{Build---Make
1020 @node Eclipse/CDT, Emacs/Vim/etc., KDevelop, Interfacing OMK to popular IDEs
1021 @subsection Eclipse/CDT
1023 @node Emacs/Vim/etc., , Eclipse/CDT, Interfacing OMK to popular IDEs
1024 @subsection Emacs, VIM, etc.
1026 Since OMK compilation is started by executing @command{make} command,
1027 many common editors can work easily with OMK.
1029 Under Emacs, you can use @command{compile} or @command{recompile}
1030 commands as you are used to do.
1032 @node Troubleshooting, , Interfacing OMK to popular IDEs, OMK User's Manual
1033 @section Troubleshooting
1037 If you rename some file or directory and then you can't compile your
1038 project, call @command{make clean} in the directory with errors. The
1039 reason for this behavior is that OMK remembers dependencies of every
1040 file. After renaming something, the original name is still stored in
1041 dependencies, but make doesn't know how to create this non-existent
1045 Sometimes, you may want to compile one file the same way as OMK does
1046 it, but run the compilation manually from command line. For example,
1047 you want to debug some preprocessor macros and you only want to
1048 produce preprocessed source instead of an object file.
1050 To compile something manually, you can run OMK by @command{make
1051 V=2}. This will print all commands executed together with directory
1052 navigation messages. Find the command you want to execute manually in
1053 the output. To run it, you need to change the working directory to the
1054 correct one in the @file{_build} tree. The correct directory can be
1055 found in make output on the line @samp{Entering directory} preceding
1056 the desired command.
1059 Currently, C++ sources are supposed to have @file{.cc} or @file{.cxx}
1060 extensions. The @file{.cpp} extension is not supported (yet).
1063 @node Original README, OMK Development, OMK User's Manual, Top
1064 @chapter Original README
1066 Since this manual still doesn't cover all aspects of OMK, we include
1067 here a @file{README.rules} file, which was written for the first version
1070 @b{Important notice:} This make system uses features found in recent
1071 versions of GNU Make program. If you encounter problems with package
1072 building, check, that you use correct version of Make program. The
1073 Make older than version 3.80, could not be used. Even Make version
1074 3.80 has annoying bug which causes building fail with misleading
1075 message "virtual memory exhausted". Please, upgrade at least to
1076 version 3.81 of GNU Make.
1078 There is list of features which we want to solve with our make system:
1081 Central @file{Makefile.rules} for most of components of a bigger project.
1083 FIXME (our CAN framework includes more libraries common with our other
1084 projects, we need to separate some utility libraries etc.)
1086 The rules in more spread Makefiles are way to the hell (update for
1087 different kernel, RT-Linux etc would be nightmare in other case).
1089 Make system should allow to freely move cross-dependant components in
1090 directory structure without need to update users of moved component (I
1091 hate something like @option{-I../../sched/rtlshwq/include} in CAN makefiles for
1092 example. If a component is renamed or version is added to then name,
1093 all Makefiles in CAN will require update).
1095 Make system should be able to compile mutually cross-dependant
1096 libraries and should ensure, that change in one component sources or
1097 headers would result in relink or rebuild in components linked against
1098 that library or including modified header file.
1100 Make system has to enable compilation out of OCERA full source tree
1101 (we would lost many users of particular components in other case).
1103 Compile should be able to do all above work without need to install
1104 any files before successful finish of build.
1106 Because we use some libraries for RT-Linux build and user-space build,
1107 we need to solve how to compile from same sources to both targets.
1109 The build system should allow to call make for particular source
1110 subdirectory. Time of recursive make through all subdirectories is
1113 Make system should enable to build out of sources tree (else clean or
1114 working with CVS sandbox gets fussy and simultaneous multiple targets
1117 It would be good, if there is a possibility to call make from
1118 read-only media sources.
1120 Make system should store results of build in some separate directory
1121 structure to simple install and testing.
1123 Makefiles in sources directories should be simple.
1126 There is probably only one alternative fully supporting above requirements
1127 and it is GNU Autoheader...Automake...Autoconf... system.
1128 But it is complicated and requires big amount of support files.
1129 It would be acceptable if it could be easily used for OCERA framework.
1130 But there are important show stoppers for that system:
1133 It would require deep revision of all OCERA CVS contents and agreement
1134 on this would be problematic
1136 This system is not well prepared for dual compilation for Linux and
1137 RT-Linux sub-targets. It would mean many changes in default autoconf
1138 setup to support this. Probably simplest way would be to rebuild GCC
1139 tool chain for something like i586-elf-rtlinux. This would require
1140 even more space for OCERA development.
1143 The problem calls for some solution, which would have minimal impact
1144 on other components and would be elegant and would be maintainable
1145 and small, because our main goal is components development and not
1146 make systems development.
1148 There is result of our trial. It is OMK make system.
1149 The @file{Makefile} and @file{Makefile.omk} files should be in all source
1150 directories. Common @file{Makefile.rules} file is required in the toplevel
1151 sources directory. Alternatively this file could be moved
1152 to link tree pointing into readonly media or can be anywhere
1153 else if @code{MAKERULES_DIR} and @code{SOURCES_DIR} are specified.
1155 @c !!! tohle tam nejak zmizelo, mozna by to chtelo zkontrolovat, ze to
1156 @c sedi s aktualnim stavem
1159 Syntax of Makefile.omk files is for usual cases compatible
1160 to Automake's Makefile.am descriptions. There are specific targets
1161 for RT-Linux and Linux kernel related stuff
1163 Makefile.omk user defined variables
1166 list of subdirectories intended for make from actual directory
1168 list of the user-space libraries
1169 @item shared_LIBRARIES
1170 list of the user-space shared libraries
1171 @item kernel_LIBRARIES
1172 list of the kernel-space libraries
1173 @item rtlinux_LIBRARIES
1174 list of the RT-Linux kernel-space libraries
1175 @item include_HEADERS
1176 list of the user-space header files
1177 @item nobase_include_HEADERS
1178 headers copied even with directory part
1179 @item kernel_HEADERS
1180 list of the kernel-space header files
1181 @item rtlinux_HEADERS
1182 list of the RT-Linux kernel-space header files
1184 list of the require binary programs
1185 @item utils_PROGRAMS
1186 list of the development utility programs
1187 @item kernel_MODULES
1188 list of the kernel side modules/applications
1189 @item rtlinux_MODULES
1190 list of RT-Linux the kernel side modules/applications
1192 list of specific target sources
1194 additional include directories and defines for user-space
1195 @item kernel_INCLUDES
1196 additional include directories and defines for kernel-space
1197 @item rtlinux_INCLUDES
1198 additional include directories and defines for RT-Linux
1199 @item default_CONFIG
1200 list of default config assignments CONFIG_XXX=y/n ...
1203 The Makefile is same for all sources directories and is only 14 lines
1204 long. It is there only for convenience reasons to enable call "make"
1205 from local directory. It contains code which locates
1206 @file{Makefile.rules} in actual or any parent directory. With standard
1207 BASH environment it works such way, that if you get into sources
1208 directory over symbolic links, it is able to unwind yours steps back
1209 => you can make links to readonly media component directories, copy
1210 @file{Makefile.rules}, Makefile and toplevel Makefile.omk, adjust
1211 Makefile.omk to contain only required components and then call make in
1212 top or even directories after crossing from your tree to readonly
1215 The system compiles all files out of source directories. The actual
1216 version of system is adapted even for OCERA tree mode if
1217 @code{OCERA_DIR} variable is defined in @file{Makefile.rules}
1219 There are next predefined directory name components, which can be
1223 @item BUILD_DIR_NAME = _build
1224 prefix of directory, where temporary build files are stored
1225 @item COMPILED_DIR_NAME = _compiled
1226 prefix of directory, where final compilation results are stored
1227 @item GROUP_DIR_NAME = yyy
1228 this is used for separation of build sub-trees in OCERA environment
1229 where more @file{Makefile.rules} is spread in the tree
1232 Next directories are used:
1235 @item KERN_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern
1236 directory to store intermediate files for kernel-space targets
1237 @item USER_BUILD_DIR := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
1238 directory to store intermediate files for user-space targets
1240 @item USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
1241 directory to store exported include files which should be installed later
1242 on user-space include path
1243 @item USER_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
1244 same for user-pace libraries
1245 @item USER_UTILS_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
1246 utilities for testing, which would not probably be installed
1247 @item USER_BIN_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
1248 binaries, which should go into directory on standard system PATH
1249 (/usr/local/bin, /usr/bin or $(prefix)/bin)
1251 @item KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern
1252 directory to store exported include files which should be installed later
1253 on kernel-space include path
1254 @item KERN_LIB_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern
1255 same for kernel-pace libraries
1256 @item KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules
1257 builded modules for Linux kernel or RT-Linux system
1260 There is more recursive passes through directories to enable
1261 mutual dependant libraries and binaries to compile.
1262 Next passes are defined
1265 @item default-config
1266 generates @file{config.omk-default} or xxx-default (FIXME) configuration file
1268 checks and creates required build directories
1270 copies header files to @code{USER_INCLUDE_DIR} and @code{KERN_INCLUDE_DIR}
1272 builds objects in USER_BUILD_DIR/@var{relative path} and creates libraries
1274 @item binary-pass and utils-pass
1275 links respective binaries in USER_@{BIN,UTILS@}_DIR directory. If some
1276 object file is missing it compiles it in USER_BUILD_DIR/@var{relative path}
1277 @item kernel-lib-pass
1278 builds libraries for kernel space targets
1280 builds kernel modules
1283 The amount of passes is relatively high and consumes some time. But
1284 only other way to support all required features is to assemble one big
1285 toplevel Makefile, which would contain all components and targets
1288 Drawbacks of designed make system
1291 the system is not as fast as we would like
1293 it lacks Autoconf and configure extensive support for many systems
1294 from UNIX to DOS and WINDOWS
1296 it does not contain support for checking existence of target
1297 libraries and functionalities as GNU Autoconf
1299 it is heavily dependant on GNU MAKE program. But it would not be big
1300 problem, because even many commercial applications distribute GNU MAKE
1301 with them to be able to work in non-friendly systems
1303 the key drawback is dependence on recent MAKE version 3.80 and better
1304 and even version 3.80 of MAKE has important bug, which has been
1305 corrected in newer sources (FIXME)
1308 The last point is critical. I have not noticed it first, because
1309 I use Slackware-9.2 and it contains latest released version
1310 of MAKE (version 3.80).
1311 The problem appears when I have tried to build bigger libraries.
1312 There is bug in version 3.80, which results in misleading
1313 error "Virtual memory exhausted". It is known bug with ID 1517
1316 * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
1320 I have optimized some rules to not push memory to the edge,
1321 but there could be still issues with 3.80 version.
1323 I have downloaded latest MAKE CVS sources. The compilation required
1324 separate lookup and download for .po files and full Autoheader... cycle.
1325 I have put together package similar to release. Only ./configure --prefix=...
1326 and make is required. CVS sources contains version 3.81beta1.
1327 You can download prepared sources archive from
1328 @uref{http://paulandlesley.org/make/make-3.81beta1.tar.bz2}
1329 Or you can get our local copy from
1330 @uref{http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz}
1332 The archive contains even "make" binary build by me, which should work
1333 on other Linux distributions as well. Older version of MAKE (3.79.x
1334 released about year 2000) found on Mandrake and RedHat are not
1335 sufficient and do not support eval feature. I do not expect, that
1336 Debian would be more up-to-date or contain fixes to MAKE vm exhausted
1339 The local CTU archive with our CAN components prepared for inclusion
1340 into OCERA SF CVS could be found in my "can" directory
1342 @uref{http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz}
1344 The code should build for user-space with new make on most of Linux distros
1345 when make is updated.
1347 If you want to test compile for RT-Linux targets, line
1350 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
1353 in @file{Makefile.rules} has to be activated and updated
1354 to point RT-Linux directory containing "rtl.mk".
1355 There is only one library ("ulutrtl") and test utility compiled for RT-Linux
1356 (@file{can/utils/ulut/ul_rtlchk.c}).
1358 The next line, if enabled, controls compilation in OCERA project tree
1361 #OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
1364 The LinCAN driver has been updated to compile out of source directories.
1366 Please, check, if you could compile CAN package and help us with integration
1367 into OCERA SF CVS. Send your comments and objections.
1369 The OMK system has been adapted to support actual OCERA configuration process.
1370 I am not happy with ocera.mk mix of defines and poor two or three rules,
1371 but OMK is able to overcome that.
1373 The OMK system has integrated rules (default-config) to build default
1374 configuration file. The file is named @file{config.omk-default} for
1375 the stand-alone compilation. The name corresponds to OCERA config +
1376 "-default" if OCERA_DIR is defined. This file contains statements
1377 from all @code{default_CONFIG} lines in all @file{Makefile.omk}. The
1378 file should be used for building of own @file{config.omk} file, or as
1379 list for all options if Kconfig is used.
1381 @c @chapter OMK Reference
1383 @node OMK Development, Variable Index, Original README, Top
1384 @chapter OMK Development
1386 This section is far from complete. Its purpose is to document internals
1387 of @file{Makefile.rules} as well as other things needed only by people
1388 who hack OMK itself.
1392 A pass is created by instantiation of @code{omk_pass_template} with
1393 @var{pass-name} as one of arguments. This defines several targets which
1397 @item @var{pass-name}
1398 Target used to invoke the individual pass either from command line or
1399 from inside of @file{Makefile.rules}.
1401 @item @var{pass-name}-submakes
1402 Invoked recursively from @var{pass-name}. The reason for this is the
1405 @item @var{pass-name}-this-dir
1406 This target calls make recursively once again with @var{pass-name}-local
1407 target, which does the real-work. Make's working directory is set to the
1408 corresponding directory in @file{_build} tree and the -local
1410 @item @var{pass-name}-@var{dirname}-subdir
1411 This target is responsible for recursive invocation of @command{make} in
1412 subdirectories specified in @code{@ref{SUBDIRS}} variable.
1415 @node Variable Index, , OMK Development, Top
1416 @unnumbered Variable Index
1420 @c @node Concept Index, , Variable Index, Top
1421 @c @unnumbered Concept Index