1 | /* $Id: VBox-MakefileGuidelines.cpp 75168 2018-10-29 21:09:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox - Makefile Guidelines.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /** @page pg_vbox_makefile_guidelines VBox Makefile Guidelines
|
---|
19 | *
|
---|
20 | * These guidelines apply to all the Makefile.kmk files in the tree.
|
---|
21 | * No exceptions.
|
---|
22 | *
|
---|
23 | * All these makefiles are ultimately the responsiblity of bird. Since there
|
---|
24 | * are currently more than three hundred files and the number is growing, they
|
---|
25 | * have to be very kept uniform or it will become very difficult to maintain
|
---|
26 | * them and impossible do bulk refactoring. Thus these guidelines have no bits
|
---|
27 | * that are optional unlike the coding guidelines, and should be thought of as
|
---|
28 | * rules rather than guidelines.
|
---|
29 | *
|
---|
30 | * Note! The guidelines do not apply to the non-kBuild makefiles found in the
|
---|
31 | * source tree, like the ones shipped in the SDK and the ones for the
|
---|
32 | * linux kernel modules.
|
---|
33 | *
|
---|
34 | *
|
---|
35 | * @section sec_vbox_makefile_guidelines_kbuild kBuild
|
---|
36 | *
|
---|
37 | * kBuild is way older than VirtualBox, at least as a concept, but the
|
---|
38 | * VirtualBox project was a push to get something done about it again. It's
|
---|
39 | * maintained by bird in his spare time because: "We don't make buildsystems, we
|
---|
40 | * make virtual machines". So, kBuild makes progress when there is spare time
|
---|
41 | * or when there is an urgent need for something.
|
---|
42 | *
|
---|
43 | * The kBuild docs are in the process of being written. The current items and
|
---|
44 | * their status per 2018-10-29:
|
---|
45 | * - kmk Quick Reference [completed]:
|
---|
46 | * http://svn.netlabs.org/kbuild/wiki/kmk%20Quick%20Reference
|
---|
47 | * - kBuild Quick Reference [just started]:
|
---|
48 | * http://svn.netlabs.org/kbuild/wiki/kBuild%20Quick%20Reference
|
---|
49 | *
|
---|
50 | * Local copies of the docs can be found in kBuild/docs, just keep in mind that
|
---|
51 | * they might be slightly behind the online version.
|
---|
52 | *
|
---|
53 | *
|
---|
54 | * @section sec_vbox_makefile_guidelines_example Example Makefiles
|
---|
55 | *
|
---|
56 | * Let me point to some good sample makefiles:
|
---|
57 | * - src/VBox/Additions/common/VBoxService/Makefile.kmk
|
---|
58 | * - src/VBox/Debugger/Makefile.kmk
|
---|
59 | * - src/VBox/Disassembler/Makefile.kmk
|
---|
60 | *
|
---|
61 | * And some bad ones:
|
---|
62 | * - src/lib/xpcom18a4/Makefile.kmk
|
---|
63 | * - src/recompiler/Makefile.kmk
|
---|
64 | * - src/VBox/Devices/Makefile.kmk
|
---|
65 | * - src/VBox/Main/Makefile.kmk
|
---|
66 | * - src/VBox/Runtime/Makefile.kmk
|
---|
67 | *
|
---|
68 | *
|
---|
69 | * @section sec_vbox_makefile_guidelines Guidelines
|
---|
70 | *
|
---|
71 | * First one really important fact:
|
---|
72 | *
|
---|
73 | * Everything is global because all makefiles
|
---|
74 | * are virtually one single makefile.
|
---|
75 | *
|
---|
76 | * The rules:
|
---|
77 | *
|
---|
78 | * - Using bits defined by a sub-makefile is fine, using anything defined
|
---|
79 | * by a parent, sibling, uncle, cousine, or remoter relatives is not
|
---|
80 | * Okay. It may break sub-tree building which is not acceptable.
|
---|
81 | *
|
---|
82 | * - Template names starts with VBox and are camel cased, no
|
---|
83 | * underscores or other separators. (Note this used to be all upper
|
---|
84 | * case, fixing this incomplete.)
|
---|
85 | *
|
---|
86 | * - Makefile variables shall be prefixed with VBOX or VB to avoid clashes
|
---|
87 | * with environment and kBuild variables.
|
---|
88 | *
|
---|
89 | * - Makefile variables are all upper cased and uses underscores to
|
---|
90 | * separate the words.
|
---|
91 | *
|
---|
92 | * - All variables are global. Make sure they are globally unique, but try
|
---|
93 | * not make them incredible long.
|
---|
94 | *
|
---|
95 | * - Makefile variables goes after the inclusion of the header and
|
---|
96 | * usually after including sub-makefiles.
|
---|
97 | *
|
---|
98 | * - Variables that are used by more than one makefile usually ends up
|
---|
99 | * in the monster file, Config.kmk. However, see if there are any
|
---|
100 | * sub-tree specific Config.kmk files that could do the job first.
|
---|
101 | *
|
---|
102 | * - Targets are lower or camel cased and as a rule the same as the
|
---|
103 | * resulting binary.
|
---|
104 | *
|
---|
105 | * - Install targets frequently have a -inst in their name, and a name that
|
---|
106 | * gives some idea what they install
|
---|
107 | *
|
---|
108 | * - Always use templates (mytarget_TEMPLATE = VBoxSomething).
|
---|
109 | *
|
---|
110 | * - Comment each target with a 3+ line block as seen in
|
---|
111 | * src/VBox/Debugger/Makefile.kmk.
|
---|
112 | *
|
---|
113 | * - No space between the comment block and the target definition.
|
---|
114 | *
|
---|
115 | * - Try fit all the custom recipes after the target they apply to.
|
---|
116 | *
|
---|
117 | * - Custom recipes that apply to more than one target should be placed at
|
---|
118 | * the bottom of the makefile, before the footer inclusion when possible.
|
---|
119 | *
|
---|
120 | * - Do NOT use custom recipes to install stuff, use install targets.
|
---|
121 | * Generate files to inst-target_0_OUTDIR. (Yes, there are a lot places
|
---|
122 | * where we don't do this yet.)
|
---|
123 | *
|
---|
124 | * - Always break SOURCES, LIBS, long target list and other lists the
|
---|
125 | * manner Debugger_SOURCES is broken into multiple lines in
|
---|
126 | * src/VBox/Debugger/Makefile.kmk. I.e. exactly one tab, the file name /
|
---|
127 | * list item, another space, the slash and then the newline.
|
---|
128 | *
|
---|
129 | * - The last element of an broken list should not have a slash-newline,
|
---|
130 | * otherwise we risk getting the next variable into the list.
|
---|
131 | *
|
---|
132 | * - When if'ed blocks come into play, we will only indent the conditional
|
---|
133 | * makefile directives (if, ifeq, ifneq, if1of, ifn1of, ifdef, ifndef,
|
---|
134 | * else, endif, ++), one space for each level. (Note! We used to indent
|
---|
135 | * non-directives, which made emacs upset as we'd have both tabs and
|
---|
136 | * spaces on as indentation on the same line. There are a lot of cases
|
---|
137 | * of this still around.)
|
---|
138 | *
|
---|
139 | * - \$(NO_SUCH_VARIABLE) should be when you need to put nothing somewhere,
|
---|
140 | * for instance to prevent inherting an attribute.
|
---|
141 | *
|
---|
142 | * - Always put the defines in the DEFS properties, never use the FLAGS
|
---|
143 | * properties for this. Doing so may screw up depenencies and object
|
---|
144 | * caches.
|
---|
145 | *
|
---|
146 | * - Mark each section and target of the file with a 3+ lines comment
|
---|
147 | * block.
|
---|
148 | *
|
---|
149 | * - Document variables that are not immediately obvious using double hash
|
---|
150 | * comments, doxygen style.
|
---|
151 | *
|
---|
152 | * - Each an every Makefile.kmk shall have a file header with Id, file
|
---|
153 | * description and copyright/license exactly like in the examples. (The
|
---|
154 | * SCM tool will complain if you don't.)
|
---|
155 | *
|
---|
156 | * - Multiple blank lines in a makefile is very seldom there without a
|
---|
157 | * reason and shall be preserved.
|
---|
158 | *
|
---|
159 | * - Inserting blank lines between target properties is all right if the
|
---|
160 | * target definition is long and/or crooked.
|
---|
161 | *
|
---|
162 | * - if1of and ifn1of shall always have a space after the comma, while ifeq
|
---|
163 | * and ifneq shall not. That way they are easier to tell apart.
|
---|
164 | *
|
---|
165 | * - Do a svn diff before committing makefile changes.
|
---|
166 | *
|
---|
167 | *
|
---|
168 | * @section sec_vbox_makefile_guidelines_reminders Helpful reminders
|
---|
169 | *
|
---|
170 | * - Do not be afraid to ask for help on IRC or in the defect you're
|
---|
171 | * working on. There are usually somebody around that know how to best do
|
---|
172 | * something.
|
---|
173 | *
|
---|
174 | * - Watch out for "Heads Up!" bugtracker messages concerning the build
|
---|
175 | * system.
|
---|
176 | *
|
---|
177 | * - To remove bits from a template you're using you have to create a new
|
---|
178 | * template that extends the existing one and creatively use
|
---|
179 | * \$(filter-out) or \$(patsubst).
|
---|
180 | *
|
---|
181 | * - You can build sub-trees.
|
---|
182 | *
|
---|
183 | * - You don't have to cd into sub-trees: kmk -C src/recompiler
|
---|
184 | *
|
---|
185 | * - You can build individual targets: kmk VBoxRT
|
---|
186 | *
|
---|
187 | * - Even install targets: kmk nobin
|
---|
188 | *
|
---|
189 | * - You can compile individual source files: kmk ConsoleImpl.o
|
---|
190 | *
|
---|
191 | * - You can tell kmk to continue on failure: kmk -k
|
---|
192 | *
|
---|
193 | * - You can tell kmk to run at low priority: kmk --nice
|
---|
194 | *
|
---|
195 | * - The --pretty-command-printing option is useful for seeing exactly
|
---|
196 | * what's passed to the tools.
|
---|
197 | *
|
---|
198 | * - You can invoke recipes in the root makefile more efficiently via the
|
---|
199 | * Maintenance.kmk file: kmk -f Maintenance.kmk incs
|
---|
200 | *
|
---|
201 | */
|
---|
202 |
|
---|