]> rtime.felk.cvut.cz Git - omk.git/blob - doc/omk-manual.texinfo
Updates xxx_SOURCES in documentation.
[omk.git] / doc / omk-manual.texinfo
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename omk-manual
4 @settitle OMK: Ocera Make System
5 @c %**end of header
6
7 @copying
8 Manual for Ocera Make System (OMK)
9
10 Copyright @copyright{} 2007 Michal Sojka, Pavel Pisa
11 @end copying
12
13 @titlepage
14 @title Ocera Make System Manual
15 @page
16 @vskip 0pt plus 1filll
17 @insertcopying
18 @end titlepage
19
20 @contents
21
22 @ifnottex
23 @node Top, Overview of OMK, (dir), (dir)
24 @top Ocera Make System
25
26 @insertcopying
27 @end ifnottex
28
29
30 @menu
31 * Overview of OMK::             
32 * OMK User's Manual::           
33 * Original README::             
34 * OMK Development::             
35 * Variable Index::              
36 @end menu
37
38 @node Overview of OMK, OMK User's Manual, Top, Top
39 @chapter OMK Overview
40 @cindex overview
41
42 OMK is an advanced make system written entirely in GNU make. Compiling
43 software using OMK requires only GNU make binary and standard UNIX
44 utilities (@command{sh}, @command{sed}, @command{cmp} and
45 @command{tr}@footnote{@command{tr} is needed only for OMK to be
46 compatible with MinGW.}) installed. OMK aims to be developer friendly;
47 to use OMK, you do not need to understand (sometimes) cryptic syntax of
48 Makefiles.
49
50 You can use OMK on all platforms where you can run GNU Make including
51 Cygwin and MinGW. MS DOS was not tested.
52
53 @c @section Features
54
55 @c @itemize
56 @c @item
57 @c Easy to use for beginners.
58 @c @item
59 @c Automatic handling of dependencies.
60 @c @item
61 @c Supported host platforms: all Un*x operating system including Linux,
62 @c Cygwin, MS DOS and maybe others.
63 @c @end itemize
64
65 @menu
66 * Why to Use OMK?::             
67 * Quick Start::                 
68 * History::                     
69 @end menu
70
71 @node Why to Use OMK?, Quick Start, Overview of OMK, Overview of OMK
72 @section Why to Use OMK?
73
74 Here we list some of OMK features, which we think are important for
75 choosing of a make system.
76
77
78 @itemize
79 @item
80   Makefile in source directories are usually very @b{simple}.
81 @item
82   There is only @b{one} @file{Makefile.rules} for most of components of
83   a bigger project.
84 @item
85   OMK greatly simplifies compilation of projects, where source files are
86   spread between @b{multiple directories}.
87 @item
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
90   files changed.
91 @item
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.
98 @item
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.
102 @item
103   Compilation of an OMK based projects don't require to install any
104   files before successful finish of build.
105 @item
106   OMK allows to call @command{make} for a particular subdirectory in the
107   source tree.
108 @item
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
112   needed.
113 @end itemize
114
115
116 @node Quick Start, History, Why to Use OMK?, Overview of OMK
117 @section Quick Start
118
119 If you get some sources, which are distributed with OMK, usually the
120 following commands are sufficient to compile the whole project.
121
122 @example
123 @verbatim
124 make default-config
125 make
126 @end verbatim
127 @end example
128
129 @noindent To use OMK in your own project, follow these steps:
130
131 @enumerate
132 @item
133   Take appropriate @file{Makefile.rules}, put it together with leaf
134   @file{Makefile} to the root directory of your project.
135 @item
136   Create @file{Makefile.omk} files in all directories you want to
137   compile something. Please refer to @ref{OMK User's Manual} to learn
138   what to write in @file{Makefile.omk} files.
139 @item
140   Run @command{make omkize} in the root directory.
141 @end enumerate
142
143 @noindent Your project is now ready to compile.
144
145
146 @node History,  , Quick Start, Overview of OMK
147 @section History
148
149 OMK was originally written by Pavel Pisa as a solution to have one
150 common make system for OCERA project, where we needed to compile
151 user-space programs, Linux kernel modules and RT Linux modules in one
152 package. Although this system was not accepted for the whole OCERA
153 project. Several individual developers (mostly from Czech Technical
154 University) liked it and started to use it.
155
156 As a number of projects using OMK grew it was necessary to modularize
157 the make system to support more ``targets''. Michal Sojka took care
158 about the process of modularization.
159
160 @node OMK User's Manual, Original README, Overview of OMK, Top
161 @chapter OMK User's Manual
162
163 @menu
164 * Basic Concepts::              
165 * Invoking OMK::                
166 * Compiling Programs::          
167 * Libraries::                   
168 * Multiple Directories::        
169 * Dependency Tracking::         
170 * Configuration and Conditional Compilation::  
171 * Advanced OMK Features::       
172 * Running OMK under Windows OS::  
173 * Interfacing OMK to popular IDEs::  
174 * Troubleshooting::             
175 @end menu
176
177 @node Basic Concepts, Invoking OMK, OMK User's Manual, OMK User's Manual
178 @section Basic Concepts
179
180 The main concept of OMK is very simple. In the root directory of the
181 projects resides a file called @file{Makefile.rules}. This file contains
182 all compilation rules needed for compilation of a particular
183 project. There are different @file{Makefile.rules} for different
184 platforms (Unix, RTEMS, system-less, ...). In every subdirectory a
185 @file{Makefile.omk} is stored. This file determines what should be done
186 in the respective directory (e.g. compile a program from several source
187 files). Its syntax is very simple -- see the following sections.
188
189 Since make searches by default for a @file{Makefile} and not for
190 @file{Makefile.rules} or @file{Makefile.omk}, there must be a small
191 generic @file{Makefile} in every directory, whose task is only to find
192 @file{Makefile.rules} in the actual or any parent directory and include
193 it. This search is performed only once at the beginning of compilation.
194
195 @c TODO: Pavel's note about qmake.
196
197 The compilation process itself is comprised of several passes. Every
198 pass traverses the whole directory structure@footnote{In future, we are
199 planning some optimization that allows OMK to traverse the directories
200 only once and thus decrease compilation time.} and does a particular
201 task in every directory of the project. Typically, these passes are:
202 @table @dfn
203 @anchor{include-pass}
204 @item include-pass
205     This pass takes all include files marked for ``export'' and copies
206     (or links) them to the @file{include} directory under
207     @file{_compiled} directory. @xref{Header Files}.
208
209     Also, during this pass, automatically generated header file are
210     generated according to the current
211     configuration. @xref{Configuration and Conditional Compilation}.
212 @item library-pass
213     During this pass, all include files are in place, so all libraries
214     can be compiled.
215 @item binary-pass
216     Finally, programs can be compiled and linked against libraries
217     created in the previous pass.
218 @end table
219
220 The results of compilation are stored under the @file{_compiled}
221 directory. This directory is structured as a classical Unix file-system
222 (it contains directories like @file{bin}, @file{lib} and @file{include})
223 and can be directly copied to the target device or to some directory on
224 a host computer (e.g. @file{/usr/local}).
225
226 Besides @file{_compiled} directory, there in a @file{_build}
227 directory. Under this directory are stored some temporary files and
228 intermediate compilation products (object files, dependency files etc.).
229
230 In the next section, we provide an overview of methods, how to invoke
231 OMK from command line. Section @ref{Interfacing OMK to popular IDEs}
232 covers running of OMK from popular IDEs.
233
234 Sections @ref{Compiling Programs} through @ref{Configuration and
235 Conditional Compilation} deals with the content of
236 @file{Makefile.omk}. Its syntax in usual cases compatible to GNU
237 Automake's @file{Makefile.am} syntax. Also, the scheme for naming
238 variables was inspired by Automake so most OMK variables have the name
239 like @samp{@var{target}_@var{TYPE}}.
240
241 @node Invoking OMK, Compiling Programs, Basic Concepts, OMK User's Manual
242 @section Invoking OMK
243
244 Before using OMK for the first time, you have to call:
245 @example
246 @command{make default-config}
247 @end example
248 @noindent See @ref{Configuration and Conditional Compilation} for
249 details. If you forget to do this, OMK will notice you.
250
251 To compile the whole project or only some subtree of the project, call
252 @example
253 @command{make}
254 @end example
255 @noindent in the appropriate directory.
256
257 To clean files in @file{_build} directory but not in @file{_compiled}
258 one, use:
259 @example
260 @command{make clean}
261 @end example
262
263 To clean the compilation completely, you can either remove
264 @file{_compiled} and @file{_build} directories manually, or call
265 @example
266 @command{make distclean}
267 @end example
268 @noindent which does the same. This command removes these directories
269 even if you call it from a subdirectory.
270
271 To debug compilation problems, you can use @code{V} variable (see
272 @ref{V}):
273 @example
274 @command{make V=1}
275 @end example
276
277 You can also set values of some other variables on command line for
278 temporary change something. The example below compiles the code
279 temporarily with debugging information:
280 @example
281 @command{make CFLAGS="-g -O0 -Wall"}
282 @end example
283
284
285 @anchor{V}
286 @defvar V
287 If this variable equals to @samp{1}, the whole command lines for all
288 executed commands are displayed. Otherwise, only short messages are
289 printed.
290 @end defvar
291
292 @node Compiling Programs, Libraries, Invoking OMK, OMK User's Manual
293 @section Compiling Programs
294
295 To tell OMK to compile a program, you need to set some variables in
296 @file{Makefile.omk} (usually) in the directory where program sources are
297 located.
298
299 In the example bellow a program @command{test} will be compiled from
300 source @file{test.c}.
301
302 @example
303 @verbatiminclude ../tests/programs/Makefile.omk
304 @end example
305
306 @noindent The variables are:
307
308 @anchor{bin_PROGRAMS}
309 @defvar bin_PROGRAMS
310   Contains a list of names (whitespace separated) of programs to be
311   compiled in this directory.
312 @end defvar
313
314 @defvar test_PROGRAMS
315   Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
316   stored in @file{bin-tests} directory instead of @file{bin}. This
317   variable is intended for various test programs not to be mixed with
318   the final product.
319 @end defvar
320
321 @defvar utils_PROGRAMS
322   Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
323   stored in @file{bin-utils} directory instead of @file{bin}. This
324   variable is intended for various development utilities not to be mixed
325   with the final product.
326 @end defvar
327
328 @defvar xxx_SOURCES
329   For every program name @var{xxx} in @code{bin_PROGRAMS},
330   @code{test_PROGRAMS} or @code{utils_PROGRAMS}, this variable contains
331   a list of sources that are needed to compile the program. OMK uses an
332   extension of the filename to determine the compiler to compile this
333   source.
334 @end defvar
335
336 @defvar xxx_LIBS
337   This variable contains a list of libraries the program @var{xxx} will
338   be linked with.
339
340   @example
341   test_LIBS = m curses
342   @end example
343 @end defvar
344
345 @defvar LOADLIBES
346   This variable contains a list of libraries all programs in this
347   directory needs to be linked to.
348 @end defvar
349
350 @defvar INCLUDES
351   Directives passed to the C or C++ compiler with additional directories
352   to be searched for header files. In most cases you need to specify an
353   absolute path. To specify a directory relative to the source
354   directory, you can use the @code{$(SOURCES_DIR)} variable, which
355   refers to the directory, where @file{Makefile.omk} is located. This
356   variable applies to all compilations invoked in the current directory.
357
358   @example
359   INCLUDES = -I$(SOURCES_DIR)/my_include_dir
360   @end example
361 @end defvar
362
363 @defvar DEFS
364   Directives passed to the C or C++ compiler with preprocessor macro
365   definitions. This variable applies to all compilations invoked in the
366   current directory.
367
368   @example
369   DEFS = -DDEBUG=1
370   @end example
371 @end defvar
372
373
374 @c FIXME: INCLUDES variable should not be set by rtlinux rules.
375
376 @node Libraries, Multiple Directories, Compiling Programs, OMK User's Manual
377 @section Libraries
378
379
380 With OMK, you can easily create statically or dynamically linked
381 libraries. The way of creating libraries is very similar to how programs
382 are created. @xref{Compiling Programs}.
383
384 In @file{Makefile.omk}, you specify several variables, which defines how
385 the libraries should be compiled. In the example below the library
386 @samp{mylib} is created from two sources @file{funca.c} and
387 @file{funcb.c}. Interface of this library is defined in
388 @file{myfunc.h}. Therfore, we export this header for use by other
389 programs.
390
391 @example
392 @verbatiminclude ../tests/libraries/Makefile.omk
393 @end example
394
395 @noindent Variables for use with libraries are:
396
397 @defvar lib_LIBRARIES
398   Specifies a list of statically linked libraries to be compiled. 
399 @end defvar
400
401 @defvar shared_LIBRARIES
402   Specifies a list of dynamically linked libraries to be compiled. 
403 @end defvar
404
405 @defvar xxx_SOURCES
406   For every library name @var{xxx} in @code{lib_LIBRARIES} or
407   @code{shared_LIBRARIES}, this variable contains a list of sources that
408   are needed to compile the library. OMK uses an extension of the
409   filename to determine the compiler to compile this source.
410 @end defvar
411
412 @menu
413 * Header Files::                
414 @end menu
415
416 @node Header Files,  , Libraries, Libraries
417 @subsection Header Files
418
419 C and C++ libraries are not very useful without header files. OMK
420 provides several variables that specify activities on header files.
421
422 During compilation, header files are copied (or linked) from source
423 directories to the @file{_compiled} tree
424 (see @ref{include-pass}). Libraries and programs are then compiled against
425 these copies.
426
427 @anchor{include_HEADERS}
428 @defvar include_HEADERS
429   Specifies the list of header files to be exported for use by other
430   libraries/programs. The files are exported directly to the
431   @file{include} directory even if the file is located in a subdirectory
432   (like @file{sci_regs.h} in the example below)
433
434   @example
435   include_HEADERS = regs.h periph/sci_regs.h
436   @end example
437 @end defvar
438
439 @defvar nobase_include_HEADERS
440   Similar to @ref{include_HEADERS}, but the directory prefix is always
441   kept. To include the file exported by this variable, use
442   @code{#include <@var{prefix}/@var{header.h}>}.
443 @end defvar
444
445 @defvar renamed_include_HEADERS
446   Exports the header files under different name. The form of the items
447   in this whitespace separated list is: @var{real name}@code{->}@var{new
448   name}.
449
450 @example 
451   renamed_include_HEADERS = orte_config_omk_win32.h->orte_config.h
452 @end example
453 @end defvar
454
455 @defvar LN_INCLUDES
456   If this variable equals to @samp{y}, symbolic links to headers in
457   source directories are used in @file{_compiled} tree instead of
458   copies.
459
460   Normally, the header files are copied into @file{_compiled} directory
461   to be prepared for transfer into target location afterwards. Copying
462   ensures that resulting libraries are in correspondence with the header
463   files even if the header is changed by a developer but the library is
464   not recompiled.
465
466 @c   Another reason for having single include directory for the whole
467 @c   project is tat every component knows where to find header files of
468 @c   other components. 
469
470   On the other side, the copying could make problems during
471   development. Most @acronym{IDE}s, allows you to jump directly to the
472   place, where an error is reported by the compiler. If the error is in
473   a header file, IDE opens you the copy of the header file. If you
474   correct the error there, after the next compilation, your header file
475   will be overwritten by the old version from your source tree.
476   
477   This option is not typically used in @file{Makefile.omk}, but in the
478   top level configuration file @file{config.omk} or on command line.
479 @end defvar
480
481 @node Multiple Directories, Dependency Tracking, Libraries, OMK User's Manual
482 @section Multiple Directories
483
484 OMK is probably most useful in projects consisting of multiple
485 directories. For such projects, it is not easy to write from scratch
486 classic Makefiles that provides all the needed features.
487
488 You can instruct OMK to descend to a (sub)directory by setting the
489 @code{SUBDIRS} variable in @file{Makefile.omk}.
490
491 @defvar SUBDIRS
492   This variable contains a list of directories, in which compilation
493   must be also invoked. Usually, names of subdirectories are used, but
494   you can use any path specification here.
495
496   Compilation is invoked in these directories before it is invoked in
497   the current directory.
498 @end defvar
499 @c TODO: Write tests for this.
500
501 @defvar ALL_OMK_SUBDIRS
502   This variable is set by OMK and can be used as the value of
503   @code{SUBDIRS} variable. It contains a list of all direct
504   subdirectories, which contain @file{Makefile.omk}. This is especially
505   useful if you are combining several projects or components
506   together. In the root directory of your project, you just create
507   symbolic links the components from other projects and all the linked
508   directories automatically appears as the value of this variable.
509
510   @example
511   SUBDIRS = $(ALL_OMK_SUBDIRS)
512   @end example
513 @end defvar
514
515 @node Dependency Tracking, Configuration and Conditional Compilation, Multiple Directories, OMK User's Manual
516 @section Dependency Tracking
517
518 OMK automatically handles tracking of dependencies of files in compiled
519 projects. It uses gcc's @option{-M@var{x}} options to do this for object
520 files. This way, whenever you change some header file, OMK recompiles
521 only those files, where the changed header was really included.
522
523 Dependencies are also maintained for libraries and binaries. To find the
524 dependencies, OMK parses linker map files, so a change to some library
525 causes recompilation of all programs using that library.
526
527 @node Configuration and Conditional Compilation, Advanced OMK Features, Dependency Tracking, OMK User's Manual
528 @section Configuration and Conditional Compilation
529
530 In many projects, it is necessary to configure a compilation process. By
531 this configuring we mean, setting some parameters that influence the
532 output of compilation process. In GNU projects, @command{configure}
533 script is usually responsible for configuration. User provides some
534 parameters to @command{configure}, which is run before compilation, and
535 this script does all steps needed to configure the sources and
536 make-system in the desired way.
537
538 OMK has its own configuration mechanism, which is described in this
539 section. For future releases, we plan that this mechanism can make use
540 of GNU Autoconf, but currently there is no directly integrated support
541 for it.
542
543 In every directory you can specify some configuration parameters, which
544 can be modified by a user. Then, when @command{make default-config} is
545 run, all these parameters are found and together with their default
546 values are stored as makefile variables in
547 @file{config.omk-default}. This file is included during compilation, so
548 if you don't specify other values, these defaults are used. If you are
549 not satisfied with these defaults, you can override the values of
550 parameters in @file{config.omk}. This file is also included during
551 compilation and variables mentioned there takes precedence over those
552 specified in @file{config.omk-default}. Both @file{config.omk} and
553 @file{config.omk-default} have to be stored in the same directory as
554 @file{Makefile.rules}.
555
556 Besides overriding the default values of configuration parameters,
557 @file{config.omk} can also be used as a common place to store some
558 global settings that applies to the whole project, e.g. the compiler to
559 use or common compiler flags.
560
561 @subsection Specifying Configuration Parameters
562
563 To specify names and default values of configuration parameters use the
564 @code{default_CONFIG} variable in @file{Makefile.omk}.
565
566 @defvar default_CONFIG
567   This variable contains a list of configuration parameters and their
568   default values. The format of every item in this list is
569   @var{CONFIG_xxxx}=@var{value}. You can name the parameter as you want,
570   but it is good practice to start the name with @samp{CONFIG_} prefix.
571    
572   OMK can automatically generate header files, with C preprocessor macro
573   definitions according to the OMK's configuration parameters. The
574   actual content of generated header files depends on the form of the
575   @var{value}. The possible forms are:
576   
577 @table @code 
578 @item @samp{y}, @samp{n} or @samp{x}
579   This defines boolean parameters. If the value of the parameter is
580   @samp{y}, the @samp{#define CONFIG_@var{xxx} 1} is generated, if it is
581   @samp{n}, no @code{#define} is generated. 
582
583   @samp{x} is a special value called @emph{recessive 'n'}. The meaning
584   is that this parameter influences the component in the current
585   directory (i.e. the corresponding @code{#define} will be included in
586   @code{LOCAL_CONFIG_H}; see @ref{LOCAL_CONFIG_H}) but the default value
587   is not specified here. If the default value is not specified anywhere,
588   the behavior is the same as if @samp{n} is specified.
589 @item @samp{number}
590   Numeric parameters. The define looks like @samp{#define CONFIG_@var{xxx} @var{number}}
591 @item @samp{text}
592   Text without quotes. The define looks like @samp{#define CONFIG_@var{xxx} @var{text}}
593 @item @samp{"text"}
594   Text with quotes. The define looks like @samp{#define CONFIG_@var{xxx} "@var{text}"}
595 @end table
596 @end defvar
597
598 @noindent Example of using @code{default_CONFIG}. @file{Makefile.omk} reads like:
599 @example
600 @verbatiminclude ../tests/config/default/Makefile.omk
601 @end example
602 @noindent and @file{subdir/Makefile.omk} like:
603 @example
604 @verbatiminclude ../tests/config/default/subdir/Makefile.omk
605 @end example
606
607 @noindent After running @command{make default-config}, the content of
608 @file{config.omk-default} will be:
609 @example
610 @verbatiminclude ../tests/config/default/config.omk-correct
611 @end example
612
613 @subsection Using Configuration Parameters
614
615 Configuration parameters can be used in two ways:
616 @enumerate
617 @item
618   as variables in @file{Makefile.omk} and
619 @item
620   as C/C++ preprocessor macros in OMK generated header files.
621 @end enumerate
622
623 @noindent For the first use, your @file{Makefile.omk} may contain something like:
624 @example
625 SUBDIRS = arch/$(CONFIG_ARCH)
626
627 ifeq ($(CONFIG_DEBUG),y)
628 DEFS += -DUSE_SIMULATOR
629 endif
630 @end example
631
632 @noindent For the second use, there are several variables that control
633 the generation of header files with configuration values. These
634 variables are described here:
635
636 @anchor{LOCAL_CONFIG_H}
637 @defvar LOCAL_CONFIG_H
638   The value of this variable is the name of a header file, which will
639   contain all configuration parameters declared in the current directory
640   by @code{default_CONFIG}. This header file is accessible only by files
641   in the current directory and it should be included like @code{#include
642   "@var{myconfig.h}"}.
643
644   In @file{Makefile.omk}, the use of this variable can look like this:
645
646 @example
647 LOCAL_CONFIG_H = myconfig.h
648 @end example
649 @end defvar
650
651 @defvar config_include_HEADERS
652   This variable is similar to @code{LOCAL_CONFIG_H}. One difference is
653   that the generated header file is accessible to all sub-projects in
654   all directories, not only to the files in the same directory (the
655   header is stored in @file{_compiled} tree). The second difference is
656   that you have to specify, which configuration parameters you want to
657   appear in the header file.
658 @end defvar
659
660 @defvar xxx_DEFINES
661   This variable determines the configuration parameters that should be
662   stored in a header file specified by
663   @code{config_include_HEADERS}. The @var{xxx} in the name of this
664   variable needs to be the same as the base name (without extension) of
665   the header file.
666 @end defvar
667
668 @noindent Example of using @code{config_include_HEADERS}:
669 @example
670 default_CONFIG = CONFIG_LINCAN=y CONFIG_LINCANRTL=n CONFIG_LINCANVME=n
671 config_include_HEADERS = global.h
672 global_DEFINES = CONFIG_OC_LINCAN CONFIG_OC_LINCANRTL 
673 @end example
674
675 @noindent Here, we include only two out of the three configuration 
676 parameters defined in the current @file{Makefile.omk}. It is also
677 possible to include configuration parameters defined in a different
678 directory.
679
680 @subsection Common Variables
681
682 It is common practice to use @file{config.omk} to store project-wide
683 settings. Here is the list of variables, which are commonly set here
684 (but they can also be set elsewhere, e.g. in @file{Makefile.omk}).
685
686 You can easily ``reconfigure'' your project by changing the
687 @file{config.omk} file. It is useful to have several configurations
688 stored in different files and let @file{config.omk} be a symbolic link
689 to the desired configuration.
690
691 @vtable @code
692 @item CC
693   The name of C compiler.
694 @item CFLAGS
695   Command line options for C compiler.
696 @item CXX
697   The name of C++ compiler.
698 @item CPPFLAGS
699   Additional parameters (besides @code{CFLAGS}) to by passed to C++
700   compiler.
701 @end vtable
702
703 @node Advanced OMK Features, Running OMK under Windows OS, Configuration and Conditional Compilation, OMK User's Manual
704 @section Advanced OMK Features
705
706 In this section we list several OMK features, which are more complicated
707 or rarely used so they were omitted in previous sections.
708
709 @itemize
710 @item
711   The @file{_compiled} directory can be shared between multiple projects
712   (by using symbolic links).
713
714 @item
715   If you work on a bigger project, you usually don't need to rebuild the
716   whole project and call @command{make} only in a
717   subdirectory. Sometimes, it might be useful to rebuild the whole
718   project. You can either change working directory to the root of your
719   project and call @command{make} there or, as a shortcut, you can use
720   @code{W} variable (see @ref{W}) to compile everything directly from a
721   subdirectory.
722 @example
723 @code{make W=1}
724 @end example
725
726 @item
727   Searching for @file{Makefile.rules} works such way, that if you get
728   into sources directory over symbolic links, OMK is able to unwind your
729   steps back. This implies you can make links to component directories
730   on read-only media, copy @file{Makefile.rules}, @file{Makefile} and
731   top-level @file{Makefile.omk}, adjust @file{Makefile.omk} to contain
732   only required components and then call @command{make} in the top
733   directory or even in read-only directories after changing working
734   directory from your tree to readonly media.
735 @end itemize
736
737
738 @anchor{W}
739 @defvar W
740 If this variable equals to @samp{1}, the @b{whole} project is
741 (re)compiled, even if @command{make} is called from a subdirectory.
742 @end defvar
743
744
745
746  
747 @node Running OMK under Windows OS, Interfacing OMK to popular IDEs, Advanced OMK Features, OMK User's Manual
748 @section Running OMK under Windows OS
749
750 @node Interfacing OMK to popular IDEs, Troubleshooting, Running OMK under Windows OS, OMK User's Manual
751 @section Interfacing OMK to popular IDEs
752
753 @subsection KDevelop
754
755 KDevelop has support for custom build systems. To use KDevelop to
756 develop projects using OMK follow these steps. These steps are valid for
757 version 3.5.0 of KDevelop, but for previous versions it doesn't differ
758 much.
759
760 @enumerate
761 @item
762   Import project to KDevelop (from menu choose @emph{Project---Import
763   existing project}). Select the type of project to @emph{Generic C
764   Application (Custom Buildsystem)}.
765 @example
766   @image{kdevelop1}
767 @end example
768
769 @item
770   Then answer to following dialogs as you want.
771 @example
772   @image{kdevelop2}
773 @end example
774 @example
775   @image{kdevelop3} @image{kdevelop4}
776 @end example
777
778 @item
779   If you are working only on some small part of the bigger project, you
780   usually don't want to recompile the whole project every time. In
781   @emph{Project---Project Options}, you can specify the subdirectory where to
782   run @command{make}.
783 @example
784   @image{kdevelop5}
785 @end example
786
787 @item
788   If you want to switch between several configurations easily (see also
789   @ref{Configuration and Conditional Compilation}), in the same dialog
790   you can add @option{-e} to make options. This makes environment variables
791   have higher precedence than those in @file{config.omk-default}. Then,
792   you can define several environments with different
793   @code{CONFIG_@var{xxx}} variables and their values.
794 @example
795   @image{kdevelop6}
796 @end example
797
798 @item
799   You can easily switch the configurations from @emph{Build---Make
800   Environment}.
801 @example
802   @image{kdevelop7}
803 @end example
804 @end enumerate
805
806
807 @subsection Eclipse
808
809 @subsection Emacs, VIM, etc.
810
811 Since OMK compilation is started by executing @command{make} command,
812 many common editors can work easily with OMK.
813
814 Under Emacs, you can use @command{compile} or @command{recompile}
815 commands as you are used to do.
816
817 @node Troubleshooting,  , Interfacing OMK to popular IDEs, OMK User's Manual
818 @section Troubleshooting
819
820 Renaming of some file => dependency problems.
821
822 Manual compilation ... V=1
823
824 @node Original README, OMK Development, OMK User's Manual, Top
825 @chapter Original README
826
827 Since this manual still doesn't cover all aspects of OMK, we include
828 here a @file{README.rules} file, which was written for the first version
829 of OMK.
830
831 @b{Important notice:} This make system uses features found in recent
832 versions of GNU Make program. If you encounter problems with package
833 building, check, that you use correct version of Make program.  The
834 Make older than version 3.80, could not be used.  Even Make version
835 3.80 has annoying bug which causes building fail with misleading
836 message "virtual memory exhausted".  Please, upgrade at least to
837 version 3.81 of GNU Make.
838
839 There is list of features which we want to solve with our make system:
840 @itemize
841 @item
842 Central @file{Makefile.rules} for most of components of a bigger project.
843
844 FIXME (our CAN framework includes more libraries common with our other
845 projects, we need to separate some utility libraries etc.)
846 @item
847 The rules in more spread Makefiles are way to the hell (update for
848 different kernel, RT-Linux etc would be nightmare in other case).
849 @item
850 Make system should allow to freely move cross-dependant components in
851 directory structure without need to update users of moved component (I
852 hate somethink like @option{-I../../sched/rtlshwq/include} in CAN makefiles for
853 example. If a component is renamed or version is added to then name,
854 all Makefiles in CAN will require update).
855 @item
856 Make system should be able to compile mutually cross-dependant
857 libraries and should ensure, that change in one component sources or
858 headers would result in relink or rebuild in components linked against
859 that library or including modified header file.
860 @item
861 Make system has to enable compilation out of OCERA full source tree
862 (we would lost many users of particular components in other case).
863 @item
864 Compile should be able to do all above work without need to install
865 any files before successful finish of build.
866 @item
867 Because we use some libraries for RT-Linux build and user-space build,
868 we need to solve how to compile from same sources to both targets.
869 @item
870 The build system should allow to call make for particular source
871 subdirectory. Time of recursive make through all subdirectories is
872 unacceptable.
873 @item
874 Make system should enable to build out of sources tree (else clean or
875 working with CVS sandbox gets fussy and simultaneous multiple targets
876 gets problematic).
877 @item
878 It would be good, if there is a possibility to call make from
879 read-only media sources.
880 @item
881 Make system should store results of build in some separate directory
882 structure to simple install and testing.
883 @item
884 Makefiles in sources directories should be simple.
885 @end itemize
886
887 There is probably only one alternative fully supporting above requirements
888 and it is GNU Autoheader...Automake...Autoconf... system.
889 But it is complicated and requires big amount of support files.
890 It would be acceptable if it could be easily used for OCERA framework.
891 But there are important show stoppers for that system:
892 @itemize
893 @item
894 It would require deep revision of all OCERA CVS contents and agreement
895 on this would be problematic
896 @item
897 This system is not well prepared for dual compilation for Linux and
898 RT-Linux sub-targets. It would mean many changes in default autoconf
899 setup to support this. Probably simplest way would be to rebuild GCC
900 tool chain for something like i586-elf-rtlinux.  This would require
901 even more space for OCERA development.
902 @end itemize
903
904 The problem calls for some solution, which would have minimal impact
905 on other components and would be elegant and would be maintainable
906 and small, because our main goal is components development and not
907 make systems development.
908
909 There is result of our trial. It is OMK make system.
910 The @file{Makefile} and @file{Makefile.omk} files should be in all source
911 directories. Common @file{Makefile.rules} file is required in the toplevel
912 sources directory. Alternatively this file could be moved
913 to link tree pointing into readonly media or can be anywhere
914 else if @code{MAKERULES_DIR} and @code{SOURCES_DIR} are specified.
915
916 @c !!! tohle tam nejak zmizelo, mozna by to chtelo skontrolovat, ze to
917 @c     sedi s aktualnim stavem
918
919
920 Syntax of Makefile.omk files is for usual cases compatible
921 to Automake's Makefile.am descriptions. There are specific targets
922 for RT-Linux and Linux kernel related stuff
923
924 Makefile.omk user defined variables
925 @vtable @code
926 @item SUBDIRS
927 list of subdirectories intended for make from actual directory
928 @item lib_LIBRARIES
929 list of the user-space libraries
930 @item shared_LIBRARIES
931 list of the user-space shared libraries
932 @item kernel_LIBRARIES
933 list of the kernel-space libraries
934 @item rtlinux_LIBRARIES
935 list of the RT-Linux kernel-space libraries
936 @item include_HEADERS  
937 list of the user-space header files
938 @item nobase_include_HEADERS 
939 headers copied even with directory part
940 @item kernel_HEADERS   
941 list of the kernel-space  header files
942 @item rtlinux_HEADERS  
943 list of the RT-Linux kernel-space  header files
944 @item bin_PROGRAMS     
945 list of the require binary programs
946 @item utils_PROGRAMS   
947 list of the development utility programs
948 @item kernel_MODULES   
949 list of the kernel side modules/applications
950 @item rtlinux_MODULES  
951 list of RT-Linux the kernel side modules/applications
952 @item xxx_SOURCES      
953 list of specific target sources
954 @item INCLUDES         
955 additional include directories and defines for user-space
956 @item kernel_INCLUDES  
957 additional include directories and defines for kernel-space
958 @item rtlinux_INCLUDES 
959 additional include directories and defines for RT-Linux
960 @item default_CONFIG   
961 list of default config assignments CONFIG_XXX=y/n ...
962 @end vtable
963
964 The Makefile is same for all sources directories and is only 14 lines
965 long.  It is there only for convenience reasons to enable call "make"
966 from local directory. It contains code which locates
967 @file{Makefile.rules} in actual or any parent directory. With standard
968 BASH environment it works such way, that if you get into sources
969 directory over symbolic links, it is able to unwind yours steps back
970 => you can make links to readonly media component directories, copy
971 @file{Makefile.rules}, Makefile and toplevel Makefile.omk, adjust
972 Makefile.omk to contain only required components and then call make in
973 top or even directories after crossing from your tree to readonly
974 media.
975
976 The system compiles all files out of source directories.  The actual
977 version of system is adapted even for OCERA tree mode if
978 @code{OCERA_DIR} variable is defined in @file{Makefile.rules}
979
980 There are next predefined directory name components, which can be
981 adapted if required
982
983 @table @code
984 @item BUILD_DIR_NAME = _build
985         prefix of directory, where temporary build files are stored
986 @item COMPILED_DIR_NAME = _compiled
987         prefix of directory, where final compilation results are stored
988 @item GROUP_DIR_NAME = yyy
989         this is used for separation of build sub-trees in OCERA environment
990         where more @file{Makefile.rules} is spread in the tree
991 @end table
992
993 Next directories are used:
994
995 @table @code
996 @item KERN_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern
997         directory to store intermediate files for kernel-space targets
998 @item USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
999         directory to store intermediate files for user-space targets
1000
1001 @item USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
1002         directory to store exported include files which should be installed later
1003         on user-space include path
1004 @item USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
1005         same for user-pace libraries
1006 @item USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
1007         utilities for testing, which would not probably be installed
1008 @item USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
1009         binaries, which should go into directory on standard system PATH
1010         (/usr/local/bin, /usr/bin or $(prefix)/bin)
1011
1012 @item KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern
1013         directory to store exported include files which should be installed later
1014         on kernel-space include path
1015 @item KERN_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern
1016         same for kernel-pace libraries
1017 @item KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules
1018         builded modules for Linux kernel or RT-Linux system
1019 @end table
1020
1021 There is more recursive passes through directories to enable
1022 mutual dependant libraries and binaries to compile.
1023 Next passes are defined
1024
1025 @table @samp
1026 @item default-config
1027 generates @file{config.omk-default} or xxx-default (FIXME) configuration file
1028 @item check-dir 
1029 checks and creates required build directories
1030 @item include-pass   
1031 copies header files to @code{USER_INCLUDE_DIR} and @code{KERN_INCLUDE_DIR}
1032 @item library-pass
1033 builds objects in USER_BUILD_DIR/@var{relative path} and creates libraries
1034 in USER_LIB_DIR
1035 @item binary-pass and utils-pass
1036 links respective binaries in USER_@{BIN,UTILS@}_DIR directory. If some
1037 object file is missing it compiles it in USER_BUILD_DIR/@var{relative path}
1038 @item kernel-lib-pass
1039 builds libraries for kernel space targets
1040 @item kernel-pass 
1041 builds kernel modules
1042 @end table
1043
1044 The amount of passes is relatively high and consumes some time.  But
1045 only other way to support all required features is to assemble one big
1046 toplevel Makefile, which would contain all components and targets
1047 cross-dependencies.
1048
1049 Drawbacks of designed make system
1050 @itemize
1051 @item
1052 the system is not as fast as we would like
1053 @item
1054 it lacks Autoconf and configure extensive support for many systems
1055 from UNIX to DOS and WINDOWS
1056 @item
1057 it does not contain support for checking existence of target
1058 libraries and functionalities as GNU Autoconf
1059 @item
1060 it is heavily dependant on GNU MAKE program. But it would not be big
1061 problem, because even many commercial applications distribute GNU MAKE
1062 with them to be able to work in non-friendly systems
1063 @item
1064 the key drawback is dependence on recent MAKE version 3.80 and better
1065 and even version 3.80 of MAKE has important bug, which has been
1066 corrected in newer sources (FIXME)
1067 @end itemize
1068
1069 The last point is critical. I have not noticed it first, because
1070 I use Slackware-9.2 and it contains latest released version 
1071 of MAKE (version 3.80).
1072 The problem appears when I have tried to build bigger libraries.
1073 There is bug in version 3.80, which results in misleading
1074 error "Virtual memory exhausted". It is known bug with ID 1517
1075
1076 @smallexample
1077 * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
1078 @end smallexample
1079
1080
1081 I have optimized some rules to not push memory to the edge,
1082 but there could be still issues with 3.80 version.
1083
1084 I have downloaded latest MAKE CVS sources. The compilation required
1085 separate lookup and download for .po files and full Autoheader... cycle.
1086 I have put together package similar to release. Only ./configure --prefix=...
1087 and make is required. CVS sources contains version 3.81beta1.
1088 You can download prepared sources archive from
1089   @indicateurl{http://paulandlesley.org/make/make-3.81beta1.tar.bz2}
1090 Or you can get our local copy from
1091   @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz}
1092
1093 The archive contains even "make" binary build by me, which should work
1094 on other Linux distributions as well.  Older version of MAKE (3.79.x
1095 released about year 2000) found on Mandrake and RedHat are not
1096 sufficient and do not support eval feature.  I do not expect, that
1097 Debian would be more up-to-date or contain fixes to MAKE vm exhausted
1098 bug.
1099
1100 The local CTU archive with our CAN components prepared for inclusion
1101 into OCERA SF CVS could be found in my "can" directory
1102
1103   @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz}
1104
1105 The code should build for user-space with new make on most of Linux distros
1106 when make is updated.
1107
1108 If you want to test compile for RT-Linux targets, line
1109
1110 @example
1111 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
1112 @end example
1113
1114 in @file{Makefile.rules} has to be activated and updated
1115 to point RT-Linux directory containing "rtl.mk".
1116 There is only one library ("ulutrtl") and test utility compiled for RT-Linux
1117 (@file{can/utils/ulut/ul_rtlchk.c}).
1118
1119 The next line, if enabled, controls compilation in OCERA project tree
1120
1121 @example
1122 #OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
1123 @end example
1124
1125 The LinCAN driver has been updated to compile out of source directories.
1126
1127 Please, check, if you could compile CAN package and help us with integration
1128 into OCERA SF CVS. Send your comments and objections. 
1129
1130 The OMK system has been adapted to support actual OCERA configuration process.
1131 I am not happy with ocera.mk mix of defines and poor two or three rules,
1132 but OMK is able to overcome that.
1133
1134 The OMK system has integrated rules (default-config) to build default
1135 configuration file. The file is named @file{config.omk-default} for
1136 the stand-alone compilation.  The name corresponds to OCERA config +
1137 "-default" if OCERA_DIR is defined.  This file contains statements
1138 from all @code{default_CONFIG} lines in all @file{Makefile.omk}.  The
1139 file should be used for building of own @file{config.omk} file, or as
1140 list for all options if Kconfig is used.
1141
1142 @c @chapter OMK Reference
1143
1144 @node OMK Development, Variable Index, Original README, Top
1145 @chapter OMK Development
1146
1147
1148
1149 @node Variable Index,  , OMK Development, Top
1150 @unnumbered Variable Index
1151
1152 @printindex vr
1153
1154 @c @node Concept Index,  , Variable Index, Top
1155 @c @unnumbered Concept Index
1156 @c @printindex cp
1157
1158 @bye