1 | /* $Id: VBox-MakefileGuidelines.cpp 75386 2018-11-11 23:30:51Z 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 | * - Line continuation slashes shall never ever be aligned vertically (that
|
---|
130 | * always goes crooked sooner or later), but have exactly one space
|
---|
131 | * before them.
|
---|
132 | *
|
---|
133 | * - The last element of an broken list shall not have a slash-newline,
|
---|
134 | * otherwise we risk getting the next variable into the list.
|
---|
135 | *
|
---|
136 | * - When if'ed blocks come into play, we will only indent the conditional
|
---|
137 | * makefile directives (if, ifeq, ifneq, if1of, ifn1of, ifdef, ifndef,
|
---|
138 | * else, endif, ++), one space for each level. (Note! We used to indent
|
---|
139 | * non-directives, which made emacs upset as we'd have both tabs and
|
---|
140 | * spaces on as indentation on the same line. There are a lot of cases
|
---|
141 | * of this still around.)
|
---|
142 | *
|
---|
143 | * - \$(NO_SUCH_VARIABLE) should be when you need to put nothing somewhere,
|
---|
144 | * for instance to prevent inherting an attribute.
|
---|
145 | *
|
---|
146 | * - Always put the defines in the DEFS properties, never use the FLAGS
|
---|
147 | * properties for this. Doing so may screw up depenencies and object
|
---|
148 | * caches.
|
---|
149 | *
|
---|
150 | * - Mark each section and target of the file with a 3+ lines comment
|
---|
151 | * block.
|
---|
152 | *
|
---|
153 | * - Document variables that are not immediately obvious using double hash
|
---|
154 | * comments, doxygen style.
|
---|
155 | *
|
---|
156 | * - Each an every Makefile.kmk shall have a file header with Id, file
|
---|
157 | * description and copyright/license exactly like in the examples. (The
|
---|
158 | * SCM tool will complain if you don't.)
|
---|
159 | *
|
---|
160 | * - Multiple blank lines in a makefile is very seldom there without a
|
---|
161 | * reason and shall be preserved.
|
---|
162 | *
|
---|
163 | * - Inserting blank lines between target properties is all right if the
|
---|
164 | * target definition is long and/or crooked.
|
---|
165 | *
|
---|
166 | * - if1of and ifn1of shall always have a space after the comma, while ifeq
|
---|
167 | * and ifneq shall not. That way they are easier to tell apart.
|
---|
168 | *
|
---|
169 | * - Do a svn diff before committing makefile changes.
|
---|
170 | *
|
---|
171 | *
|
---|
172 | * @section sec_vbox_makefile_guidelines_reminders Helpful reminders
|
---|
173 | *
|
---|
174 | * - Do not be afraid to ask for help on IRC or in the defect you're
|
---|
175 | * working on. There are usually somebody around that know how to best do
|
---|
176 | * something.
|
---|
177 | *
|
---|
178 | * - Watch out for "Heads Up!" bugtracker messages concerning the build
|
---|
179 | * system.
|
---|
180 | *
|
---|
181 | * - To remove bits from a template you're using you have to create a new
|
---|
182 | * template that extends the existing one and creatively use
|
---|
183 | * \$(filter-out) or \$(patsubst).
|
---|
184 | *
|
---|
185 | * - You can build sub-trees.
|
---|
186 | *
|
---|
187 | * - You don't have to cd into sub-trees: kmk -C src/recompiler
|
---|
188 | *
|
---|
189 | * - You can build individual targets: kmk VBoxRT
|
---|
190 | *
|
---|
191 | * - Even install targets: kmk nobin
|
---|
192 | *
|
---|
193 | * - You can compile individual source files: kmk ConsoleImpl.o
|
---|
194 | *
|
---|
195 | * - You can tell kmk to continue on failure: kmk -k
|
---|
196 | *
|
---|
197 | * - You can tell kmk to run at low priority: kmk --nice
|
---|
198 | *
|
---|
199 | * - The --pretty-command-printing option is useful for seeing exactly
|
---|
200 | * what's passed to the tools.
|
---|
201 | *
|
---|
202 | * - You can invoke recipes in the root makefile more efficiently via the
|
---|
203 | * Maintenance.kmk file: kmk -f Maintenance.kmk incs
|
---|
204 | *
|
---|
205 | */
|
---|
206 |
|
---|