ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync/* $Id$ */
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync/** @file
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * VBox - Makefile Guidelines.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync */
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2009-2010 Oracle Corporation
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * available from http://www.virtualbox.org. This file is free software;
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * you can redistribute it and/or modify it under the terms of the GNU
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * General Public License (GPL) as published by the Free Software
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync */
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync/** @page pg_vbox_makefile_guidelines VBox Makefile Guidelines
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * These guidelines apply to all the Makefile.kmk files in the tree.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * No exceptions.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * All these makefiles are ultimately the responsiblity of bird. Since there are
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * currently more than two hundred files and the number is growing, they have to
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * be very kept uniform or it will become very difficult to maintain them and
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * impossible do bulk refactoring. Thus these guidelines have no bits that are
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * optional unlike the coding guidelines, and should be thought of as rules
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * rather than guidelines.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Note! The guidelines do not apply to the other makefiles found in the source
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * tree, like the ones shipped in the SDK and the ones for the linux kernel
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * modules.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * @section sec_vbox_makefile_guidelines_kbuild kBuild
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * kBuild is way older than VirtualBox, at least as a concept, but the
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * VirtualBox project was a push to get something done about it again. It's
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * maintained by bird in his spare time because: "We don't make buildsystems, we
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * make virtual machines". So, kBuild makes progress when there is spare time or
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * when there is an urgent need for something.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * The kBuild docs are in the process of being written. The current items and
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * their status per 2009-04-19:
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - kmk Quick Reference [completed]:
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * http://svn.netlabs.org/kbuild/wiki/kmk%20Quick%20Reference
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - kBuild Quick Reference [just started]:
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * http://svn.netlabs.org/kbuild/wiki/kBuild%20Quick%20Reference
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Local copies of the docs can be found in kBuild/docs, just keep in mind that
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * they might be slightly behind the online version.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * @section sec_vbox_makefile_guidelines_example Example Makefiles
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Let me point to some good sample makefiles:
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/VBox/Additions/common/VBoxService/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/VBox/Debugger/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/VBox/Disassembler/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * And some bad ones:
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/lib/xpcom18a4/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/recompiler/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/VBox/Devices/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/VBox/Main/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - src/VBox/Runtime/Makefile.kmk
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * @section sec_vbox_makefile_guidelines Guidelines
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * First one really important fact:
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Everything is global because all makefiles
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * are virtually one single makefile.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * The rules:
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Using bits defined by a sub-makefile is fine, using anything defined
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * by a parent, sibling, uncle, cousine, or remoter relatives is not
5c571d69a0355bedb9a401ce4de992a2b0ef3515vboxsync * Okay. It may break sub-tree building which is not acceptable.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Template names starts with VBOX and are all upper cased, no
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * underscores or other separators. (TODO: Change this to camel case.)
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Makefile variables shall be prefixed with VBOX or VB to avoid clashes
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * with environment and kBuild variables.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Makefile variables are all upper cased and uses underscores to
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * separate the words.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - All variables are global. Make sure they are globally unique, but try
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * not make them incredible long.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Makefile variables goes after the inclusion of the header and
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * usually after including sub-makefiles.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Variables that are used by more than one makefile usually belongs
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * in the monster file, Config.kmk.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Targets are lower or camel cased and as a rule the same as the
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * resulting binary.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Install targets frequently have a -inst in their name, and a name that
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * gives some idea what they install
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Always use templates (mytarget_TEMPLATE = VBOXSOMETHING).
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Comment each target with a 3+ line block as seen in
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * src/VBox/Debugger/Makefile.kmk.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - No space between the comment block and the target definition.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Try fit all the custom recipes after the target they apply to.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Custom recipes that apply to more than one target should be placed at
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * the bottom of the makefile, before the footer inclusion when possible.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Do NOT use custom recipes to install stuff, use install targets.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Generate files to inst-target_0_OUTDIR. (Yes, there are a lot places
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * where we don't do this yet.)
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Always break SOURCES, LIBS, long target list and other lists the
2d8f7775ea7361ee20e62a6463e996d9234c7029vboxsync * manner Debugger_SOURCES is broken into multiple lines in
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * src/VBox/Debugger/Makefile.kmk. I.e. exactly one tab, the file name /
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * list item, another space, the slash and then the newline.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - The last element of an broken list should not have a slash-newline,
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * otherwise we risk getting the next variable into the list.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Indentation of if'ed blocks is done in 1 space increments, this also
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * applies to broken lists. It does not apply to the commands in a
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * recipes of course, because that would make kmk choke. (Yes, there are
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * plenty examples of doing this differently, but these will be weeded
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * out over time.)
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - \$(NO_SUCH_VARIABLE) should be when you need to put nothing somewhere,
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * for instance to prevent inherting an attribute.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Always put the defines in the DEFS properties, never use the FLAGS
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * properties for this. Doing so may screw up depenencies and object
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * caches.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Mark each section and target of the file with a 3+ lines comment
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * block.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Document variables that are not obvious using double hash comments.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Each an every Makefile.kmk shall have a file header with Id, file
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * description and copyright/license exactly like in the examples.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Multiple blank lines in a makefile is very seldom there without a
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * reason and shall be preserved.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Inserting blank lines between target properties is all right if the
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * target definition is long and/or crooked.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
689e8c44f580478449d47bd48c9af52e82a028aevboxsync * - if1of and ifn1of shall always have a space after the comma, while ifeq
689e8c44f580478449d47bd48c9af52e82a028aevboxsync * and ifneq shall not. That way they are easier to tell apart.
689e8c44f580478449d47bd48c9af52e82a028aevboxsync *
689e8c44f580478449d47bd48c9af52e82a028aevboxsync * - Do a svn diff before committing makefile changes.
689e8c44f580478449d47bd48c9af52e82a028aevboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * @section sec_vbox_makefile_guidelines_reminders Helpful reminders
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Do not be afraid to ask for help on IRC or in the defect you're
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * working on. There are usually somebody around that know how to best do
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * something.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Watch out for "Heads Up!" bugtracker messages concerning the build
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * system.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - To remove bits from a template you're using you have to create a new
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * template that extends the existing one and creatively use
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * \$(filter-out) or \$(patsubst).
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - You can build sub-trees.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - You don't have to cd into sub-trees: kmk -C src/recompiler
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - You can build individual targets: kmk VBoxRT
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - Even install targets: kmk nobin
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * - You can compile individual source files: kmk ConsoleImpl.o
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync *
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync */
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync