xref: /OK3568_Linux_fs/kernel/tools/build/Documentation/Build.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunBuild Framework
2*4882a593Smuzhiyun===============
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunThe perf build framework was adopted from the kernel build system, hence the
5*4882a593Smuzhiyunidea and the way how objects are built is the same.
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunBasically the user provides set of 'Build' files that list objects and
8*4882a593Smuzhiyundirectories to nest for specific target to be build.
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunUnlike the kernel we don't have a single build object 'obj-y' list that where
11*4882a593Smuzhiyunwe setup source objects, but we support more. This allows one 'Build' file to
12*4882a593Smuzhiyuncarry a sources list for multiple build objects.
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunBuild framework makefiles
16*4882a593Smuzhiyun-------------------------
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunThe build framework consists of 2 Makefiles:
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun  Build.include
21*4882a593Smuzhiyun  Makefile.build
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunWhile the 'Build.include' file contains just some generic definitions, the
24*4882a593Smuzhiyun'Makefile.build' file is the makefile used from the outside. It's
25*4882a593Smuzhiyuninterface/usage is following:
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun  $ make -f tools/build/Makefile.build srctree=$(KSRC) dir=$(DIR) obj=$(OBJECT)
28*4882a593Smuzhiyun
29*4882a593Smuzhiyunwhere:
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun  KSRC   - is the path to kernel sources
32*4882a593Smuzhiyun  DIR    - is the path to the project to be built
33*4882a593Smuzhiyun  OBJECT - is the name of the build object
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunWhen succefully finished the $(DIR) directory contains the final object file
36*4882a593Smuzhiyuncalled $(OBJECT)-in.o:
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun  $ ls $(DIR)/$(OBJECT)-in.o
39*4882a593Smuzhiyun
40*4882a593Smuzhiyunwhich includes all compiled sources described in 'Build' makefiles.
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunBuild makefiles
44*4882a593Smuzhiyun---------------
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunThe user supplies 'Build' makefiles that contains a objects list, and connects
47*4882a593Smuzhiyunthe build to nested directories.
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunAssume we have the following project structure:
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun  ex/a.c
52*4882a593Smuzhiyun    /b.c
53*4882a593Smuzhiyun    /c.c
54*4882a593Smuzhiyun    /d.c
55*4882a593Smuzhiyun    /arch/e.c
56*4882a593Smuzhiyun    /arch/f.c
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunOut of which you build the 'ex' binary ' and the 'libex.a' library:
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun  'ex'      - consists of 'a.o', 'b.o' and libex.a
61*4882a593Smuzhiyun  'libex.a' - consists of 'c.o', 'd.o', 'e.o' and 'f.o'
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunThe build framework does not create the 'ex' and 'libex.a' binaries for you, it
64*4882a593Smuzhiyunonly prepares proper objects to be compiled and grouped together.
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunTo follow the above example, the user provides following 'Build' files:
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun  ex/Build:
69*4882a593Smuzhiyun    ex-y += a.o
70*4882a593Smuzhiyun    ex-y += b.o
71*4882a593Smuzhiyun    ex-y += b.o # duplicates in the lists are allowed
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun    libex-y += c.o
74*4882a593Smuzhiyun    libex-y += d.o
75*4882a593Smuzhiyun    libex-y += arch/
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun  ex/arch/Build:
78*4882a593Smuzhiyun    libex-y += e.o
79*4882a593Smuzhiyun    libex-y += f.o
80*4882a593Smuzhiyun
81*4882a593Smuzhiyunand runs:
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun  $ make -f tools/build/Makefile.build dir=. obj=ex
84*4882a593Smuzhiyun  $ make -f tools/build/Makefile.build dir=. obj=libex
85*4882a593Smuzhiyun
86*4882a593Smuzhiyunwhich creates the following objects:
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun  ex/ex-in.o
89*4882a593Smuzhiyun  ex/libex-in.o
90*4882a593Smuzhiyun
91*4882a593Smuzhiyunthat contain request objects names in Build files.
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunIt's only a matter of 2 single commands to create the final binaries:
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun  $ ar  rcs libex.a libex-in.o
96*4882a593Smuzhiyun  $ gcc -o ex ex-in.o libex.a
97*4882a593Smuzhiyun
98*4882a593SmuzhiyunYou can check the 'ex' example in 'tools/build/tests/ex' for more details.
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun
101*4882a593SmuzhiyunMakefile.include
102*4882a593Smuzhiyun----------------
103*4882a593Smuzhiyun
104*4882a593SmuzhiyunThe tools/build/Makefile.include makefile could be included
105*4882a593Smuzhiyunvia user makefiles to get usefull definitions.
106*4882a593Smuzhiyun
107*4882a593SmuzhiyunIt defines following interface:
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun  - build macro definition:
110*4882a593Smuzhiyun      build := -f $(srctree)/tools/build/Makefile.build dir=. obj
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun    to make it easier to invoke build like:
113*4882a593Smuzhiyun      make $(build)=ex
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun
116*4882a593SmuzhiyunFixdep
117*4882a593Smuzhiyun------
118*4882a593SmuzhiyunIt is necessary to build the fixdep helper before invoking the build.
119*4882a593SmuzhiyunThe Makefile.include file adds the fixdep target, that could be
120*4882a593Smuzhiyuninvoked by the user.
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun
123*4882a593SmuzhiyunRules
124*4882a593Smuzhiyun-----
125*4882a593Smuzhiyun
126*4882a593SmuzhiyunThe build framework provides standard compilation rules to handle .S and .c
127*4882a593Smuzhiyuncompilation.
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunIt's possible to include special rule if needed (like we do for flex or bison
130*4882a593Smuzhiyuncode generation).
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun
133*4882a593SmuzhiyunCFLAGS
134*4882a593Smuzhiyun------
135*4882a593Smuzhiyun
136*4882a593SmuzhiyunIt's possible to alter the standard object C flags in the following way:
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun  CFLAGS_perf.o        += '...'  - adds CFLAGS for perf.o object
139*4882a593Smuzhiyun  CFLAGS_gtk           += '...'  - adds CFLAGS for gtk build object
140*4882a593Smuzhiyun  CFLAGS_REMOVE_perf.o += '...'  - removes CFLAGS for perf.o object
141*4882a593Smuzhiyun  CFLAGS_REMOVE_gtk    += '...'  - removes CFLAGS for gtk build object
142*4882a593Smuzhiyun
143*4882a593SmuzhiyunThis C flags changes has the scope of the Build makefile they are defined in.
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun
146*4882a593SmuzhiyunDependencies
147*4882a593Smuzhiyun------------
148*4882a593Smuzhiyun
149*4882a593SmuzhiyunFor each built object file 'a.o' the '.a.cmd' is created and holds:
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun  - Command line used to built that object
152*4882a593Smuzhiyun    (for each object)
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun  - Dependency rules generated by 'gcc -Wp,-MD,...'
155*4882a593Smuzhiyun    (for compiled object)
156*4882a593Smuzhiyun
157*4882a593SmuzhiyunAll existing '.cmd' files are included in the Build process to follow properly
158*4882a593Smuzhiyunthe dependencies and trigger a rebuild when necessary.
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun
161*4882a593SmuzhiyunSingle rules
162*4882a593Smuzhiyun------------
163*4882a593Smuzhiyun
164*4882a593SmuzhiyunIt's possible to build single object file by choice, like:
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun  $ make util/map.o    # objects
167*4882a593Smuzhiyun  $ make util/map.i    # preprocessor
168*4882a593Smuzhiyun  $ make util/map.s    # assembly
169