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