kexec-tools-klibc-static: remove the unsettings of compiler flags
[openembedded.git] / classes / icecc.bbclass
blob4962fcb7e6ec3aa4c5799c1f9c00358473d0f886
1 # IceCream distributed compiling support
3 # Stages directories with symlinks from gcc/g++ to icecc, for both
4 # native and cross compilers. Depending on each configure or compile,
5 # the directories are added at the head of the PATH list and ICECC_CXX
6 # and ICEC_CC are set.
8 # For the cross compiler, creates a tar.gz of our toolchain and sets
9 # ICECC_VERSION accordingly.
11 #The class now handles all 3 different compile 'stages' (i.e native ,cross-kernel and target) creating the
12 #necessary enviroment tar.gz file to be used by the remote machines.
13 #It also supports meta-toolchain generation
15 #If ICECC_PATH is not set in local.conf then the class will try to locate it using 'which'
16 #but nothing is sure ;)
18 #If ICECC_ENV_EXEC is set in local.conf should point to the icecc-create-env script provided by the user
19 #or the default one provided by icecc-create-env.bb  will be used
20 #(NOTE that this is a modified version of the script need it and *not the one that comes with icecc*
22 #User can specify if specific packages or packages belonging to class should not use icecc to distribute
23 #compile jobs to remote machines, but handled localy, by defining ICECC_USER_CLASS_BL and ICECC_PACKAGE_BL
24 #with the appropriate values in local.conf
25 #########################################################################################
26 #Error checking is kept to minimum so double check any parameters you pass to the class
27 ###########################################################################################
30 def icc_determine_gcc_version(gcc):
31     """
32     Hack to determine the version of GCC
34     'i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5363)'
35     """
36     return os.popen("%s --version" % gcc ).readline().split()[2]
38 def create_cross_env(bb,d):
39     """
40     Create a tar.bz2 of the current toolchain
41     """
42     # Constin native-native compilation no environment needed if
43     # host prefix is empty (let us duplicate the query for ease)
44     prefix = bb.data.expand('${HOST_PREFIX}', d)
45     if len(prefix) == 0:
46         return ""
48     import tarfile, socket, time
49     ice_dir = bb.data.expand('${CROSS_DIR}', d)
50     prefix  = bb.data.expand('${HOST_PREFIX}' , d)
51     distro  = bb.data.expand('${DISTRO}', d)
52     target_sys = bb.data.expand('${TARGET_SYS}',  d)
53     target_prefix = bb.data.expand('${TARGET_PREFIX}',  d)
54     float   = bb.data.getVar('TARGET_FPU', d) or "hard"
55     name    = socket.gethostname()
57     # Stupid check to determine if we have built a libc and a cross
58     # compiler.
59     try:
60         os.stat(os.path.join(ice_dir, target_sys, 'lib', 'libstdc++.so'))
61         os.stat(os.path.join(ice_dir, target_sys, 'bin', 'g++'))
62     except: # no cross compiler built yet
63         bb.error('no cross compiler built yet?')
64         return ""
66     VERSION = icc_determine_gcc_version( os.path.join(ice_dir,target_sys,"bin","g++") )
67     cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
68     tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
70     try:
71         os.stat(tar_file)
72         # tar file already exists
73         return tar_file
74     except: 
75         try:
76             os.makedirs(os.path.join(ice_dir,'ice'))
77         except:
78             # directory already exists, continue
79             pass
82     #check if user has specified a specific icecc-create-env script
83     #if not use the OE provided one
84     cr_env_script = bb.data.expand('${ICECC_ENV_EXEC}',  d)
85     if cr_env_script == "${ICECC_ENV_EXEC}":
86         cr_env_script = bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
87     #call the modified create-env script
88     result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
89            "--silent",
90            os.path.join(ice_dir, 'bin', "%s-gcc" % target_sys),
91            os.path.join(ice_dir, 'bin', "%s-g++" % target_sys),
92            os.path.join(ice_dir, 'bin', "%s-as" % target_sys),
93            os.path.join(ice_dir,"ice",cross_name) ) )
94     return tar_file
97 def create_native_env(bb,d):
98     import tarfile, socket, time
99     ice_dir = bb.data.expand('${CROSS_DIR}', d)
100     prefix  = bb.data.expand('${HOST_PREFIX}' , d)
101     distro  = bb.data.expand('${DISTRO}', d)
102     target_sys = bb.data.expand('${TARGET_SYS}',  d)
103     target_prefix = bb.data.expand('${TARGET_PREFIX}',  d)
104     float   = bb.data.getVar('TARGET_FPU', d) or "hard"
105     name    = socket.gethostname()
107     archive_name = "local-host-env" + "-" + name
108     tar_file = os.path.join(ice_dir, 'ice', archive_name + '.tar.gz')
110     try:
111         os.stat(tar_file)
112         # tar file already exists
113         return tar_file
114     except: 
115         try:
116             #os.makedirs(os.path.join(ice_dir))
117             os.makedirs(os.path.join(ice_dir,'ice'))
118         except:
119             # directory already exists, continue
120             pass
122     #check if user has specified a specific icecc-create-env script
123     #if not use the OE provided one
124     cr_env_script = bb.data.expand('${ICECC_ENV_EXEC}',  d)
125     if cr_env_script == "${ICECC_ENV_EXEC}":
126         cr_env_script = bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
127     result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
128            "--silent",
129            os.popen("%s gcc" % "which").read()[:-1],
130            os.popen("%s g++" % "which").read()[:-1],
131            os.popen("%s as" % "which").read()[:-1],
132            os.path.join(ice_dir,"ice",archive_name) ) )
133     return tar_file
136 def get_cross_kernel_cc(bb,d):
137     kernel_cc = bb.data.expand('${KERNEL_CC}', d)
138     kernel_cc = kernel_cc.replace('ccache', '').strip()
139     kernel_cc = kernel_cc.split(' ')[0]
140     kernel_cc = kernel_cc.strip()
141     return kernel_cc
144 def create_cross_kernel_env(bb,d):
145     import tarfile, socket, time
146     ice_dir = bb.data.expand('${CROSS_DIR}', d)
147     prefix  = bb.data.expand('${HOST_PREFIX}' , d)
148     distro  = bb.data.expand('${DISTRO}', d)
149     target_sys = bb.data.expand('${TARGET_SYS}',  d)
150     target_prefix = bb.data.expand('${TARGET_PREFIX}',  d)
151     float   = bb.data.getVar('TARGET_FPU', d) or "hard"
152     name    = socket.gethostname()
153     kernel_cc = get_cross_kernel_cc(bb, d)
155     # Stupid check to determine if we have built a libc and a cross
156     # compiler.
157     try:
158         os.stat(os.path.join(ice_dir, 'bin', kernel_cc))
159     except: # no cross compiler built yet
160         bb.error('no kernel cross compiler built yet')
161         return ""
163     VERSION = icc_determine_gcc_version( os.path.join(ice_dir,"bin",kernel_cc) )
164     cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
165     tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
167     try:
168         os.stat(tar_file)
169         # tar file already exists
170         return tar_file
171     except: 
172         try:
173             os.makedirs(os.path.join(ice_dir,'ice'))
174         except:
175             # directory already exists, continue
176             pass
179     #check if user has specified a specific icecc-create-env script
180     #if not use the OE provided one
181     cr_env_script = bb.data.getVar('ICECC_ENV_EXEC',  d) or  bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
182     result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
183            "--silent",
184            os.path.join(ice_dir, 'bin', kernel_cc),
185            os.path.join(ice_dir, 'bin', "%s-g++" % target_sys),
186            os.path.join(ice_dir, 'bin', "%s-as" % target_sys),
187            os.path.join(ice_dir, "ice", cross_name) ) )
188     return tar_file
191 def create_env(bb,d):
193         #return create_cross_kernel_env(bb,d) 
195         if bb.data.inherits_class("native", d):
196           return create_native_env(bb,d)
197         elif bb.data.inherits_class("kernel", d):
198           return create_cross_kernel_env(bb,d)
199         elif bb.data.inherits_class("cross", d):
200           return create_native_env(bb,d)
201         elif bb.data.inherits_class("sdk", d):
202           return create_native_env(bb,d)
203         else:  
204           return create_cross_env(bb,d)
207 def create_path(compilers, type, bb, d):
208     """
209     Create Symlinks for the icecc in the staging directory
210     """
211     staging = os.path.join(bb.data.expand('${STAGING_DIR}', d), "ice", type)
213     #check if the icecc path is set by the user
214     icecc   = bb.data.getVar('ICECC_PATH', d) or os.popen("%s icecc" % "which").read()[:-1]
216     # Create the dir if necessary
217     try:
218         os.stat(staging)
219     except:
220         os.makedirs(staging)
222     for compiler in compilers:
223         gcc_path = os.path.join(staging, compiler)
224         try:
225             os.stat(gcc_path)
226         except:
227             os.symlink(icecc, gcc_path)
229     return staging + ":"
232 def use_icc_version(bb,d):
233       icecc_ver = "yes"
234       system_class_blacklist = [ "none" ] 
236       for black in system_class_blacklist:
237            if bb.data.inherits_class(black, d):
238               icecc_ver = "no"
240       user_class_blacklist =  bb.data.getVar('ICECC_USER_CLASS_BL', d) or "none"
241       user_class_blacklist = user_class_blacklist.split()
243       for black in user_class_blacklist:
244            if bb.data.inherits_class(black, d):
245               icecc_ver = "no"
247       return icecc_ver
250 def icc_path(bb,d):
251     package_tmp = bb.data.expand('${PN}', d)
253     #"system" package blacklist contains a list of packages that can not distribute compile tasks
254     #for one reason or the other
255     system_package_blacklist = [ "uclibc", "glibc", "gcc", "qemu", "bind", "u-boot", "dhcp-forwarder", "enchant", "connman" ]
256     user_package_blacklist = (bb.data.getVar('ICECC_USER_PACKAGE_BL', d) or "").split()
257     package_blacklist = system_package_blacklist + user_package_blacklist
259     for black in package_blacklist:
260         if black in package_tmp:
261             bb.note(package_tmp, ' found in blacklist, disable icecc')
262             bb.data.setVar("PARALLEL_MAKE" , "", d) 
263             return ""
265     prefix = bb.data.expand('${HOST_PREFIX}', d)
267     if bb.data.inherits_class("cross", d):
268         return create_path( ["gcc", "g++"], "native", bb, d)
270     elif bb.data.inherits_class("native", d):
271         return create_path( ["gcc", "g++"], "native", bb, d)
273     elif bb.data.inherits_class("kernel", d):
274         return create_path( [get_cross_kernel_cc(bb,d), ], "cross-kernel", bb, d)
276     elif len(prefix) == 0:
277         return create_path( ["gcc", "g++"], "native", bb, d)
279     else:
280         return create_path( [prefix+"gcc", prefix+"g++"], "cross", bb, d)      
283 def icc_version(bb,d):
284     return create_env(bb,d)
287 def check_for_kernel(bb,d):     
288     if  bb.data.inherits_class("kernel", d):
289          return "yes"
290     return "no"
293 set_icecc_env() {
294     ICE_PATH=${@icc_path(bb,d)}
295     if test x${ICE_PATH} != x; then
296         export PATH=${ICE_PATH}$PATH
297         export CCACHE_PATH=$PATH
298         #check if we are building a kernel and select gcc-cross-kernel
299         if [ "${@check_for_kernel(bb,d)}" = "yes" ]; then
300             export ICECC_CC="${@get_cross_kernel_cc(bb,d)}"
301             export ICECC_CXX="${HOST_PREFIX}g++"
302         else
303             export ICECC_CC="${HOST_PREFIX}gcc"
304             export ICECC_CXX="${HOST_PREFIX}g++"
305         fi
307         if [ "${@use_icc_version(bb,d)}" = "yes" ]; then
308             export ICECC_VERSION="${@icc_version(bb,d)}"
309         else
310             export -n ICECC_VERSION
311         fi
312         oenote "set the icecream environment variables: PATH=$PATH, CCACHE_PATH=$CCACHE_PATH, ICECC_CC=$ICECC_CC, ICECC_CXX=$ICECC_CXX, ICECC_VERSION=$ICECC_VERSION"
313     fi
316 do_configure_prepend() {
317     set_icecc_env
320 do_compile_prepend() {
321     set_icecc_env