From ab864d71fb85628e0f1980b84a23bad7a7e2baea Mon Sep 17 00:00:00 2001 From: Scott Rifenbark Date: Wed, 7 May 2014 23:50:59 +0300 Subject: dev-manual: Edits to the "Understanding Recipe Syntax" section. (From yocto-docs rev: 97e5025ccff55efd077fdaf9b2d65eae5b59bc2b) Signed-off-by: Scott Rifenbark Signed-off-by: Richard Purdie --- .../dev-manual/dev-manual-common-tasks.xml | 120 +++++++++------------ 1 file changed, 49 insertions(+), 71 deletions(-) diff --git a/documentation/dev-manual/dev-manual-common-tasks.xml b/documentation/dev-manual/dev-manual-common-tasks.xml index 55257f7c58..01add16a60 100644 --- a/documentation/dev-manual/dev-manual-common-tasks.xml +++ b/documentation/dev-manual/dev-manual-common-tasks.xml @@ -1290,6 +1290,21 @@ The basic items that make up a BitBake recipe file are as follows: + Variable Assignments and Manipulations: + Variable assignments allow a value to be assigned to a + variable. + The assignment can be static text or might include + the contents of other variables. + In addition to the assignment, appending and prepending + operations are also supported. + The following example shows some of the ways + you can use variables in recipes: + + S = "${WORKDIR}/postfix-${PV}" + CFLAGS += "-DNO_ASM" + SRC_URI_append = " file://fixup.patch" + + Functions: Functions provide a series of actions to be performed. You usually use functions to override the default @@ -1313,25 +1328,9 @@ new functions are not replacing or complimenting the default functions. You can implement functions in Python - instead of sh. + instead of shell. Both of these options are not seen in the majority of recipes. - Variable Assignments and Manipulations: - Variable assignments allow a value to be assigned to a - variable. - The assignment can be static text or might include - the contents of other variables. - In addition to the assignment, appending and prepending - operations are also supported. - The following example shows some of the ways - you can use variables in recipes: - - S = "${WORKDIR}/postfix-${PV}" - PR = "r4" - CFLAGS += "-DNO_ASM" - SRC_URI_append = "file://fixup.patch" - - Keywords: BitBake recipes use only a few keywords. You use keywords to include common @@ -1389,7 +1388,8 @@ Quote All Assignments: "<value>" - - Use double quotes to make all variable assignments. + Use double quotes around the value in all variable + assignments. VAR1 = "${OTHERVAR}" VAR2 = "The version is ${PV}" @@ -1401,13 +1401,14 @@ unset. Use the question mark followed by the equal sign (?=) to make a "soft" assignment - used for conditional assignment. - Typically, you use conditional assignment to - provide - a default value for use when no specific definition is - provided by the machine or distro configuration in - your local.conf configuration. - + used for conditional assignment. + Typically, "soft" assignments are used in the + local.conf file for variables + that are allowed to come through from the external + environment. + Doing so allows you to actually set variables from + the external environment that would otherwise be + overwritten. Here is an example: VAR1 ?= "New value" @@ -1455,7 +1456,9 @@ This operator does not add any additional space. Also, the operator is applied after all the +=, and - =+ operators have been applied. + =+ operators have been applied and + after all = assignments have + occurred. The following example shows the space being explicitly added to the start to ensure the appended @@ -1470,26 +1473,17 @@ SRC_URI_append_sh4 = " file://fix-makefile.patch" - - The appended information is a variable itself. - Therefore, it is possible to use the - += or - =+ operators to assign - variables to the _append - information: - - SRC_URI_append = " file://fix-makefile.patch" - SRC_URI_append += "file://fix-install.patch" - - Prepending: _prepend - Use the _prepend operator to prepend values to existing variables. This operator does not add any additional space. - Also, it is applied after all the - += and - =+ operators have been applied. + This operator does not add any additional space. + Also, the operator is applied after all the + +=, and + =+ operators have been applied and + after all = assignments have + occurred. The following example shows the space being explicitly added to the end to ensure the prepended @@ -1504,45 +1498,29 @@ CFLAGS_prepend_sh4 = " file://fix-makefile.patch" - - The appended information is a variable itself. - Therefore, it is possible to use the - += or - =+ operators to assign - variables to the _prepend - information: - - CFLAGS_prepend = "-I${S}/myincludes " - CFLAGS_prepend += "-I${S}/myincludes2 " - - Notice in this example no spacing is used at the - front of the value string. - Recall that the += operator - adds space itself. - - Spaces as Compared to Tabs: + Indentation: Use spaces for indentation rather than than tabs. - Both currently work, however it is a policy decision - of the Yocto Project to use tabs in shell functions - and spaces in Python. - However, realize that some layers use a policy of all - spaces. + For shell functions, both currently work. + However, it is a policy decision of the Yocto Project + to use tabs in shell functions. + Realize that some layers have a policy to use spaces + for all indentation. - Using Python for Complex Operations: ${@...} - + Using Python for Complex Operations: ${@<variable>} - For more advanced processing, it is possible to use Python code during variable assignments (e.g. search and replacement on a variable). - You indicate Python code using a preceding - @ character in the variable - assignment: + You indicate Python code using the + ${@<variable>} syntax for the + variable assignment: - CXXFLAGS := "${@'${CXXFLAGS}'.replace('-frename-registers', '')}" + SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz - Shell Syntax: - Use shell syntax as if you were writing a shell script - when you describe a list of actions to take. + Shell Function Syntax: + Use shell function syntax as if you were writing a shell + script when you describe a list of actions to take. You should ensure that your script works with a generic sh and that it does not require any bash or other shell-specific -- cgit v1.2.3-54-g00ecf