Code Chapter 8
Writing a New Recipe
Establish the Recipe
Skeleton Recipe
SUMMARY = "" DESCRPTION = "" AUTHOR = "" HOMEPAGE = "" BUGTRACKER = ""
Packaging the Build Output
Customizing Packaging
SUMMARY = "Hello Universe Application" DESCRPTION = "The ultimate hello extending beyond 'world'." AUTHOR = "spacey@universetrotter.com" HOMEPAGE = "http://universetrotter.com" BUGTRACKER = "https://bugs.universetrotter.com" PN = "hellouniverse" # Other recipe stuff # ... PACKAGES =+ "graphics" FILES_${PN}-graphics = "${datadir}/pixmaps/*" FILES_${PN}-doc =+ "${datadir}/blurbs/*" PACKAGE_BEFORE_PN = "examples" FILES_${PN}-examples = "${datadir}/examples"
Custom Installation Scripts
Postinstallation Script Skeleton
pkg_postinst_${PN}() { #!/bin/sh # shell commands go here }
Conditional Postinstallation Script Skeleton
pkg_postinst_${PN}() { #!/bin/sh if [ x"$D" = "x" ]; then # shell commands for target execution else # shell commands for build system execution fi }
Recipe Examples
C File Software Package
C File Software Package Source Code
helloprint.h: void printHello(void); helloprint.c: #include <stdio.h> #include "helloprint.h" void printHello(void) { printf("Hello, World! My first Yocto Project recipe.\n"); return; } hello.c: #include "helloprint.h" int main() { printHello(); return(0); }
Recipe to Build C File Source Package
SUMMARY = "Simple Hello World Application" DESCRIPTION = "A test application to demonstrate how to create a recipe \ by directly compiling C files with BitBake." SECTION = "examples" PRIORITY = "optional" LICENSE = "MIT" LIC_FILES_CHKSUM = "\ file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "file://hello-1.0.tgz" S = "${WORKDIR}" do_compile() { ${CC} -c helloprint.c ${CC} -c hello.c ${CC} -o hello hello.o helloprint.o } do_install() { install -d ${D}${bindir} install -m 0755 hello ${D}${bindir} }
Makefile-Based Software Package
Makefile
CC=gcc RM=rm CFLAGS=-c -Wall LDFLAGS= DESTDIR= BINDIR=/usr/bin SOURCES=hello.c helloprint.c OBJECTS=$(SOURCES:.c=.o) EXECUTABLE=hellomake .cpp.o: $(CC) $(CFLAGS) $< -o $@ all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(LDFLAGS) $^ -o $@ clean: $(RM) $(EXECUTABLE) *.o install: $(EXECUTABLE) mkdir -p $(DESTDIR)/$(BINDIR) install -m 0755 $< $(DESTDIR)/$(BINDIR)
Recipe to Build Makefile-Based Software Package
SUMMARY = "Hello with Makefile" DESCRIPTION = "A test application to demonstrate how to create a \ recipe for makefile-based project." SECTION = "examples" PRIORITY = "optional" LICENSE = "MIT" LIC_FILES_CHKSUM = "\ file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "file://${P}.tgz" EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' \ 'CFLAGS=${CFLAGS} -I${S}/. -DWITHOUT_XATTR' 'BUILDDIR=${S}'" do_install () { oe_runmake install DESTDIR=${D} BINDIR=${bindir} SBINDIR=${sbindir} \ MANDIR=${mandir} INCLUDEDIR=${includedir} }
CMake-Based Software Package
Recipe to Build Synergy
SUMMARY = "Synergy - control multiple computers with one keyboard and mouse" HOMEPAGE = "http://synergy.googlecode.com" LIC_FILES_CHKSUM = "file://COPYING;md5=9772a11e3569985855e2ce450e56f991" LICENSE = "GPL-2.0" SECTION = "x11/utils" DEPENDS = "libx11 libxtst libxinerama" SRC_URI = "http://synergy.googlecode.com/files/synergy-${PV}-Source.tar.gz" SRC_URI[md5sum] = "3534c65ecfa6e47d7899c57975442f03" SRC_URI[sha256sum] = \ "0afc83e4ed0b46ed497d4229b2b2854e8d3c581a112f4da05110943edbfacc03" S = "${WORKDIR}/${PN}-${PV}-Source" inherit cmake do_install() { install -d ${D}/usr/bin install -m 0755 ${S}/bin/synergy* ${D}/usr/bin/ }
GNU Autotools-Based Software Package
Recipe to Build the Nano Editor
SUMMARY = "GNU nano - an enhanced clone of the Pico text editor" DESCRIPTION = "GNU nano - an enhanced clone of the Pico text editor" HOMEPAGE = "http://www.nano-editor.org" BUGTRACKER = "https://savannah.gnu.org/bugs/?group=nano" SECTION = "console/utils" PRIORITY = "optional" LICENSE = "GPLv3" LIC_FILES_CHKSUM = "file://COPYING;md5=f27defe1e96c2e1ecd4e0c9be8967949" DEPENDS = "ncurses" PV_MAJ = "${@bb.data.getVar('PV',d,1).split('.')[0]}" PV_MIN = "${@bb.data.getVar('PV',d,1).split('.')[1]}" SRC_URI = "\ http://www.nano-editor.org/dist/v${PV_MAJ}.${PV_MIN}/nano-${PV}.tar.gz" SRC_URI[md5sum] = "af09f8828744b0ea0808d6c19a2b4bfd" SRC_URI[sha256sum] = "\ b7bace9a8e543b84736d6ef5ce5430305746efea3aacb24391f692efc6f3c8d3" inherit autotools gettext RDEPENDS_${PN} = "ncurses"
Externally Built Software Package
Recipe using bin_package
SUMMARY = "Package the Proprietary Software" DESCRIPTION = "A sample recipe utilizing the bin_package class \ to package the externally build Proprietary software \ package." LICENSE = "CLOSED" SRC_URI = "file://proprietary-${PV}.rpm" inherit bin_package