]> rtime.felk.cvut.cz Git - omk/sssa.git/blob - doc/omk-manual.texinfo
Fixed LN_HEADERS in manual.
[omk/sssa.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 If your project uses an alternative make-system (e.g. Automake or custom
285 makefiles), it might be useful for you to use the command:
286 @example
287 @command{make omkize}
288 @end example
289 @noindent This will find all @file{Makefile.omk} files in all subdirectories
290 and copies generic @file{Makefile} from the root directory to that
291 subdirectories. This way you can easily switch your project to use OMK.
292
293
294
295 @anchor{V}
296 @defvar V
297 If this variable equals to @samp{1}, the whole command lines for all
298 executed commands are displayed. When not set or zero, only short
299 messages are printed. Value of @samp{2} displays the whole command lines
300 as with @samp{1} and in addition directory navigation messages are
301 printed.
302 @end defvar
303
304 @node Compiling Programs, Libraries, Invoking OMK, OMK User's Manual
305 @section Compiling Programs
306
307 To tell OMK to compile a program, you need to set some variables in
308 @file{Makefile.omk} (usually) in the directory where program sources are
309 located.
310
311 In the example bellow a program @command{test} will be compiled from
312 source @file{test.c}.
313
314 @example
315 @verbatiminclude ../tests/programs/Makefile.omk
316 @end example
317
318 @noindent The variables are:
319
320 @anchor{bin_PROGRAMS}
321 @defvar bin_PROGRAMS
322   Contains a list of names (whitespace separated) of programs to be
323   compiled in this directory.
324 @end defvar
325
326 @defvar test_PROGRAMS
327   Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
328   stored in @file{bin-tests} directory instead of @file{bin}. This
329   variable is intended for various test programs not to be mixed with
330   the final product.
331 @end defvar
332
333 @defvar utils_PROGRAMS
334   Almost the same as @ref{bin_PROGRAMS}, but resulting binaries are
335   stored in @file{bin-utils} directory instead of @file{bin}. This
336   variable is intended for various development utilities not to be mixed
337   with the final product.
338 @end defvar
339
340 @defvar xxx_SOURCES
341   For every program name @var{xxx} in @code{bin_PROGRAMS},
342   @code{test_PROGRAMS} or @code{utils_PROGRAMS}, this variable contains
343   a list of sources that are needed to compile the program. OMK uses an
344   extension of the filename to determine the compiler to compile this
345   source.
346 @end defvar
347
348 @defvar xxx_LIBS
349   This variable contains a list of libraries the program @var{xxx} will
350   be linked with.
351
352   @example
353   test_LIBS = m curses
354   @end example
355 @end defvar
356
357 @defvar LOADLIBES
358   This variable contains a list of libraries all programs in this
359   directory needs to be linked to.
360 @end defvar
361
362 @defvar INCLUDES
363   Directives passed to the C or C++ compiler with additional directories
364   to be searched for header files. In most cases you need to specify an
365   absolute path. To specify a directory relative to the source
366   directory, you can use the @code{$(SOURCES_DIR)} variable, which
367   refers to the directory, where @file{Makefile.omk} is located. This
368   variable applies to all compilations invoked in the current directory.
369
370   @example
371   INCLUDES = -I$(SOURCES_DIR)/my_include_dir
372   @end example
373 @end defvar
374
375 @defvar DEFS
376   Directives passed to the C or C++ compiler with preprocessor macro
377   definitions. This variable applies to all compilations invoked in the
378   current directory.
379
380   @example
381   DEFS = -DDEBUG=1
382   @end example
383 @end defvar
384
385
386 @c FIXME: INCLUDES variable should not be set by rtlinux rules.
387
388 @node Libraries, Multiple Directories, Compiling Programs, OMK User's Manual
389 @section Libraries
390
391
392 With OMK, you can easily create statically or dynamically linked
393 libraries. The way of creating libraries is very similar to how programs
394 are created. @xref{Compiling Programs}.
395
396 In @file{Makefile.omk}, you specify several variables, which defines how
397 the libraries should be compiled. In the example below the library
398 @samp{mylib} is created from two sources @file{funca.c} and
399 @file{funcb.c}. Interface of this library is defined in
400 @file{myfunc.h}. Therfore, we export this header for use by other
401 programs.
402
403 @example
404 @verbatiminclude ../tests/libraries/Makefile.omk
405 @end example
406
407 @noindent Variables for use with libraries are:
408
409 @defvar lib_LIBRARIES
410   Specifies a list of statically linked libraries to be compiled. 
411 @end defvar
412
413 @defvar shared_LIBRARIES
414   Specifies a list of dynamically linked libraries to be compiled. 
415 @end defvar
416
417 @defvar xxx_SOURCES
418   For every library name @var{xxx} in @code{lib_LIBRARIES} or
419   @code{shared_LIBRARIES}, this variable contains a list of sources that
420   are needed to compile the library. OMK uses an extension of the
421   filename to determine the compiler to compile this source.
422 @end defvar
423
424 @menu
425 * Header Files::                
426 @end menu
427
428 @node Header Files,  , Libraries, Libraries
429 @subsection Header Files
430
431 C and C++ libraries are not very useful without header files. OMK
432 provides several variables that specify activities on header files.
433
434 During compilation, header files are copied (or linked) from source
435 directories to the @file{_compiled} tree
436 (see @ref{include-pass}). Libraries and programs are then compiled against
437 these copies.
438
439 @anchor{include_HEADERS}
440 @defvar include_HEADERS
441   Specifies the list of header files to be exported for use by other
442   libraries/programs. The files are exported directly to the
443   @file{include} directory even if the file is located in a subdirectory
444   (like @file{sci_regs.h} in the example below)
445
446   @example
447   include_HEADERS = regs.h periph/sci_regs.h
448   @end example
449 @end defvar
450
451 @defvar nobase_include_HEADERS
452   Similar to @ref{include_HEADERS}, but the directory prefix is always
453   kept. To include the file exported by this variable, use
454   @code{#include <@var{prefix}/@var{header.h}>}.
455 @end defvar
456
457 @defvar renamed_include_HEADERS
458   Exports the header files under different name. The form of the items
459   in this whitespace separated list is: @var{real name}@code{->}@var{new
460   name}.
461
462 @example 
463   renamed_include_HEADERS = orte_config_omk_win32.h->orte_config.h
464 @end example
465 @end defvar
466
467 @defvar LN_HEADERS
468   If this variable equals to @samp{y}, symbolic links to headers in
469   source directories are used in @file{_compiled} tree instead of
470   copies.
471
472   Normally, the header files are copied into @file{_compiled} directory
473   to be prepared for transfer into target location afterwards. Copying
474   ensures that resulting libraries are in correspondence with the header
475   files even if the header is changed by a developer but the library is
476   not recompiled.
477
478 @c   Another reason for having single include directory for the whole
479 @c   project is tat every component knows where to find header files of
480 @c   other components. 
481
482   On the other side, the copying could make problems during
483   development. Most @acronym{IDE}s, allows you to jump directly to the
484   place, where an error is reported by the compiler. If the error is in
485   a header file, IDE opens you the copy of the header file. If you
486   correct the error there, after the next compilation, your header file
487   will be overwritten by the old version from your source tree.
488   
489   This option is not typically used in @file{Makefile.omk}, but in the
490   top level configuration file @file{config.omk} or on command line.
491 @end defvar
492
493 @node Multiple Directories, Dependency Tracking, Libraries, OMK User's Manual
494 @section Multiple Directories
495
496 OMK is probably most useful in projects consisting of multiple
497 directories. For such projects, it is not easy to write from scratch
498 classic Makefiles that provides all the needed features.
499
500 You can instruct OMK to descend to a (sub)directory by setting the
501 @code{SUBDIRS} variable in @file{Makefile.omk}.
502
503 @defvar SUBDIRS
504   This variable contains a list of directories, in which compilation
505   must be also invoked. Usually, names of subdirectories are used, but
506   you can use any path specification here.
507
508   Compilation is invoked in these directories before it is invoked in
509   the current directory.
510 @end defvar
511 @c TODO: Write tests for this.
512
513 @defvar ALL_OMK_SUBDIRS
514   This variable is set by OMK and can be used as the value of
515   @code{SUBDIRS} variable. It contains a list of all direct
516   subdirectories, which contain @file{Makefile.omk}. This is especially
517   useful if you are combining several projects or components
518   together. In the root directory of your project, you just create
519   symbolic links the components from other projects and all the linked
520   directories automatically appears as the value of this variable.
521
522   @example
523   SUBDIRS = $(ALL_OMK_SUBDIRS)
524   @end example
525 @end defvar
526
527 @node Dependency Tracking, Configuration and Conditional Compilation, Multiple Directories, OMK User's Manual
528 @section Dependency Tracking
529
530 OMK automatically handles tracking of dependencies of files in compiled
531 projects. It uses gcc's @option{-M@var{x}} options to do this for object
532 files. This way, whenever you change some header file, OMK recompiles
533 only those files, where the changed header was really included.
534
535 Dependencies are also maintained for libraries and binaries. To find the
536 dependencies, OMK parses linker map files, so a change to some library
537 causes recompilation of all programs using that library.
538
539 @node Configuration and Conditional Compilation, Advanced OMK Features, Dependency Tracking, OMK User's Manual
540 @section Configuration and Conditional Compilation
541
542 In many projects, it is necessary to configure a compilation process. By
543 this configuring we mean, setting some parameters that influence the
544 output of compilation process. In GNU projects, @command{configure}
545 script is usually responsible for configuration. User provides some
546 parameters to @command{configure}, which is run before compilation, and
547 this script does all steps needed to configure the sources and
548 make-system in the desired way.
549
550 OMK has its own configuration mechanism, which is described in this
551 section. For future releases, we plan that this mechanism can make use
552 of GNU Autoconf, but currently there is no directly integrated support
553 for it.
554
555 In every directory you can specify some configuration parameters, which
556 can be modified by a user. Then, when @command{make default-config} is
557 run, all these parameters are found and together with their default
558 values are stored as makefile variables in
559 @file{config.omk-default}. This file is included during compilation, so
560 if you don't specify other values, these defaults are used. If you are
561 not satisfied with these defaults, you can override the values of
562 parameters in @file{config.omk}. This file is also included during
563 compilation and variables mentioned there takes precedence over those
564 specified in @file{config.omk-default}. Both @file{config.omk} and
565 @file{config.omk-default} have to be stored in the same directory as
566 @file{Makefile.rules}.
567
568 Besides overriding the default values of configuration parameters,
569 @file{config.omk} can also be used as a common place to store some
570 global settings that applies to the whole project, e.g. the compiler to
571 use or common compiler flags.
572
573 @subsection Specifying Configuration Parameters
574
575 To specify names and default values of configuration parameters use the
576 @code{default_CONFIG} variable in @file{Makefile.omk}.
577
578 @defvar default_CONFIG
579   This variable contains a list of configuration parameters and their
580   default values. The format of every item in this list is
581   @var{CONFIG_xxxx}=@var{value}. You can name the parameter as you want,
582   but it is good practice to start the name with @samp{CONFIG_} prefix.
583    
584   OMK can automatically generate header files, with C preprocessor macro
585   definitions according to the OMK's configuration parameters. The
586   actual content of generated header files depends on the form of the
587   @var{value}. The possible forms are:
588   
589 @table @code 
590 @item @samp{y}, @samp{n} or @samp{x}
591   This defines boolean parameters. If the value of the parameter is
592   @samp{y}, the @samp{#define CONFIG_@var{xxx} 1} is generated, if it is
593   @samp{n}, no @code{#define} is generated. 
594
595   @samp{x} is a special value called @emph{recessive 'n'}. The meaning
596   is that this parameter influences the component in the current
597   directory (i.e. the corresponding @code{#define} will be included in
598   @code{LOCAL_CONFIG_H}; see @ref{LOCAL_CONFIG_H}) but the default value
599   is not specified here. If the default value is not specified anywhere,
600   the behavior is the same as if @samp{n} is specified.
601 @item @samp{number}
602   Numeric parameters. The define looks like @samp{#define CONFIG_@var{xxx} @var{number}}
603 @item @samp{text}
604   Text without quotes. The define looks like @samp{#define CONFIG_@var{xxx} @var{text}}
605 @item @samp{"text"}
606   Text with quotes. The define looks like @samp{#define CONFIG_@var{xxx} "@var{text}"}
607 @end table
608 @end defvar
609
610 @noindent Example of using @code{default_CONFIG}. @file{Makefile.omk} reads like:
611 @example
612 @verbatiminclude ../tests/config/default/Makefile.omk
613 @end example
614 @noindent and @file{subdir/Makefile.omk} like:
615 @example
616 @verbatiminclude ../tests/config/default/subdir/Makefile.omk
617 @end example
618
619 @noindent After running @command{make default-config}, the content of
620 @file{config.omk-default} will be:
621 @example
622 @verbatiminclude ../tests/config/default/config.omk-correct
623 @end example
624
625 @subsection Using Configuration Parameters
626
627 Configuration parameters can be used in two ways:
628 @enumerate
629 @item
630   as variables in @file{Makefile.omk} and
631 @item
632   as C/C++ preprocessor macros in OMK generated header files.
633 @end enumerate
634
635 @noindent For the first use, your @file{Makefile.omk} may contain something like:
636 @example
637 SUBDIRS = arch/$(CONFIG_ARCH)
638
639 ifeq ($(CONFIG_DEBUG),y)
640 DEFS += -DUSE_SIMULATOR
641 endif
642 @end example
643
644 @noindent For the second use, there are several variables that control
645 the generation of header files with configuration values. These
646 variables are described here:
647
648 @anchor{LOCAL_CONFIG_H}
649 @defvar LOCAL_CONFIG_H
650   The value of this variable is the name of a header file, which will
651   contain all configuration parameters declared in the current directory
652   by @code{default_CONFIG}. This header file is accessible only by files
653   in the current directory and it should be included like @code{#include
654   "@var{myconfig.h}"}.
655
656   In @file{Makefile.omk}, the use of this variable can look like this:
657
658 @example
659 LOCAL_CONFIG_H = myconfig.h
660 @end example
661 @end defvar
662
663 @defvar config_include_HEADERS
664   This variable is similar to @code{LOCAL_CONFIG_H}. One difference is
665   that the generated header file is accessible to all sub-projects in
666   all directories, not only to the files in the same directory (the
667   header is stored in @file{_compiled} tree). The second difference is
668   that you have to specify, which configuration parameters you want to
669   appear in the header file.
670 @end defvar
671
672 @defvar xxx_DEFINES
673   This variable determines the configuration parameters that should be
674   stored in a header file specified by
675   @code{config_include_HEADERS}. The @var{xxx} in the name of this
676   variable needs to be the same as the base name (without extension) of
677   the header file.
678 @end defvar
679
680 @noindent Example of using @code{config_include_HEADERS}:
681 @example
682 default_CONFIG = CONFIG_LINCAN=y CONFIG_LINCANRTL=n CONFIG_LINCANVME=n
683 config_include_HEADERS = global.h
684 global_DEFINES = CONFIG_OC_LINCAN CONFIG_OC_LINCANRTL 
685 @end example
686
687 @noindent Here, we include only two out of the three configuration 
688 parameters defined in the current @file{Makefile.omk}. It is also
689 possible to include configuration parameters defined in a different
690 directory.
691
692 @subsection Common Variables
693
694 It is common practice to use @file{config.omk} to store project-wide
695 settings. Here is the list of variables, which are commonly set here
696 (but they can also be set elsewhere, e.g. in @file{Makefile.omk}).
697
698 You can easily ``reconfigure'' your project by changing the
699 @file{config.omk} file. It is useful to have several configurations
700 stored in different files and let @file{config.omk} be a symbolic link
701 to the desired configuration.
702
703 @vtable @code
704 @item CC
705   The name of C compiler.
706 @item CFLAGS
707   Command line options for C compiler.
708 @item CXX
709   The name of C++ compiler.
710 @item CPPFLAGS
711   Additional parameters (besides @code{CFLAGS}) to by passed to C++
712   compiler.
713 @end vtable
714
715 @node Advanced OMK Features, Running OMK under Windows OS, Configuration and Conditional Compilation, OMK User's Manual
716 @section Advanced OMK Features
717
718 In this section we list several OMK features, which are more complicated
719 or rarely used so they were omitted in previous sections.
720
721 @itemize
722 @item
723   The @file{_compiled} directory can be shared between multiple projects
724   (by using symbolic links).
725
726 @item
727   If you work on a bigger project, you usually don't need to rebuild the
728   whole project and call @command{make} only in a
729   subdirectory. Sometimes, it might be useful to rebuild the whole
730   project. You can either change working directory to the root of your
731   project and call @command{make} there or, as a shortcut, you can use
732   @code{W} variable (see @ref{W}) to compile everything directly from a
733   subdirectory.
734 @example
735 @code{make W=1}
736 @end example
737
738 @item
739   Searching for @file{Makefile.rules} works such way, that if you get
740   into sources directory over symbolic links, OMK is able to unwind your
741   steps back. This implies you can make links to component directories
742   on read-only media, copy @file{Makefile.rules}, @file{Makefile} and
743   top-level @file{Makefile.omk}, adjust @file{Makefile.omk} to contain
744   only required components and then call @command{make} in the top
745   directory or even in read-only directories after changing working
746   directory from your tree to readonly media.
747 @end itemize
748
749
750 @anchor{W}
751 @defvar W
752 If this variable equals to @samp{1}, the @b{whole} project is
753 (re)compiled, even if @command{make} is called from a subdirectory.
754 @end defvar
755
756
757
758  
759 @node Running OMK under Windows OS, Interfacing OMK to popular IDEs, Advanced OMK Features, OMK User's Manual
760 @section Running OMK under Windows OS
761
762 @node Interfacing OMK to popular IDEs, Troubleshooting, Running OMK under Windows OS, OMK User's Manual
763 @section Interfacing OMK to popular IDEs
764
765 @subsection KDevelop
766
767 KDevelop has support for custom build systems. To use KDevelop to
768 develop projects using OMK follow these steps. These steps are valid for
769 version 3.5.0 of KDevelop, but for previous versions it doesn't differ
770 much.
771
772 @enumerate
773 @item
774   Import project to KDevelop (from menu choose @emph{Project---Import
775   existing project}). Select the type of project to @emph{Generic C
776   Application (Custom Buildsystem)}.
777 @example
778   @image{kdevelop1}
779 @end example
780
781 @item
782   Then answer to following dialogs as you want.
783 @example
784   @image{kdevelop2}
785 @end example
786 @example
787   @image{kdevelop3} @image{kdevelop4}
788 @end example
789
790 @item
791   If you are working only on some small part of the bigger project, you
792   usually don't want to recompile the whole project every time. In
793   @emph{Project---Project Options}, you can specify the subdirectory where to
794   run @command{make}.
795 @example
796   @image{kdevelop5}
797 @end example
798
799 @item
800   If you want to switch between several configurations easily (see also
801   @ref{Configuration and Conditional Compilation}), in the same dialog
802   you can add @option{-e} to make options. This makes environment variables
803   have higher precedence than those in @file{config.omk-default}. Then,
804   you can define several environments with different
805   @code{CONFIG_@var{xxx}} variables and their values.
806 @example
807   @image{kdevelop6}
808 @end example
809
810 @item
811   You can easily switch the configurations from @emph{Build---Make
812   Environment}.
813 @example
814   @image{kdevelop7}
815 @end example
816 @end enumerate
817
818
819 @subsection Eclipse
820
821 @subsection Emacs, VIM, etc.
822
823 Since OMK compilation is started by executing @command{make} command,
824 many common editors can work easily with OMK.
825
826 Under Emacs, you can use @command{compile} or @command{recompile}
827 commands as you are used to do.
828
829 @node Troubleshooting,  , Interfacing OMK to popular IDEs, OMK User's Manual
830 @section Troubleshooting
831
832 @itemize
833 @item
834   If you rename some file or directory and then you can't compile your
835   project, call @command{make clean} in the directory with errors. The
836   reason for this behavior is that OMK remembers dependencies of every
837   file. After renaming something, the original name is still stored in
838   dependencies, but make doesn't know how to create this non-existent
839   source.
840
841 @item
842   Sometimes, you may want to compile one file the same way as OMK does
843   it, but run the compilation manually from command line. For example,
844   you want to debug some preprocessor macros and you only want to
845   produce preprocessed source instead of object file.
846
847   To compile something manually, you can run OMK with @command{make
848   V=2}. This will print all commands executed together with directory
849   navigation messages. Find the command you want to execute manually in
850   the output. To run it, you need to change the working directory to the
851   correct one in the @file{_build} tree. The correct directory can be
852   found in make output on the line @samp{Entering directory} preceding
853   the desired command.
854 @end itemize
855
856 @node Original README, OMK Development, OMK User's Manual, Top
857 @chapter Original README
858
859 Since this manual still doesn't cover all aspects of OMK, we include
860 here a @file{README.rules} file, which was written for the first version
861 of OMK.
862
863 @b{Important notice:} This make system uses features found in recent
864 versions of GNU Make program. If you encounter problems with package
865 building, check, that you use correct version of Make program.  The
866 Make older than version 3.80, could not be used.  Even Make version
867 3.80 has annoying bug which causes building fail with misleading
868 message "virtual memory exhausted".  Please, upgrade at least to
869 version 3.81 of GNU Make.
870
871 There is list of features which we want to solve with our make system:
872 @itemize
873 @item
874 Central @file{Makefile.rules} for most of components of a bigger project.
875
876 FIXME (our CAN framework includes more libraries common with our other
877 projects, we need to separate some utility libraries etc.)
878 @item
879 The rules in more spread Makefiles are way to the hell (update for
880 different kernel, RT-Linux etc would be nightmare in other case).
881 @item
882 Make system should allow to freely move cross-dependant components in
883 directory structure without need to update users of moved component (I
884 hate somethink like @option{-I../../sched/rtlshwq/include} in CAN makefiles for
885 example. If a component is renamed or version is added to then name,
886 all Makefiles in CAN will require update).
887 @item
888 Make system should be able to compile mutually cross-dependant
889 libraries and should ensure, that change in one component sources or
890 headers would result in relink or rebuild in components linked against
891 that library or including modified header file.
892 @item
893 Make system has to enable compilation out of OCERA full source tree
894 (we would lost many users of particular components in other case).
895 @item
896 Compile should be able to do all above work without need to install
897 any files before successful finish of build.
898 @item
899 Because we use some libraries for RT-Linux build and user-space build,
900 we need to solve how to compile from same sources to both targets.
901 @item
902 The build system should allow to call make for particular source
903 subdirectory. Time of recursive make through all subdirectories is
904 unacceptable.
905 @item
906 Make system should enable to build out of sources tree (else clean or
907 working with CVS sandbox gets fussy and simultaneous multiple targets
908 gets problematic).
909 @item
910 It would be good, if there is a possibility to call make from
911 read-only media sources.
912 @item
913 Make system should store results of build in some separate directory
914 structure to simple install and testing.
915 @item
916 Makefiles in sources directories should be simple.
917 @end itemize
918
919 There is probably only one alternative fully supporting above requirements
920 and it is GNU Autoheader...Automake...Autoconf... system.
921 But it is complicated and requires big amount of support files.
922 It would be acceptable if it could be easily used for OCERA framework.
923 But there are important show stoppers for that system:
924 @itemize
925 @item
926 It would require deep revision of all OCERA CVS contents and agreement
927 on this would be problematic
928 @item
929 This system is not well prepared for dual compilation for Linux and
930 RT-Linux sub-targets. It would mean many changes in default autoconf
931 setup to support this. Probably simplest way would be to rebuild GCC
932 tool chain for something like i586-elf-rtlinux.  This would require
933 even more space for OCERA development.
934 @end itemize
935
936 The problem calls for some solution, which would have minimal impact
937 on other components and would be elegant and would be maintainable
938 and small, because our main goal is components development and not
939 make systems development.
940
941 There is result of our trial. It is OMK make system.
942 The @file{Makefile} and @file{Makefile.omk} files should be in all source
943 directories. Common @file{Makefile.rules} file is required in the toplevel
944 sources directory. Alternatively this file could be moved
945 to link tree pointing into readonly media or can be anywhere
946 else if @code{MAKERULES_DIR} and @code{SOURCES_DIR} are specified.
947
948 @c !!! tohle tam nejak zmizelo, mozna by to chtelo skontrolovat, ze to
949 @c     sedi s aktualnim stavem
950
951
952 Syntax of Makefile.omk files is for usual cases compatible
953 to Automake's Makefile.am descriptions. There are specific targets
954 for RT-Linux and Linux kernel related stuff
955
956 Makefile.omk user defined variables
957 @vtable @code
958 @item SUBDIRS
959 list of subdirectories intended for make from actual directory
960 @item lib_LIBRARIES
961 list of the user-space libraries
962 @item shared_LIBRARIES
963 list of the user-space shared libraries
964 @item kernel_LIBRARIES
965 list of the kernel-space libraries
966 @item rtlinux_LIBRARIES
967 list of the RT-Linux kernel-space libraries
968 @item include_HEADERS  
969 list of the user-space header files
970 @item nobase_include_HEADERS 
971 headers copied even with directory part
972 @item kernel_HEADERS   
973 list of the kernel-space  header files
974 @item rtlinux_HEADERS  
975 list of the RT-Linux kernel-space  header files
976 @item bin_PROGRAMS     
977 list of the require binary programs
978 @item utils_PROGRAMS   
979 list of the development utility programs
980 @item kernel_MODULES   
981 list of the kernel side modules/applications
982 @item rtlinux_MODULES  
983 list of RT-Linux the kernel side modules/applications
984 @item xxx_SOURCES      
985 list of specific target sources
986 @item INCLUDES         
987 additional include directories and defines for user-space
988 @item kernel_INCLUDES  
989 additional include directories and defines for kernel-space
990 @item rtlinux_INCLUDES 
991 additional include directories and defines for RT-Linux
992 @item default_CONFIG   
993 list of default config assignments CONFIG_XXX=y/n ...
994 @end vtable
995
996 The Makefile is same for all sources directories and is only 14 lines
997 long.  It is there only for convenience reasons to enable call "make"
998 from local directory. It contains code which locates
999 @file{Makefile.rules} in actual or any parent directory. With standard
1000 BASH environment it works such way, that if you get into sources
1001 directory over symbolic links, it is able to unwind yours steps back
1002 => you can make links to readonly media component directories, copy
1003 @file{Makefile.rules}, Makefile and toplevel Makefile.omk, adjust
1004 Makefile.omk to contain only required components and then call make in
1005 top or even directories after crossing from your tree to readonly
1006 media.
1007
1008 The system compiles all files out of source directories.  The actual
1009 version of system is adapted even for OCERA tree mode if
1010 @code{OCERA_DIR} variable is defined in @file{Makefile.rules}
1011
1012 There are next predefined directory name components, which can be
1013 adapted if required
1014
1015 @table @code
1016 @item BUILD_DIR_NAME = _build
1017         prefix of directory, where temporary build files are stored
1018 @item COMPILED_DIR_NAME = _compiled
1019         prefix of directory, where final compilation results are stored
1020 @item GROUP_DIR_NAME = yyy
1021         this is used for separation of build sub-trees in OCERA environment
1022         where more @file{Makefile.rules} is spread in the tree
1023 @end table
1024
1025 Next directories are used:
1026
1027 @table @code
1028 @item KERN_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern
1029         directory to store intermediate files for kernel-space targets
1030 @item USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
1031         directory to store intermediate files for user-space targets
1032
1033 @item USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
1034         directory to store exported include files which should be installed later
1035         on user-space include path
1036 @item USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
1037         same for user-pace libraries
1038 @item USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
1039         utilities for testing, which would not probably be installed
1040 @item USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
1041         binaries, which should go into directory on standard system PATH
1042         (/usr/local/bin, /usr/bin or $(prefix)/bin)
1043
1044 @item KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern
1045         directory to store exported include files which should be installed later
1046         on kernel-space include path
1047 @item KERN_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern
1048         same for kernel-pace libraries
1049 @item KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules
1050         builded modules for Linux kernel or RT-Linux system
1051 @end table
1052
1053 There is more recursive passes through directories to enable
1054 mutual dependant libraries and binaries to compile.
1055 Next passes are defined
1056
1057 @table @samp
1058 @item default-config
1059 generates @file{config.omk-default} or xxx-default (FIXME) configuration file
1060 @item check-dir 
1061 checks and creates required build directories
1062 @item include-pass   
1063 copies header files to @code{USER_INCLUDE_DIR} and @code{KERN_INCLUDE_DIR}
1064 @item library-pass
1065 builds objects in USER_BUILD_DIR/@var{relative path} and creates libraries
1066 in USER_LIB_DIR
1067 @item binary-pass and utils-pass
1068 links respective binaries in USER_@{BIN,UTILS@}_DIR directory. If some
1069 object file is missing it compiles it in USER_BUILD_DIR/@var{relative path}
1070 @item kernel-lib-pass
1071 builds libraries for kernel space targets
1072 @item kernel-pass 
1073 builds kernel modules
1074 @end table
1075
1076 The amount of passes is relatively high and consumes some time.  But
1077 only other way to support all required features is to assemble one big
1078 toplevel Makefile, which would contain all components and targets
1079 cross-dependencies.
1080
1081 Drawbacks of designed make system
1082 @itemize
1083 @item
1084 the system is not as fast as we would like
1085 @item
1086 it lacks Autoconf and configure extensive support for many systems
1087 from UNIX to DOS and WINDOWS
1088 @item
1089 it does not contain support for checking existence of target
1090 libraries and functionalities as GNU Autoconf
1091 @item
1092 it is heavily dependant on GNU MAKE program. But it would not be big
1093 problem, because even many commercial applications distribute GNU MAKE
1094 with them to be able to work in non-friendly systems
1095 @item
1096 the key drawback is dependence on recent MAKE version 3.80 and better
1097 and even version 3.80 of MAKE has important bug, which has been
1098 corrected in newer sources (FIXME)
1099 @end itemize
1100
1101 The last point is critical. I have not noticed it first, because
1102 I use Slackware-9.2 and it contains latest released version 
1103 of MAKE (version 3.80).
1104 The problem appears when I have tried to build bigger libraries.
1105 There is bug in version 3.80, which results in misleading
1106 error "Virtual memory exhausted". It is known bug with ID 1517
1107
1108 @smallexample
1109 * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
1110 @end smallexample
1111
1112
1113 I have optimized some rules to not push memory to the edge,
1114 but there could be still issues with 3.80 version.
1115
1116 I have downloaded latest MAKE CVS sources. The compilation required
1117 separate lookup and download for .po files and full Autoheader... cycle.
1118 I have put together package similar to release. Only ./configure --prefix=...
1119 and make is required. CVS sources contains version 3.81beta1.
1120 You can download prepared sources archive from
1121   @indicateurl{http://paulandlesley.org/make/make-3.81beta1.tar.bz2}
1122 Or you can get our local copy from
1123   @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz}
1124
1125 The archive contains even "make" binary build by me, which should work
1126 on other Linux distributions as well.  Older version of MAKE (3.79.x
1127 released about year 2000) found on Mandrake and RedHat are not
1128 sufficient and do not support eval feature.  I do not expect, that
1129 Debian would be more up-to-date or contain fixes to MAKE vm exhausted
1130 bug.
1131
1132 The local CTU archive with our CAN components prepared for inclusion
1133 into OCERA SF CVS could be found in my "can" directory
1134
1135   @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz}
1136
1137 The code should build for user-space with new make on most of Linux distros
1138 when make is updated.
1139
1140 If you want to test compile for RT-Linux targets, line
1141
1142 @example
1143 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
1144 @end example
1145
1146 in @file{Makefile.rules} has to be activated and updated
1147 to point RT-Linux directory containing "rtl.mk".
1148 There is only one library ("ulutrtl") and test utility compiled for RT-Linux
1149 (@file{can/utils/ulut/ul_rtlchk.c}).
1150
1151 The next line, if enabled, controls compilation in OCERA project tree
1152
1153 @example
1154 #OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
1155 @end example
1156
1157 The LinCAN driver has been updated to compile out of source directories.
1158
1159 Please, check, if you could compile CAN package and help us with integration
1160 into OCERA SF CVS. Send your comments and objections. 
1161
1162 The OMK system has been adapted to support actual OCERA configuration process.
1163 I am not happy with ocera.mk mix of defines and poor two or three rules,
1164 but OMK is able to overcome that.
1165
1166 The OMK system has integrated rules (default-config) to build default
1167 configuration file. The file is named @file{config.omk-default} for
1168 the stand-alone compilation.  The name corresponds to OCERA config +
1169 "-default" if OCERA_DIR is defined.  This file contains statements
1170 from all @code{default_CONFIG} lines in all @file{Makefile.omk}.  The
1171 file should be used for building of own @file{config.omk} file, or as
1172 list for all options if Kconfig is used.
1173
1174 @c @chapter OMK Reference
1175
1176 @node OMK Development, Variable Index, Original README, Top
1177 @chapter OMK Development
1178
1179
1180
1181 @node Variable Index,  , OMK Development, Top
1182 @unnumbered Variable Index
1183
1184 @printindex vr
1185
1186 @c @node Concept Index,  , Variable Index, Top
1187 @c @unnumbered Concept Index
1188 @c @printindex cp
1189
1190 @bye