169 lines · plain
1Build Framework2===============3 4The perf build framework was adopted from the kernel build system, hence the5idea and the way how objects are built is the same.6 7Basically the user provides set of 'Build' files that list objects and8directories to nest for specific target to be build.9 10Unlike the kernel we don't have a single build object 'obj-y' list that where11we setup source objects, but we support more. This allows one 'Build' file to12carry a sources list for multiple build objects.13 14 15Build framework makefiles16-------------------------17 18The build framework consists of 2 Makefiles:19 20 Build.include21 Makefile.build22 23While the 'Build.include' file contains just some generic definitions, the24'Makefile.build' file is the makefile used from the outside. It's25interface/usage is following:26 27 $ make -f tools/build/Makefile.build srctree=$(KSRC) dir=$(DIR) obj=$(OBJECT)28 29where:30 31 KSRC - is the path to kernel sources32 DIR - is the path to the project to be built33 OBJECT - is the name of the build object34 35When succefully finished the $(DIR) directory contains the final object file36called $(OBJECT)-in.o:37 38 $ ls $(DIR)/$(OBJECT)-in.o39 40which includes all compiled sources described in 'Build' makefiles.41 42 43Build makefiles44---------------45 46The user supplies 'Build' makefiles that contains a objects list, and connects47the build to nested directories.48 49Assume we have the following project structure:50 51 ex/a.c52 /b.c53 /c.c54 /d.c55 /arch/e.c56 /arch/f.c57 58Out of which you build the 'ex' binary ' and the 'libex.a' library:59 60 'ex' - consists of 'a.o', 'b.o' and libex.a61 '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, it64only 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.o70 ex-y += b.o71 ex-y += b.o # duplicates in the lists are allowed72 73 libex-y += c.o74 libex-y += d.o75 libex-y += arch/76 77 ex/arch/Build:78 libex-y += e.o79 libex-y += f.o80 81and runs:82 83 $ make -f tools/build/Makefile.build dir=. obj=ex84 $ make -f tools/build/Makefile.build dir=. obj=libex85 86which creates the following objects:87 88 ex/ex-in.o89 ex/libex-in.o90 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.o96 $ gcc -o ex ex-in.o libex.a97 98You can check the 'ex' example in 'tools/build/tests/ex' for more details.99 100 101Makefile.include102----------------103 104The tools/build/Makefile.include makefile could be included105via 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=. obj111 112 to make it easier to invoke build like:113 make $(build)=ex114 115 116Fixdep117------118It is necessary to build the fixdep helper before invoking the build.119The Makefile.include file adds the fixdep target, that could be120invoked by the user.121 122 123Rules124-----125 126The build framework provides standard compilation rules to handle .S and .c127compilation.128 129It's possible to include special rule if needed (like we do for flex or bison130code generation).131 132 133CFLAGS134------135 136It's possible to alter the standard object C flags in the following way:137 138 CFLAGS_perf.o += '...' - adds CFLAGS for perf.o object139 CFLAGS_gtk += '...' - adds CFLAGS for gtk build object140 CFLAGS_REMOVE_perf.o += '...' - removes CFLAGS for perf.o object141 CFLAGS_REMOVE_gtk += '...' - removes CFLAGS for gtk build object142 143This C flags changes has the scope of the Build makefile they are defined in.144 145 146Dependencies147------------148 149For each built object file 'a.o' the '.a.cmd' is created and holds:150 151 - Command line used to built that object152 (for each object)153 154 - Dependency rules generated by 'gcc -Wp,-MD,...'155 (for compiled object)156 157All existing '.cmd' files are included in the Build process to follow properly158the dependencies and trigger a rebuild when necessary.159 160 161Single rules162------------163 164It's possible to build single object file by choice, like:165 166 $ make util/map.o # objects167 $ make util/map.i # preprocessor168 $ make util/map.s # assembly169