18c2ecf20Sopenharmony_ciBuild Framework
28c2ecf20Sopenharmony_ci===============
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciThe perf build framework was adopted from the kernel build system, hence the
58c2ecf20Sopenharmony_ciidea and the way how objects are built is the same.
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciBasically the user provides set of 'Build' files that list objects and
88c2ecf20Sopenharmony_cidirectories to nest for specific target to be build.
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciUnlike the kernel we don't have a single build object 'obj-y' list that where
118c2ecf20Sopenharmony_ciwe setup source objects, but we support more. This allows one 'Build' file to
128c2ecf20Sopenharmony_cicarry a sources list for multiple build objects.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciBuild framework makefiles
168c2ecf20Sopenharmony_ci-------------------------
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciThe build framework consists of 2 Makefiles:
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci  Build.include
218c2ecf20Sopenharmony_ci  Makefile.build
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciWhile the 'Build.include' file contains just some generic definitions, the
248c2ecf20Sopenharmony_ci'Makefile.build' file is the makefile used from the outside. It's
258c2ecf20Sopenharmony_ciinterface/usage is following:
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci  $ make -f tools/build/Makefile.build srctree=$(KSRC) dir=$(DIR) obj=$(OBJECT)
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciwhere:
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci  KSRC   - is the path to kernel sources
328c2ecf20Sopenharmony_ci  DIR    - is the path to the project to be built
338c2ecf20Sopenharmony_ci  OBJECT - is the name of the build object
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciWhen succefully finished the $(DIR) directory contains the final object file
368c2ecf20Sopenharmony_cicalled $(OBJECT)-in.o:
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci  $ ls $(DIR)/$(OBJECT)-in.o
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciwhich includes all compiled sources described in 'Build' makefiles.
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciBuild makefiles
448c2ecf20Sopenharmony_ci---------------
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciThe user supplies 'Build' makefiles that contains a objects list, and connects
478c2ecf20Sopenharmony_cithe build to nested directories.
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciAssume we have the following project structure:
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci  ex/a.c
528c2ecf20Sopenharmony_ci    /b.c
538c2ecf20Sopenharmony_ci    /c.c
548c2ecf20Sopenharmony_ci    /d.c
558c2ecf20Sopenharmony_ci    /arch/e.c
568c2ecf20Sopenharmony_ci    /arch/f.c
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciOut of which you build the 'ex' binary ' and the 'libex.a' library:
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci  'ex'      - consists of 'a.o', 'b.o' and libex.a
618c2ecf20Sopenharmony_ci  'libex.a' - consists of 'c.o', 'd.o', 'e.o' and 'f.o'
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciThe build framework does not create the 'ex' and 'libex.a' binaries for you, it
648c2ecf20Sopenharmony_cionly prepares proper objects to be compiled and grouped together.
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciTo follow the above example, the user provides following 'Build' files:
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci  ex/Build:
698c2ecf20Sopenharmony_ci    ex-y += a.o
708c2ecf20Sopenharmony_ci    ex-y += b.o
718c2ecf20Sopenharmony_ci    ex-y += b.o # duplicates in the lists are allowed
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci    libex-y += c.o
748c2ecf20Sopenharmony_ci    libex-y += d.o
758c2ecf20Sopenharmony_ci    libex-y += arch/
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci  ex/arch/Build:
788c2ecf20Sopenharmony_ci    libex-y += e.o
798c2ecf20Sopenharmony_ci    libex-y += f.o
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciand runs:
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci  $ make -f tools/build/Makefile.build dir=. obj=ex
848c2ecf20Sopenharmony_ci  $ make -f tools/build/Makefile.build dir=. obj=libex
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciwhich creates the following objects:
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci  ex/ex-in.o
898c2ecf20Sopenharmony_ci  ex/libex-in.o
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cithat contain request objects names in Build files.
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciIt's only a matter of 2 single commands to create the final binaries:
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci  $ ar  rcs libex.a libex-in.o
968c2ecf20Sopenharmony_ci  $ gcc -o ex ex-in.o libex.a
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ciYou can check the 'ex' example in 'tools/build/tests/ex' for more details.
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ciMakefile.include
1028c2ecf20Sopenharmony_ci----------------
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciThe tools/build/Makefile.include makefile could be included
1058c2ecf20Sopenharmony_civia user makefiles to get usefull definitions.
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciIt defines following interface:
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci  - build macro definition:
1108c2ecf20Sopenharmony_ci      build := -f $(srctree)/tools/build/Makefile.build dir=. obj
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci    to make it easier to invoke build like:
1138c2ecf20Sopenharmony_ci      make $(build)=ex
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ciFixdep
1178c2ecf20Sopenharmony_ci------
1188c2ecf20Sopenharmony_ciIt is necessary to build the fixdep helper before invoking the build.
1198c2ecf20Sopenharmony_ciThe Makefile.include file adds the fixdep target, that could be
1208c2ecf20Sopenharmony_ciinvoked by the user.
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciRules
1248c2ecf20Sopenharmony_ci-----
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciThe build framework provides standard compilation rules to handle .S and .c
1278c2ecf20Sopenharmony_cicompilation.
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ciIt's possible to include special rule if needed (like we do for flex or bison
1308c2ecf20Sopenharmony_cicode generation).
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ciCFLAGS
1348c2ecf20Sopenharmony_ci------
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ciIt's possible to alter the standard object C flags in the following way:
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci  CFLAGS_perf.o        += '...'  - adds CFLAGS for perf.o object
1398c2ecf20Sopenharmony_ci  CFLAGS_gtk           += '...'  - adds CFLAGS for gtk build object
1408c2ecf20Sopenharmony_ci  CFLAGS_REMOVE_perf.o += '...'  - removes CFLAGS for perf.o object
1418c2ecf20Sopenharmony_ci  CFLAGS_REMOVE_gtk    += '...'  - removes CFLAGS for gtk build object
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ciThis C flags changes has the scope of the Build makefile they are defined in.
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciDependencies
1478c2ecf20Sopenharmony_ci------------
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ciFor each built object file 'a.o' the '.a.cmd' is created and holds:
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci  - Command line used to built that object
1528c2ecf20Sopenharmony_ci    (for each object)
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci  - Dependency rules generated by 'gcc -Wp,-MD,...'
1558c2ecf20Sopenharmony_ci    (for compiled object)
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ciAll existing '.cmd' files are included in the Build process to follow properly
1588c2ecf20Sopenharmony_cithe dependencies and trigger a rebuild when necessary.
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ciSingle rules
1628c2ecf20Sopenharmony_ci------------
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciIt's possible to build single object file by choice, like:
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci  $ make util/map.o    # objects
1678c2ecf20Sopenharmony_ci  $ make util/map.i    # preprocessor
1688c2ecf20Sopenharmony_ci  $ make util/map.s    # assembly
169