]> rtime.felk.cvut.cz Git - omk.git/blob - doc/manual.texinfo
More documentation and some test to what is written in documentation.
[omk.git] / doc / manual.texinfo
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename omk
4 @settitle 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
24 @top Ocera Make System
25
26 @insertcopying
27 @end ifnottex
28
29
30 @node Overview of OMK
31 @chapter OMK Overview
32 @cindex overview
33
34 OMK is an advanced make system written entirely in GNU make. Compiling
35 software using OMK requires only GNU make binary and standard UNIX
36 utilities (@command{sh}, @command{sed} and
37 @command{tr}@footnote{@command{tr} is needed only for OMK to be
38 compatible with MinGW.}) installed. OMK aims to be developer friendly; to
39 use OMK, you do not need to understand (sometimes) cryptic syntax of
40 makefile commands.
41
42 OMK handles properly dependencies of source files and libraries, so it
43 is not necessary to recompile the whole project if only some files are
44 changed. Also OMK greatly simplifies compilation of projects, where
45 source files are spread between multiple directories. It is also very
46 useful in combining components (libraries) from different projects to a
47 single project.
48
49 You can use OMK on all platforms where you can run GNU Make including
50 Cygwin and MinGW. MS DOS was not tested.
51
52 @c @section Features
53
54 @c @itemize
55 @c @item
56 @c Easy to use for beginners.
57 @c @item
58 @c Automatic handling of dependencies.
59 @c @item
60 @c Supported host platforms: all Un*x operating system including Linux,
61 @c Cygwin, MS DOS and maybe others.
62 @c @end itemize
63
64 @section Why to Use OMK?
65
66 @section Quick Start
67
68 If you get some sources, which are distributed with OMK, usually the
69 following commands are sufficient to compile the whole project.
70
71 @example
72 @verbatim
73 make default-config
74 make
75 @end verbatim
76 @end example
77
78 To use OMK in your own project, follow these steps:
79
80 @enumerate
81 @item
82   Take appropriate @file{Makefile.rules}, put it together with leaf
83   @file{Makefile} to the root directory of your project.
84 @item
85   Create @file{Makefile.omk} files in all directories you want to
86   compile something. Please refer to chapter ... to learn what to write
87   in @file{Makefile.omk} files.
88 @item
89   Run @command{make omkize} in the root directory.
90 @end enumerate
91
92 Your project is now ready to compile.
93
94
95 @node History
96 @section History
97
98 OMK was originally written by Pavel Pisa as a solution to have one
99 common make system for OCERA project, where we needed to compile
100 user-space programs, Linux kernel modules and RT Linux modules in one
101 package. Although this system was not accepted for the whole OCERA
102 project. Several individual developers (mostly from Czech Technical
103 University) liked it and started to use it.
104
105 As a number of projects using OMK grew it was necessary to modularize
106 the make system to support more ``targets''. Michal Sojka took care
107 about the process of modularization.
108
109 @chapter Original README
110
111 @b{Important notice:} This make system uses features found in recent
112 versions of GNU Make program. If you encounter problems with package
113 building, check, that you use correct version of Make program.  The
114 Make older than version 3.80, could not be used.  Even Make version
115 3.80 has annoying bug which causes building fail with misleading
116 message "virtual memory exhausted".  Please, upgrade at least to
117 version 3.81 of GNU Make.
118
119 There is list of features which we want to solve with our make system:
120 @itemize
121 @item
122 Central @file{Makefile.rules} for most of components of a bigger project.
123
124 FIXME (our CAN framework includes more libraries common with our other
125 projects, we need to separate some utility libraries etc.)
126 @item
127 The rules in more spread Makefiles are way to the hell (update for
128 different kernel, RT-Linux etc would be nightmare in other case).
129 @item
130 Make system should allow to freely move cross-dependant components in
131 directory structure without need to update users of moved component (I
132 hate somethink like @option{-I../../sched/rtlshwq/include} in CAN makefiles for
133 example. If a component is renamed or version is added to then name,
134 all Makefiles in CAN will require update).
135 @item
136 Make system should be able to compile mutually cross-dependant
137 libraries and should ensure, that change in one component sources or
138 headers would result in relink or rebuild in components linked against
139 that library or including modified header file.
140 @item
141 Make system has to enable compilation out of OCERA full source tree
142 (we would lost many users of particular components in other case).
143 @item
144 Compile should be able to do all above work without need to install
145 any files before successful finish of build.
146 @item
147 Because we use some libraries for RT-Linux build and user-space build,
148 we need to solve how to compile from same sources to both targets.
149 @item
150 The build system should allow to call make for particular source
151 subdirectory. Time of recursive make through all subdirectories is
152 unacceptable.
153 @item
154 Make system should enable to build out of sources tree (else clean or
155 working with CVS sandbox gets fussy and simultaneous multiple targets
156 gets problematic).
157 @item
158 It would be good, if there is a possibility to call make from
159 read-only media sources.
160 @item
161 Make system should store results of build in some separate directory
162 structure to simple install and testing.
163 @item
164 Makefiles in sources directories should be simple.
165 @end itemize
166
167 There is probably only one alternative fully supporting above requirements
168 and it is GNU Autoheader...Automake...Autoconf... system.
169 But it is complicated and requires big amount of support files.
170 It would be acceptable if it could be easily used for OCERA framework.
171 But there are important show stoppers for that system:
172 @itemize
173 @item
174 It would require deep revision of all OCERA CVS contents and agreement
175 on this would be problematic
176 @item
177 This system is not well prepared for dual compilation for Linux and
178 RT-Linux sub-targets. It would mean many changes in default autoconf
179 setup to support this. Probably simplest way would be to rebuild GCC
180 tool chain for something like i586-elf-rtlinux.  This would require
181 even more space for OCERA development.
182 @end itemize
183
184 The problem calls for same solution, which would have minimal impact
185 on other components and would be elegant and would be maintainable
186 and small, because our main goal is components development and not
187 make systems development.
188
189 There is result of our trial. It is OMK make system.
190 The @file{Makefile} and @file{Makefile.omk} files should be in all source
191 directories. Common @file{Makefile.rules} file is required in the toplevel
192 sources directory. Alternatively this file could be moved
193 to link tree pointing into readonly media or can be anywhere
194 else if @code{MAKERULES_DIR} and @code{SOURCES_DIR} are specified.
195
196 Syntax of Makefile.omk files is for usual cases compatible
197 to Automake's Makefile.am descriptions. There are specific targets
198 for RT-Linux and Linux kernel related stuff
199
200 Makefile.omk user defined variables
201 @vtable @code
202 @item SUBDIRS
203 list of subdirectories intended for make from actual directory
204 @item lib_LIBRARIES
205 list of the user-space libraries
206 @item shared_LIBRARIES
207 list of the user-space shared libraries
208 @item kernel_LIBRARIES
209 list of the kernel-space libraries
210 @item rtlinux_LIBRARIES
211 list of the RT-Linux kernel-space libraries
212 @item include_HEADERS  
213 list of the user-space header files
214 @item nobase_include_HEADERS 
215 headers copied even with directory part
216 @item kernel_HEADERS   
217 list of the kernel-space  header files
218 @item rtlinux_HEADERS  
219 list of the RT-Linux kernel-space  header files
220 @item bin_PROGRAMS     
221 list of the require binary programs
222 @item utils_PROGRAMS   
223 list of the development utility programs
224 @item kernel_MODULES   
225 list of the kernel side modules/applications
226 @item rtlinux_MODULES  
227 list of RT-Linux the kernel side modules/applications
228 @item xxx_SOURCES      
229 list of specific target sources
230 @item INCLUDES         
231 additional include directories and defines for user-space
232 @item kernel_INCLUDES  
233 additional include directories and defines for kernel-space
234 @item rtlinux_INCLUDES 
235 additional include directories and defines for RT-Linux
236 @item default_CONFIG   
237 list of default config assignments CONFIG_XXX=y/n ...
238 @end vtable
239
240 The Makefile is same for all sources directories and is only 14 lines
241 long.  It is there only for convenience reasons to enable call "make"
242 from local directory. It contains code which locates
243 @file{Makefile.rules} in actual or any parent directory. With standard
244 BASH environment it works such way, that if you get into sources
245 directory over symbolic links, it is able to unwind yours steps back
246 => you can make links to readonly media component directories, copy
247 @file{Makefile.rules}, Makefile and toplevel Makefile.omk, adjust
248 Makefile.omk to contain only required components and then call make in
249 top or even directories after crossing from your tree to readonly
250 media.
251
252 The system compiles all files out of source directories.  The actual
253 version of system is adapted even for OCERA tree mode if
254 @code{OCERA_DIR} variable is defined in @file{Makefile.rules}
255
256 There are next predefined directory name components, which can be
257 adapted if required
258
259 @table @code
260 @item BUILD_DIR_NAME = _build
261         prefix of directory, where temporary build files are stored
262 @item COMPILED_DIR_NAME = _compiled
263         prefix of directory, where final compilation results are stored
264 @item GROUP_DIR_NAME = yyy
265         this is used for separation of build sub-trees in OCERA environment
266         where more @file{Makefile.rules} is spread in the tree
267 @end table
268
269 Next directories are used:
270
271 @table @code
272 @item KERN_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern
273         directory to store intermediate files for kernel-space targets
274 @item USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
275         directory to store intermediate files for user-space targets
276
277 @item USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
278         directory to store exported include files which should be installed later
279         on user-space include path
280 @item USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
281         same for user-pace libraries
282 @item USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
283         utilities for testing, which would not probably be installed
284 @item USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
285         binaries, which should go into directory on standard system PATH
286         (/usr/local/bin, /usr/bin or $(prefix)/bin)
287
288 @item KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern
289         directory to store exported include files which should be installed later
290         on kernel-space include path
291 @item KERN_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern
292         same for kernel-pace libraries
293 @item KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules
294         builded modules for Linux kernel or RT-Linux system
295 @end table
296
297 There is more recursive passes through directories to enable
298 mutual dependant libraries and binaries to compile.
299 Next passes are defined
300
301 @table @samp
302 @item default-config
303 generates @file{config.omk-default} or xxx-default (FIXME) configuration file
304 @item check-dir 
305 checks and creates required build directories
306 @item include-pass   
307 copies header files to @code{USER_INCLUDE_DIR} and @code{KERN_INCLUDE_DIR}
308 @item library-pass
309 builds objects in USER_BUILD_DIR/@var{relative path} and creates libraries
310 in USER_LIB_DIR
311 @item binary-pass and utils-pass
312 links respective binaries in USER_@{BIN,UTILS@}_DIR directory. If some
313 object file is missing it compiles it in USER_BUILD_DIR/@var{relative path}
314 @item kernel-lib-pass
315 builds libraries for kernel space targets
316 @item kernel-pass 
317 builds kernel modules
318 @end table
319
320 The amount of passes is relatively high and consumes some time.  But
321 only other way to support all required features is to assemble one big
322 toplevel Makefile, which would contain all components and targets
323 cross-dependencies.
324
325 Drawbacks of designed make system
326 @itemize
327 @item
328 the system is not as fast as we would like
329 @item
330 it lacks Autoconf and configure extensive support for many systems
331 from UNIX to DOS and WINDOWS
332 @item
333 it does not contain support for checking existence of target
334 libraries and functionalities as GNU Autoconf
335 @item
336 it is heavily dependant on GNU MAKE program. But it would not be big
337 problem, because even many commercial applications distribute GNU MAKE
338 with them to be able to work in non-friendly systems
339 @item
340 the key drawback is dependence on recent MAKE version 3.80 and better
341 and even version 3.80 of MAKE has important bug, which has been
342 corrected in newer sources (FIXME)
343 @end itemize
344
345 The last point is critical. I have not noticed it first, because
346 I use Slackware-9.2 and it contains latest released version 
347 of MAKE (version 3.80).
348 The problem appears when I have tried to build bigger libraries.
349 There is bug in version 3.80, which results in misleading
350 error "Virtual memory exhausted". It is known bug with ID 1517
351
352 @smallexample
353 * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
354 @end smallexample
355
356
357 I have optimized some rules to not push memory to the edge,
358 but there could be still issues with 3.80 version.
359
360 I have downloaded latest MAKE CVS sources. The compilation required
361 separate lookup and download for .po files and full Autoheader... cycle.
362 I have put together package similar to release. Only ./configure --prefix=...
363 and make is required. CVS sources contains version 3.81beta1.
364 You can download prepared sources archive from
365   @indicateurl{http://paulandlesley.org/make/make-3.81beta1.tar.bz2}
366 Or you can get our local copy from
367   @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz}
368
369 The archive contains even "make" binary build by me, which should work
370 on other Linux distributions as well.  Older version of MAKE (3.79.x
371 released about year 2000) found on Mandrake and RedHat are not
372 sufficient and do not support eval feature.  I do not expect, that
373 Debian would be more up-to-date or contain fixes to MAKE vm exhausted
374 bug.
375
376 The local CTU archive with our CAN components prepared for inclusion
377 into OCERA SF CVS could be found in my "can" directory
378
379   @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz}
380
381 The code should build for user-space with new make on most of Linux distros
382 when make is updated.
383
384 If you want to test compile for RT-Linux targets, line
385
386 @example
387 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
388 @end example
389
390 in @file{Makefile.rules} has to be activated and updated
391 to point RT-Linux directory containing "rtl.mk".
392 There is only one library ("ulutrtl") and test utility compiled for RT-Linux
393 (@file{can/utils/ulut/ul_rtlchk.c}).
394
395 The next line, if enabled, controls compilation in OCERA project tree
396
397 @example
398 #OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
399 @end example
400
401 The LinCAN driver has been updated to compile out of source directories.
402
403 Please, check, if you could compile CAN package and help us with integration
404 into OCERA SF CVS. Send your comments and objections. 
405
406 The OMK system has been adapted to support actual OCERA configuration process.
407 I am not happy with ocera.mk mix of defines and poor two or three rules,
408 but OMK is able to overcome that.
409
410 The OMK system has integrated rules (default-config) to build default
411 configuration file. The file is named @file{config.omk-default} for
412 the stand-alone compilation.  The name corresponds to OCERA config +
413 "-default" if OCERA_DIR is defined.  This file contains statements
414 from all @code{default_CONFIG} lines in all @file{Makefile.omk}.  The
415 file should be used for building of own @file{config.omk} file, or as
416 list for all options if Kconfig is used.
417
418 @chapter OMK User's Manual
419
420 @section Basic Concepts
421
422 The main concept of OMK is very simple. In the root directory of the
423 projects resides a file called @file{Makefile.rules}. This file contains
424 all compilation rules needed for compilation. There are different
425 @file{Makefile.rules} for different platforms (Unix, RTEMS, system-less,
426 ...). In every subdirectory a @file{Makefile.omk} is stored. This file
427 specifies what should be done in this directory (e.g. compile a program
428 from several source files). Its syntax is very simple -- see the
429 following sections.
430
431 In theory, this could everything, what is needed to compile a project. In
432 reality, you want to be able to start compilation simply by typing
433 @command{make} in some directory. Since make searches by default for a
434 file @file{Makefile}, in every directory, there is small
435 @file{Makefile}, whose only task is to find @file{Makefile.rules} and
436 include it.
437
438 The compilation process itself is comprised of several passes. The pass
439 traverse the whole directory structure@footnote{In future, we are
440 planning some optimization that allows OMK to traverse the directories
441 only once and thus decrease compilation time.} and does some
442 task. Typically, these passes are:
443 @table @dfn
444 @item include-pass
445     This pass takes all include files marked for ``export'' and copies
446     (or links) them to the @file{include} directory (usually under
447     @file{_compiled} directory). Also, during this pass, generated
448     headers are generated according to the current configuration. See
449     @ref{Configuration and Conditional Compilation} for details.
450 @item library-pass
451     During this pass, all include files are in place, so all libraries
452     can be compiled.
453 @item binary-pass
454     Finally, programs can be compiled and linked against libraries
455     created in the previous pass.
456 @end table
457
458 The results of compilation are stored under the @file{_compiled}
459 directory. This directory is structured as a classical Unix filesystem
460 (it contains directories like @file{bin}, @file{lib} and @file{include})
461 and can be directly copied to the target device or to some directory
462 (e.g. @file{/usr/local}).
463
464 Besides @file{_compiled} directory, there in a @file{_build}
465 directory. Under this directory are stored some temporary files and
466 intermediate compilation products (object files, dependency files etc.).
467
468 @section Dependency Tracking
469
470 OMK automatically handles tracking of dependencies of compiled
471 projects. It uses gcc's @option{-M@var{x}} options to do this for
472 object files. This way, whenever you change some header file, OMK
473 recompiles only those files, where the changed header was really
474 included.
475
476 Dependencies are also kept for libraries and binaries. OMK parses linker
477 map files, so a change to some library causes recompilation of all
478 programs using this library.
479
480 @section Compiling Simple Programs
481
482 To tell OMK to compile a program, you need to set some variables in
483 @file{Makefile.omk} (usually) in the directory where program sources are
484 located.
485
486 In the example bellow a program @command{test} will be compiled from
487 source @file{test.c}.
488
489 @example
490 @verbatiminclude ../tests/programs/Makefile.omk
491 @end example
492
493 @noindent The variables are:
494
495 @defvar bin_PROGRAMS
496 Contains a list of names (whitespace separated) of programs to be
497 compiled in this directory.
498 @end defvar
499
500 @defvar @var{program name}_SOURCES
501 For every program name in @code{bin_PROGRAMS}, this variable contains a
502 list of sources that are needed to compile the executable. OMK uses an
503 extension of the filename to determine the compiler to compile this
504 source.
505 @end defvar
506
507 @defvar @var{program name}_LIBS
508 This variable contains a list of libraries the program @var{program
509 name} needs to be linked to.
510 @end defvar
511
512 @defvar LOADLIBES
513 This variable contains a list of libraries all programs in this
514 directory needs to be linked to.
515 @end defvar
516
517 @defvar INCLUDES
518 Directives passed to the C or C++ compiler with additional directories
519 to be searched for header files. This variable applies to all
520 compilations invoked in the current directory.
521 @example
522 INCLUDES = -Imy_include_dir
523 @end example
524 @end defvar
525
526 @defvar DEFS
527 Directives passed to the C or C++ compiler with preprocessor macro
528 definitions. This variable applies to all compilations invoked in the
529 current directory.
530 @example
531 DEFS = -DDEBUG=1
532 @end example
533 @end defvar
534
535
536
537 @c FIXME: INCLUDES variable should not be set by rtlinux rules.
538
539
540 @section Libraries
541
542 LN_INCLUDES
543
544 @section Multiple Directories
545
546 ALL_OMK_SUBDIRS
547 SUBDIRS
548
549 @node Configuration and Conditional Compilation
550 @section Configuration and Conditional Compilation
551
552 @section Running OMK under Windows OS
553
554 @section Troubleshooting
555
556 Renaming of some file => dependency problems.
557
558 Manual compilation ... V=1
559
560
561
562 @chapter OMK Reference
563
564 @chapter OMK Development
565
566
567
568 @node Variable Index
569 @unnumbered Variable Index
570
571 @printindex vr
572
573 @node Concept Index
574 @unnumbered Concept Index
575
576 @printindex cp
577
578 @bye