msmcomm: bump SRCREV for latest updates
[openembedded.git] / classes / sourceipk.bbclass
blob1b639969979a316c815e32fdc175710db18b0203
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
13 #                             the sources into.
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:
22 #   /usr/src/${PN}-src
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.
28
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
33 #TODO: 
34 # Need to figure out how to use opkg-build in this class.
35 # I tried adding it as a dependency for the do_create_srcipk
36 # task using:
37 #   do_create_srcipk[depends] += "opkg-utils-native:do_populate_sysroot"
38 # But then there is a circular dependency between sourcipk.bbclass and
39 # opkg-utils-native.  Until I can figure out how to resolve this
40 # circular dependency I am extracting the needed pieces from opkg-build
41 # into this class and building the source ipk myself.
44 # Default is to not create the source ipk
45 CREATE_SRCIPK ?= "0"
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 section matches the recipe section
54 SRCIPK_SECTION ?= "${SECTION}"
56 # Default SRCIPK_INCLUDE_EXTRAFILES is to include the extra files
57 SRCIPK_INCLUDE_EXTRAFILES ?= "1"
59 # Create a README file that describes the contents of the source ipk
60 sourceipk_create_readme() {
61     readme="$1/README.${PN}-src"
62     touch $readme
63     echo 'This package contains the patched sources for ${PN} that' >> $readme
64     echo 'were used to generate the ${PN} binary ipk package(s).' >> $readme
65     echo 'This package does not build or generate the binaries' >> $readme
66     echo 'directly.  To build the binaries you must either' >> $readme
67     echo 'configure and build the sources yourself or use:' >> $readme
68     echo '    bitbake ${PN}' >> $readme
69     echo '' >> $readme
70     echo 'NOTE: The patches applied to the sources can be found in' >> $readme
71     echo "      the \"patches\" directory" >> $readme
74 # Create the source ipk file.  The ipk is manually created here instead
75 # of using the normal ipk system because some recipes will over write
76 # the PACKAGES variable.  Thus if this class added a -src package
77 # to the list of packages to be created that package would be lost.
78 # See the linux kernel recipe for an example of this issue.
79 sourceipk_do_create_srcipk() {
80     if [ ${CREATE_SRCIPK} != "0" ]
81     then
82         tmp_dir="${WORKDIR}/sourceipk-tmp"
83         srcipk_dir="${WORKDIR}/sourceipk-data"
84         mkdir -p $tmp_dir/CONTROL
85         mkdir -p $srcipk_dir
86         control_file="$tmp_dir/CONTROL/control"
88         # Write the control file
89         echo "Package: ${PN}-src" > $control_file
90         echo "Version: ${PV}-${PR}" >> $control_file
91         echo "Description: Patched sources for ${PN}" >> $control_file
92         echo "Section: ${SRCIPK_SECTION}" >> $control_file
93         echo "Priority: Optional" >> $control_file
94         echo "Maintainer: ${MAINTAINER}" >> $control_file
95         echo "License: ${LICENSE}" >> $control_file
96         echo "Architecture: ${SRCIPK_PACKAGE_ARCH}" >> $control_file
97         srcuri="${SRC_URI}"
98         if [ "$srcuri" = "" ]
99         then
100             srcuri="OpenEmbedded"
101         fi
102         echo "Source: $srcuri" >> $control_file
103         #Write the control tarball
104         tar -C $tmp_dir/CONTROL --owner=0 --group=0 -czf $srcipk_dir/control.tar.gz .
106         # Get rid of temporary control file
107         rm -rf $tmp_dir/CONTROL
109         # Copy sources for packaging
110         mkdir -p $tmp_dir/${SRCIPK_INSTALL_DIR}
111         if [ -e ${S} ]; then
112             if [ "${S}" = "${WORKDIR}" ]; then
113                 excludes='--exclude ./temp/\* --exclude ./sourceipk-tmp/\* --exclude ./sourceipk-data/\*'
114             fi
115             tar -C ${S} -cO $excludes . | tar -C $tmp_dir/${SRCIPK_INSTALL_DIR} -xpf -
116         fi
118         if [ ${SRCIPK_INCLUDE_EXTRAFILES} != "0" ]
119         then
120             sourceipk_create_readme $tmp_dir/${SRCIPK_INSTALL_DIR}/
121             cp ${FILE} $tmp_dir/${SRCIPK_INSTALL_DIR}/
122         fi
124         #Write the data tarball
125         tar -C $tmp_dir --owner=0 --group=0 -czf $srcipk_dir/data.tar.gz .
127         # Create the debian-binary file
128         echo "2.0" > $srcipk_dir/debian-binary
130         #Write the ipk file
131         mkdir -p ${DEPLOY_DIR_IPK}/${SRCIPK_PACKAGE_ARCH}
132         pkg_file=${DEPLOY_DIR_IPK}/${SRCIPK_PACKAGE_ARCH}/${PN}-src_${PV}-${PR}_${SRCIPK_PACKAGE_ARCH}.ipk
133         rm -f $pkg_file
134         ( cd $srcipk_dir && ar -crf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz )
136         # Remove the temporary directory
137         rm -rf $tmp_dir
138     fi
141 EXPORT_FUNCTIONS do_create_srcipk
143 do_create_srcipk[deptask] = "do_patch"
145 addtask create_srcipk after do_patch before do_configure
147 python () {
148     if d.getVar('do_compileconfigs', False):
149         deps = d.getVarFlag('do_compileconfigs', 'deps') or []
150         deps.append('do_create_srcipk')
151         d.setVarFlag('do_compileconfigs', 'deps', deps)
154 #Add source packages to list of packages OE knows about
155 PACKAGES_DYNAMIC += "${PN}-src"