1 # sourceipk.bbclass enables the creation of an ipk file that contains the
2 # sources used during the build. The sources contained in the ipk are the
3 # patched sources before configuration has been done.
5 # This class is used to provide an easy method to ship the corresponding
6 # sources for a package to end users so that they can install them on their
7 # host or target systems.
9 # This package uses the following variables to control its operations:
10 # - CREATE_SRCIPK = When set to 1 this variable indicates that
11 # a source ipk should be generated for the package.
12 # - SRCIPK_INSTALL_DIR = This variable indicates the directory to install
14 # - SRCIPK_PACKAGE_ARCH = This variable allows specific recipies to
15 # specify an architecture for the sourcetree
16 # package is "all" is not appropriate
17 # - SRCIPK_INC_EXTRAFILES = When set to 1 this variable indicates that
18 # the source ipk should contain extra files
19 # such as the README file and recipe.
21 # The default installation directory for the sources is:
24 # By setting the SRCIPK_INSTALL_DIR this default can be changed to any
25 # location desired. When combined with the opkg -o option this allows for the
26 # system building to specify a relative package install location to the
27 # install root given to opkg. Each source ipk can have a different directory.
29 # Creation of the source ipk can be controlled per package by setting
30 # CREATE_SRCIPK = "1" in the package recipe or by setting
31 # CREATE_SRCIPK_pn-<package name> = "1" in your local.conf
34 # Need to figure out how to use ipkg-build in this class.
35 # I tried adding it as a dependency for the do_create_srcipk
37 # do_create_srcipk[depends] += "ipkg-utils-native:do_populate_sysroot"
38 # But then there is a circular dependency between sourcipk.bbclass and
39 # ipkg-utils-native. Until I can figure out how to resolve this
40 # circular dependency I am extracting the needed pieces from ipkg-build
41 # into this class and building the source ipk myself.
44 # Default is to not create the source ipk
47 # Default installation prefix
48 SRCIPK_INSTALL_DIR ?= "/usr/src/${PN}-src"
50 # Default PACKAGE_ARCH for sources is "all"
51 SRCIPK_PACKAGE_ARCH ?= "all"
53 # Default SRCIPK_INCLUDE_EXTRAFILES is to include the extra files
54 SRCIPK_INCLUDE_EXTRAFILES ?= "1"
56 # Create a README file that describes the contents of the source ipk
57 sourceipk_create_readme() {
58 readme="$1/README.${PN}-src"
60 echo 'This package contains the patched sources for ${PN} that' >> $readme
61 echo 'were used to generate the ${PN} binary ipk package(s).' >> $readme
62 echo 'This package does not build or generate the binaries' >> $readme
63 echo 'directly. To build the binaries you must either' >> $readme
64 echo 'configure and build the sources yourself or use:' >> $readme
65 echo ' bitbake ${PN}' >> $readme
67 echo 'NOTE: The patches applied to the sources can be found in' >> $readme
68 echo " the \"patches\" directory" >> $readme
71 # Create the source ipk file. The ipk is manually created here instead
72 # of using the normal ipk system because some recipes will over write
73 # the PACKAGES variable. Thus if this class added a -src package
74 # to the list of packages to be created that package would be lost.
75 # See the linux kernel recipe for an example of this issue.
76 sourceipk_do_create_srcipk() {
77 if [ ${CREATE_SRCIPK} != "0" ]
79 tmp_dir="${WORKDIR}/sourceipk-tmp"
80 srcipk_dir="${WORKDIR}/sourceipk-data"
81 mkdir -p $tmp_dir/CONTROL
83 control_file="$tmp_dir/CONTROL/control"
85 # Write the control file
86 echo "Package: ${PN}-src" > $control_file
87 echo "Version: ${PV}-${PR}" >> $control_file
88 echo "Description: Patched sources for ${PN}" >> $control_file
89 echo "Section: ${SECTION}" >> $control_file
90 echo "Priority: Optional" >> $control_file
91 echo "Maintainer: ${MAINTAINER}" >> $control_file
92 echo "License: ${LICENSE}" >> $control_file
93 echo "Architecture: ${SRCIPK_PACKAGE_ARCH}" >> $control_file
95 if [ "$srcuri" == "" ]
99 echo "Source: $srcuri" >> $control_file
100 #Write the control tarball
101 tar -C $tmp_dir/CONTROL --owner=0 --group=0 -czf $srcipk_dir/control.tar.gz .
103 # Get rid of temporary control file
104 rm -rf $tmp_dir/CONTROL
106 # Copy sources for packaging
107 mkdir -p $tmp_dir/${SRCIPK_INSTALL_DIR}
108 cp -rLf ${S}/* $tmp_dir/${SRCIPK_INSTALL_DIR}/
110 if [ ${SRCIPK_INCLUDE_EXTRAFILES} != "0" ]
112 sourceipk_create_readme $tmp_dir/${SRCIPK_INSTALL_DIR}/
113 cp ${FILE} $tmp_dir/${SRCIPK_INSTALL_DIR}/
116 #Write the data tarball
117 tar -C $tmp_dir --owner=0 --group=0 -czf $srcipk_dir/data.tar.gz .
119 # Create the debian-binary file
120 echo "2.0" > $srcipk_dir/debian-binary
123 mkdir -p ${DEPLOY_DIR_IPK}/${SRCIPK_PACKAGE_ARCH}
124 pkg_file=${DEPLOY_DIR_IPK}/${SRCIPK_PACKAGE_ARCH}/${PN}-src_${PV}-${PR}_${SRCIPK_PACKAGE_ARCH}.ipk
126 ( cd $srcipk_dir && ar -crf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz )
128 # Remove the temporary directory
133 EXPORT_FUNCTIONS do_create_srcipk
135 do_create_srcipk[deptask] = "do_patch"
137 addtask create_srcipk after do_patch before do_configure
139 #Add source packages to list of packages OE knows about
140 PACKAGES_DYNAMIC += "${PN}-src"