1 \input texinfo @c -*-texinfo-*-
4 @settitle Ocera Make System
8 Manual for Ocera Make System (OMK)
10 Copyright @copyright{} 2007 Michal Sojka, Pavel Pisa
14 @title Ocera Make System Manual
16 @vskip 0pt plus 1filll
24 @top Ocera Make System
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
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
49 You can use OMK on all platforms where you can run GNU Make including
50 Cygwin and MinGW. MS DOS was not tested.
56 @c Easy to use for beginners.
58 @c Automatic handling of dependencies.
60 @c Supported host platforms: all Un*x operating system including Linux,
61 @c Cygwin, MS DOS and maybe others.
64 @section Why to Use OMK?
68 If you get some sources, which are distributed with OMK, usually the
69 following commands are sufficient to compile the whole project.
78 To use OMK in your own project, follow these steps:
82 Take appropriate @file{Makefile.rules}, put it together with leaf
83 @file{Makefile} to the root directory of your project.
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.
89 Run @command{make omkize} in the root directory.
92 Your project is now ready to compile.
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.
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.
109 @chapter Original README
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.
119 There is list of features which we want to solve with our make system:
122 Central @file{Makefile.rules} for most of components of a bigger project.
124 FIXME (our CAN framework includes more libraries common with our other
125 projects, we need to separate some utility libraries etc.)
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).
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).
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.
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).
144 Compile should be able to do all above work without need to install
145 any files before successful finish of build.
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.
150 The build system should allow to call make for particular source
151 subdirectory. Time of recursive make through all subdirectories is
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
158 It would be good, if there is a possibility to call make from
159 read-only media sources.
161 Make system should store results of build in some separate directory
162 structure to simple install and testing.
164 Makefiles in sources directories should be simple.
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:
174 It would require deep revision of all OCERA CVS contents and agreement
175 on this would be problematic
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.
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.
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.
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
200 Makefile.omk user defined variables
203 list of subdirectories intended for make from actual directory
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
217 list of the kernel-space header files
218 @item rtlinux_HEADERS
219 list of the RT-Linux kernel-space header files
221 list of the require binary programs
223 list of the development utility programs
225 list of the kernel side modules/applications
226 @item rtlinux_MODULES
227 list of RT-Linux the kernel side modules/applications
229 list of specific target sources
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
237 list of default config assignments CONFIG_XXX=y/n ...
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
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}
256 There are next predefined directory name components, which can be
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
269 Next directories are used:
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
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)
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
297 There is more recursive passes through directories to enable
298 mutual dependant libraries and binaries to compile.
299 Next passes are defined
303 generates @file{config.omk-default} or xxx-default (FIXME) configuration file
305 checks and creates required build directories
307 copies header files to @code{USER_INCLUDE_DIR} and @code{KERN_INCLUDE_DIR}
309 builds objects in USER_BUILD_DIR/@var{relative path} and creates libraries
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
317 builds kernel modules
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
325 Drawbacks of designed make system
328 the system is not as fast as we would like
330 it lacks Autoconf and configure extensive support for many systems
331 from UNIX to DOS and WINDOWS
333 it does not contain support for checking existence of target
334 libraries and functionalities as GNU Autoconf
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
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)
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
353 * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
357 I have optimized some rules to not push memory to the edge,
358 but there could be still issues with 3.80 version.
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}
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
376 The local CTU archive with our CAN components prepared for inclusion
377 into OCERA SF CVS could be found in my "can" directory
379 @indicateurl{http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz}
381 The code should build for user-space with new make on most of Linux distros
382 when make is updated.
384 If you want to test compile for RT-Linux targets, line
387 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
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}).
395 The next line, if enabled, controls compilation in OCERA project tree
398 #OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
401 The LinCAN driver has been updated to compile out of source directories.
403 Please, check, if you could compile CAN package and help us with integration
404 into OCERA SF CVS. Send your comments and objections.
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.
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.
418 @chapter OMK User's Manual
420 @section Basic Concepts
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
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
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:
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.
451 During this pass, all include files are in place, so all libraries
454 Finally, programs can be compiled and linked against libraries
455 created in the previous pass.
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}).
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.).
468 @section Dependency Tracking
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
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.
480 @section Compiling Simple Programs
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
486 In the example bellow a program @command{test} will be compiled from
487 source @file{test.c}.
490 @verbatiminclude ../tests/programs/Makefile.omk
493 @noindent The variables are:
496 Contains a list of names (whitespace separated) of programs to be
497 compiled in this directory.
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
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.
513 This variable contains a list of libraries all programs in this
514 directory needs to be linked to.
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.
522 INCLUDES = -Imy_include_dir
527 Directives passed to the C or C++ compiler with preprocessor macro
528 definitions. This variable applies to all compilations invoked in the
537 @c FIXME: INCLUDES variable should not be set by rtlinux rules.
544 @section Multiple Directories
549 @node Configuration and Conditional Compilation
550 @section Configuration and Conditional Compilation
552 @section Running OMK under Windows OS
554 @section Troubleshooting
556 Renaming of some file => dependency problems.
558 Manual compilation ... V=1
562 @chapter OMK Reference
564 @chapter OMK Development
569 @unnumbered Variable Index
574 @unnumbered Concept Index