blob: a47bffbae1595bdb8d9fc111ddf102f868e217e5 [file] [log] [blame]
Jiri Olsac819e2c2014-12-29 13:51:45 +01001Build Framework
2===============
3
4The perf build framework was adopted from the kernel build system, hence the
5idea and the way how objects are built is the same.
6
7Basically the user provides set of 'Build' files that list objects and
8directories to nest for specific target to be build.
9
10Unlike the kernel we don't have a single build object 'obj-y' list that where
11we setup source objects, but we support more. This allows one 'Build' file to
12carry a sources list for multiple build objects.
13
Jiri Olsaab6201d2015-09-23 12:33:56 +020014
15Build framework makefiles
16-------------------------
Jiri Olsac819e2c2014-12-29 13:51:45 +010017
18The build framework consists of 2 Makefiles:
19
20 Build.include
21 Makefile.build
22
23While the 'Build.include' file contains just some generic definitions, the
24'Makefile.build' file is the makefile used from the outside. It's
25interface/usage is following:
26
Jiri Olsaab6201d2015-09-23 12:33:56 +020027 $ make -f tools/build/Makefile.build srctree=$(KSRC) dir=$(DIR) obj=$(OBJECT)
Jiri Olsac819e2c2014-12-29 13:51:45 +010028
29where:
30
31 KSRC - is the path to kernel sources
32 DIR - is the path to the project to be built
33 OBJECT - is the name of the build object
34
35When succefully finished the $(DIR) directory contains the final object file
36called $(OBJECT)-in.o:
37
38 $ ls $(DIR)/$(OBJECT)-in.o
39
40which includes all compiled sources described in 'Build' makefiles.
41
Jiri Olsaab6201d2015-09-23 12:33:56 +020042
43Build makefiles
44---------------
Jiri Olsac819e2c2014-12-29 13:51:45 +010045
46The user supplies 'Build' makefiles that contains a objects list, and connects
47the build to nested directories.
48
49Assume we have the following project structure:
50
51 ex/a.c
52 /b.c
53 /c.c
54 /d.c
55 /arch/e.c
56 /arch/f.c
57
58Out of which you build the 'ex' binary ' and the 'libex.a' library:
59
60 'ex' - consists of 'a.o', 'b.o' and libex.a
61 'libex.a' - consists of 'c.o', 'd.o', 'e.o' and 'f.o'
62
63The build framework does not create the 'ex' and 'libex.a' binaries for you, it
64only prepares proper objects to be compiled and grouped together.
65
66To follow the above example, the user provides following 'Build' files:
67
68 ex/Build:
69 ex-y += a.o
70 ex-y += b.o
Jiri Olsa0bdede82015-08-26 15:01:03 +020071 ex-y += b.o # duplicates in the lists are allowed
Jiri Olsac819e2c2014-12-29 13:51:45 +010072
73 libex-y += c.o
74 libex-y += d.o
75 libex-y += arch/
76
77 ex/arch/Build:
78 libex-y += e.o
79 libex-y += f.o
80
81and runs:
82
83 $ make -f tools/build/Makefile.build dir=. obj=ex
84 $ make -f tools/build/Makefile.build dir=. obj=libex
85
86which creates the following objects:
87
88 ex/ex-in.o
89 ex/libex-in.o
90
91that contain request objects names in Build files.
92
93It's only a matter of 2 single commands to create the final binaries:
94
95 $ ar rcs libex.a libex-in.o
96 $ gcc -o ex ex-in.o libex.a
97
98You can check the 'ex' example in 'tools/build/tests/ex' for more details.
99
Jiri Olsaab6201d2015-09-23 12:33:56 +0200100
101Makefile.include
102----------------
103
104The tools/build/Makefile.include makefile could be included
105via user makefiles to get usefull definitions.
106
107It defines following interface:
108
109 - build macro definition:
110 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
111
112 to make it easier to invoke build like:
113 make $(build)=ex
114
115
Jiri Olsa7c422f52015-09-23 12:34:02 +0200116Fixdep
117------
118It is necessary to build the fixdep helper before invoking the build.
119The Makefile.include file adds the fixdep target, that could be
120invoked by the user.
121
122
Jiri Olsaab6201d2015-09-23 12:33:56 +0200123Rules
124-----
Jiri Olsac819e2c2014-12-29 13:51:45 +0100125
126The build framework provides standard compilation rules to handle .S and .c
127compilation.
128
129It's possible to include special rule if needed (like we do for flex or bison
130code generation).
131
Jiri Olsaab6201d2015-09-23 12:33:56 +0200132
133CFLAGS
134------
Jiri Olsac819e2c2014-12-29 13:51:45 +0100135
136It's possible to alter the standard object C flags in the following way:
137
138 CFLAGS_perf.o += '...' - alters CFLAGS for perf.o object
139 CFLAGS_gtk += '...' - alters CFLAGS for gtk build object
140
141This C flags changes has the scope of the Build makefile they are defined in.
142
143
Jiri Olsaab6201d2015-09-23 12:33:56 +0200144Dependencies
145------------
Jiri Olsac819e2c2014-12-29 13:51:45 +0100146
147For each built object file 'a.o' the '.a.cmd' is created and holds:
148
149 - Command line used to built that object
150 (for each object)
151
152 - Dependency rules generated by 'gcc -Wp,-MD,...'
153 (for compiled object)
154
155All existing '.cmd' files are included in the Build process to follow properly
156the dependencies and trigger a rebuild when necessary.
157
158
Jiri Olsaab6201d2015-09-23 12:33:56 +0200159Single rules
160------------
Jiri Olsac819e2c2014-12-29 13:51:45 +0100161
162It's possible to build single object file by choice, like:
163
164 $ make util/map.o # objects
165 $ make util/map.i # preprocessor
166 $ make util/map.s # assembly