angstrom: prefer the git version of tslib
[openembedded.git] / classes / sourceipk.bbclass
blobb37bbf9aa9bf67221223ffa75e292a6e982bd952
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 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"
59     touch $readme
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
66     echo '' >> $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" ]
78     then
79         tmp_dir="${WORKDIR}/sourceipk-tmp"
80         srcipk_dir="${WORKDIR}/sourceipk-data"
81         mkdir -p $tmp_dir/CONTROL
82         mkdir -p $srcipk_dir
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
94         srcuri="${SRC_URI}"
95         if [ "$srcuri" = "" ]
96         then
97             srcuri="OpenEmbedded"
98         fi
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}/
109         # Copy any hidden files in the source directory such as
110         # eclipse project files.  Use a regex to avoid trying to
111         # copy the . and .. directories.  This is only required for
112         # the top-level directory as the hidden files will be copied
113         # for subdiretories.
114         hidden_files=`find ${S} -maxdepth 1 -name ".*"`
115         for f in $hidden_files
116         do
117             cp -rf $f $tmp_dir/${SRCIPK_INSTALL_DIR}/
118         done
120         if [ ${SRCIPK_INCLUDE_EXTRAFILES} != "0" ]
121         then
122             sourceipk_create_readme $tmp_dir/${SRCIPK_INSTALL_DIR}/
123             cp ${FILE} $tmp_dir/${SRCIPK_INSTALL_DIR}/
124         fi
126         #Write the data tarball
127         tar -C $tmp_dir --owner=0 --group=0 -czf $srcipk_dir/data.tar.gz .
129         # Create the debian-binary file
130         echo "2.0" > $srcipk_dir/debian-binary
132         #Write the ipk file
133         mkdir -p ${DEPLOY_DIR_IPK}/${SRCIPK_PACKAGE_ARCH}
134         pkg_file=${DEPLOY_DIR_IPK}/${SRCIPK_PACKAGE_ARCH}/${PN}-src_${PV}-${PR}_${SRCIPK_PACKAGE_ARCH}.ipk
135         rm -f $pkg_file
136         ( cd $srcipk_dir && ar -crf $pkg_file ./debian-binary ./data.tar.gz ./control.tar.gz )
138         # Remove the temporary directory
139         rm -rf $tmp_dir
140     fi
143 EXPORT_FUNCTIONS do_create_srcipk
145 do_create_srcipk[deptask] = "do_patch"
147 # Add a blank compileconfigs task.  This allows the sourceipk to schedule
148 # its copy of the sources for kernels using the multi-kernel functionality
149 # before the compileconfigs task.  Failure to do this results in a race
150 # condition where in the best case the sources packaged may contain binary
151 # builds and in the worst case binary files being cleaned cause an error
152 # in the copy command for the sourceipk.
153 do_compileconfigs() {
154     :
156 addtask compileconfigs after do_patch before do_configure
158 addtask create_srcipk after do_patch before do_compileconfigs
160 #Add source packages to list of packages OE knows about
161 PACKAGES_DYNAMIC += "${PN}-src"