/[gli]/branches/overhaul/src/fe/gtk/MakeDotConf.py
Gentoo

Contents of /branches/overhaul/src/fe/gtk/MakeDotConf.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1800 - (show annotations) (download) (as text)
Sun Mar 18 16:36:44 2007 UTC (7 years, 9 months ago) by agaffney
File MIME type: text/x-python
File size: 16248 byte(s)
use os.system() instead of GLIUtility.spawn()  to view log
1 # Copyright 1999-2005 Gentoo Foundation
2 # This source code is distributed under the terms of version 2 of the GNU
3 # General Public License as published by the Free Software Foundation, a copy
4 # of which can be found in the main directory of this project.
5
6 import gtk
7 from GLIScreen import *
8 import commands
9 import gobject
10 import GLIUtility
11
12 class Panel(GLIScreen):
13
14 title = "make.conf"
15 make_conf_values = {}
16 use_flags = []
17 use_desc = {}
18 columns = []
19 arch_procs = { 'alpha': ("ev4", "ev5", "ev56", "pca56", "ev6", "ev67"),
20 'amd64': ("athlon64", "opteron", "athlon-fx", "k8", "nocona"),
21 'ppc': ("G3", "G4", "G5", "power", "common", "powerpc"),
22 'x86': ("i386", "i486", "i586", "pentium", "pentium-mmx", "i686", "pentiumpro", "pentium2", "pentium3", "pentium3m", "pentium-m", "pentium4", "pentium4m", "prescott", "k6", "k6-2", "k6-3", "athlon", "athlon-tbird", "athlon-4", "athlon-xp", "athlon-mp", "winchip-c6", "winchip2", "c3", "c3-2")
23 }
24 optimizations = ["-O0", "-O1", "-O2", "-Os", "-O3"]
25 _helptext = """
26 <b><u>Make.conf</u></b>
27
28 One of the unique (and best) features of Gentoo is the ability to define flags
29 (called USE flags) that determine what components are compiled into
30 applications. For example, you can enable the "alsa" flag and programs that
31 have alsa capability will compile in support for alsa. Otherwise they will
32 leave it out, resulting in smaller, faster applications. The result is a
33 finely-tuned OS with no unnecessary components to slow you down.
34
35 There are two types of USE flags, local (for only one application), and global
36 (for all apps). The local use flags will tell you which package they refer to
37 in the Description. Note that the names of the USE flags can sometimes be
38 misleading since they often refer to only one package.
39
40 CFLAGS:
41
42 The CFLAGS variable defines the optimization flags for the gcc C and C++
43 compilers. Although we define those generally here, you will only have maximum
44 performance if you optimize these flags for each program separately. The reason
45 for this is because every program is different.
46
47 A first setting is the processor, which specifies the name of the target
48 architecture. Select your Proc from the list.
49
50 A second one is the -O flag (that is a capital O, not a zero), which specifies
51 the gcc optimization class flag. Possible classes are s (for size-optimized),
52 0 (zero - for no optimizations), 1, 2 or 3 for more speed-optimization flags
53 (every class has the same flags as the one before, plus some extras). 2 is a
54 safe level of optimization.
55
56 You can add additional custom CFLAGS with the textbox.
57
58 Another popular optimization flag is -pipe (use pipes rather than temporary
59 files for communication between the various stages of compilation).
60
61 Mind you that using -fomit-frame-pointer (which doesn't keep the frame pointer
62 in a register for functions that don't need one) might have serious
63 repercussions on the debugging of applications!
64
65 Other:
66
67 Select Use unstable only if you are an expert Gentoo user or want to use
68 bleeding edge unstable applications. This is highly NOT recommended because it
69 will often result in failed installations due to compilation errors in unstable
70 applications.
71
72 Select Build binary packages if you plan on using the compiled packages
73 elsewhere (very rarely needed).
74
75 DistCC functionality has not yet been implemented with the GTK+ frontend. If
76 you need this, use gli-dialog, the command-line frontend to GLI.
77
78 Select ccache to enable ccache support via CC.
79
80 The CHOST variable declares the target build host for your system. This variable
81 should already be set to the correct value. Do not edit it as that might break
82 your system. If the CHOST variable does not look correct to you, you might be
83 using the wrong stage3 tarball.
84
85 With MAKEOPTS you define how many parallel compilations should occur when you
86 install a package. A good choice is the number of CPUs in your system plus one,
87 but this guideline isn't always perfect. The syntax for the MAKEOPTS varaible is
88 "-jN" where N is the number of parallel compilations (for example: -j2).
89 """
90
91 def __init__(self, controller):
92 GLIScreen.__init__(self, controller)
93
94 portage_info = {}
95 for line in GLIUtility.spawn(r"emerge --info 2>/dev/null | grep '^[A-Z0-9_]\+=' | sed -e 's:\" \([A-Z]\):\"\n\1:g'", chroot=self.controller.install_profile.get_root_mount_point(), return_output=True)[1].strip().split("\n"):
96 parts = line.split("=", 1)
97 portage_info[parts[0]] = parts[1].strip("'\"")
98 self.system_use_flags = portage_info.get("USE", "")
99 self.system_cflags = portage_info.get("CFLAGS", "")
100 self.system_chost = portage_info.get("CHOST", "")
101 self.system_makeopts = portage_info.get("MAKEOPTS", "")
102 self.system_features = portage_info.get("FEATURES", "")
103 self.system_accept_keywords = portage_info.get("ACCEPT_KEYWORDS", "")
104
105 vert = gtk.VBox(False, 0)
106 vert.set_border_width(10)
107
108 f = open(self.controller.install_profile.get_root_mount_point() + "/usr/portage/profiles/use.desc", "r")
109 for line in f:
110 line = line.strip()
111 if not line or line.startswith("#"): continue
112 dash_pos = line.find(" - ")
113 if dash_pos == -1: continue
114 flagname = line[:dash_pos] or line[dash_pos-1]
115 desc = line[dash_pos+3:]
116 self.use_desc[flagname] = desc
117 f.close()
118
119 f = open(self.controller.install_profile.get_root_mount_point() + "/usr/portage/profiles/use.local.desc", "r")
120 for line in f:
121 line = line.strip()
122 if not line or line.startswith("#"): continue
123 dash_pos = line.find(" - ")
124 if dash_pos == -1: continue
125 colon_pos = line.find(":", 0, dash_pos)
126 pkg = line[:colon_pos]
127 flagname = line[colon_pos+1:dash_pos] or line[colon_pos+1]
128 desc = "(" + pkg + ") " + line[dash_pos+3:]
129 self.use_desc[flagname] = desc
130 f.close()
131
132 hbox = gtk.HBox(False, 0)
133 label = gtk.Label()
134 label.set_markup("<b>USE flags:</b>")
135 hbox.pack_start(label, expand=False, fill=False, padding=0)
136 vert.pack_start(hbox, expand=False, fill=False, padding=5)
137
138 sorted_use = self.use_desc.keys()
139 sorted_use.sort()
140 self.treedata = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING)
141 for flag in sorted_use:
142 self.treedata.append([(flag in self.use_flags and self.use_flags[flag] == 1), flag, self.use_desc[flag]])
143 self.treeview = gtk.TreeView(self.treedata)
144 self.toggle_renderer = gtk.CellRendererToggle()
145 self.toggle_renderer.set_property("activatable", True)
146 self.toggle_renderer.connect("toggled", self.flag_toggled)
147 self.columns.append(gtk.TreeViewColumn("Active", self.toggle_renderer, active=0))
148 self.columns.append(gtk.TreeViewColumn("Flag", gtk.CellRendererText(), text=1))
149 self.columns.append(gtk.TreeViewColumn("Description", gtk.CellRendererText(), text=2))
150 for column in self.columns:
151 column.set_resizable(True)
152 self.treeview.append_column(column)
153 self.treewindow = gtk.ScrolledWindow()
154 self.treewindow.set_size_request(-1, 180)
155 self.treewindow.set_shadow_type(gtk.SHADOW_IN)
156 self.treewindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
157 self.treewindow.add(self.treeview)
158 vert.pack_start(self.treewindow, expand=False, fill=False, padding=10)
159
160 hbox = gtk.HBox(False, 0)
161 label = gtk.Label()
162 label.set_markup("<b>CFLAGS:</b>")
163 hbox.pack_start(label, expand=False, fill=False, padding=0)
164 vert.pack_start(hbox, expand=False, fill=False, padding=5)
165
166 hbox = gtk.HBox(False, 0)
167 hbox.pack_start(gtk.Label("Proc:"), expand=False, fill=False, padding=0)
168 self.proc_combo = gtk.combo_box_new_text()
169 # for proc in self.arch_procs[self.controller.cc.get_arch()]:
170 # self.proc_combo.append_text(proc)
171 # self.proc_combo.set_active(0)
172 hbox.pack_start(self.proc_combo, expand=False, fill=False, padding=10)
173 hbox.pack_start(gtk.Label("Optimizations:"), expand=False, fill=False, padding=0)
174 self.optimizations_combo = gtk.combo_box_new_text()
175 for opt in self.optimizations:
176 self.optimizations_combo.append_text(opt)
177 self.optimizations_combo.set_active(0)
178 hbox.pack_start(self.optimizations_combo, expand=False, fill=False, padding=10)
179 vert.pack_start(hbox, expand=False, fill=False, padding=5)
180 hbox = gtk.HBox(False, 0)
181 hbox.pack_start(gtk.Label("Custom:"), expand=False, fill=False, padding=0)
182 self.custom_cflags_entry = gtk.Entry()
183 self.custom_cflags_entry.set_width_chars(25)
184 self.custom_cflags_entry.set_text("-pipe")
185 hbox.pack_start(self.custom_cflags_entry, expand=False, fill=False, padding=10)
186 vert.pack_start(hbox, expand=False, fill=False, padding=5)
187
188 hbox = gtk.HBox(False, 0)
189 label = gtk.Label()
190 label.set_markup("<b>Other:</b>")
191 hbox.pack_start(label, expand=False, fill=False, padding=0)
192 vert.pack_start(hbox, expand=False, fill=False, padding=5)
193
194 hbox = gtk.HBox(False, 0)
195 self.unstable_packages_check = gtk.CheckButton("Use unstable (~arch)")
196 hbox.pack_start(self.unstable_packages_check, expand=False, fill=False, padding=0)
197 self.build_binary_check = gtk.CheckButton("Build binary packages")
198 hbox.pack_start(self.build_binary_check, expand=False, fill=False, padding=20)
199 self.use_distcc_check = gtk.CheckButton("DistCC")
200 hbox.pack_start(self.use_distcc_check, expand=False, fill=False, padding=0)
201 self.use_ccache_check = gtk.CheckButton("ccache")
202 hbox.pack_start(self.use_ccache_check, expand=False, fill=False, padding=20)
203 vert.pack_start(hbox, expand=False, fill=False, padding=5)
204
205 hbox = gtk.HBox(False, 0)
206 hbox.pack_start(gtk.Label("CHOST:"), expand=False, fill=False, padding=0)
207 self.chost_combo = gtk.combo_box_new_text()
208 # for chost in GLIUtility.get_chosts(self.controller.cc.get_arch()):
209 # self.chost_combo.append_text(chost)
210 # self.chost_combo.set_active(0)
211 hbox.pack_start(self.chost_combo, expand=False, fill=False, padding=10)
212 hbox.pack_start(gtk.Label(" "), expand=False, fill=False, padding=15)
213 hbox.pack_start(gtk.Label("MAKEOPTS:"), expand=False, fill=False, padding=0)
214 self.makeopts_entry = gtk.Entry()
215 self.makeopts_entry.set_width_chars(7)
216 hbox.pack_start(self.makeopts_entry, expand=False, fill=False, padding=10)
217 vert.pack_start(hbox, expand=False, fill=False, padding=5)
218
219 self.add_content(vert)
220
221 def flag_toggled(self, cell, path):
222 model = self.treeview.get_model()
223 model[path][0] = not model[path][0]
224 flag = model[path][1]
225 if model[path][0]:
226 self.use_flags[flag] = 1
227 else:
228 if flag in self.use_flags:
229 self.use_flags[flag] = 0
230 return
231
232 def activate(self):
233 self.controller.SHOW_BUTTON_BACK = True
234 self.controller.SHOW_BUTTON_FORWARD = True
235 self.etc_files = self.controller.install_profile.get_etc_files()
236 if not "make.conf" in self.etc_files:
237 self.etc_files['make.conf'] = {}
238 self.make_conf_values = self.etc_files['make.conf']
239 # Parsing USE
240 self.use_flags = {}
241 if not self.make_conf_values.has_key('USE') or not self.make_conf_values['USE']:
242 self.make_conf_values['USE'] = self.system_use_flags
243 for flag in self.make_conf_values['USE'].split(" "):
244 if flag.startswith("-"):
245 flag = flag[1:]
246 self.use_flags[flag] = 0
247 else:
248 self.use_flags[flag] = 1
249 sorted_use = self.use_desc.keys()
250 sorted_use.sort()
251 self.treedata = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING)
252 for flag in sorted_use:
253 if flag in self.use_flags and self.use_flags[flag] == 1:
254 self.treedata.append([True, flag, self.use_desc[flag]])
255 else:
256 self.treedata.append([False, flag, self.use_desc[flag]])
257 self.treeview.set_model(self.treedata)
258 if self.controller.install_profile.get_grp_install():
259 self.treeview.set_sensitive(False)
260 self.unstable_packages_check.set_sensitive(False)
261 self.unstable_packages_check.set_active(False)
262 else:
263 self.treeview.set_sensitive(True)
264 self.unstable_packages_check.set_sensitive(True)
265 # Parsing CFLAGS
266 if not self.make_conf_values.has_key('CFLAGS') or not self.make_conf_values['CFLAGS']:
267 self.make_conf_values['CFLAGS'] = self.system_cflags
268 custom_cflags = ""
269 arch = ""
270 for flag in self.make_conf_values['CFLAGS'].split(" "):
271 flag = flag.strip()
272 if flag.startswith("-march="):
273 arch = flag[flag.find("=")+1:]
274 elif flag.startswith("-O"):
275 i = 0
276 for opt in self.optimizations:
277 if flag == opt:
278 self.optimizations_combo.set_active(i)
279 break
280 i += 1
281 else:
282 custom_cflags = custom_cflags + " " + flag
283 self.proc_combo.get_model().clear()
284 for i, proc in enumerate(self.arch_procs[self.controller.cc.get_arch()]):
285 self.proc_combo.append_text(proc)
286 if proc == arch:
287 self.proc_combo.set_active(i)
288 if self.proc_combo.get_active() == -1:
289 self.proc_combo.set_active(0)
290 self.custom_cflags_entry.set_text(custom_cflags.strip())
291 # Parsing ACCEPT_KEYWORDS
292 if not self.make_conf_values.has_key('ACCEPT_KEYWORDS') or not self.make_conf_values['ACCEPT_KEYWORDS']:
293 self.make_conf_values['ACCEPT_KEYWORDS'] = self.system_accept_keywords
294 if self.make_conf_values['ACCEPT_KEYWORDS'] and self.make_conf_values['ACCEPT_KEYWORDS'][0] == "~":
295 self.unstable_packages_check.set_active(True)
296 else:
297 self.unstable_packages_check.set_active(False)
298 # Parsing FEATURES
299 if not self.make_conf_values.has_key('FEATURES') or not self.make_conf_values['FEATURES']:
300 self.make_conf_values['FEATURES'] = self.system_features
301 self.use_distcc_check.set_active(False)
302 self.use_ccache_check.set_active(False)
303 self.build_binary_check.set_active(False)
304 for feature in self.make_conf_values['FEATURES'].split(" "):
305 feature = feature.strip()
306 if feature == "distcc":
307 self.use_distcc_check.set_active(True)
308 elif feature == "ccache":
309 self.use_ccache_check.set_active(True)
310 elif feature == "buildpkg":
311 self.build_binary_check.set_active(True)
312 # Parsing CHOST
313 if not self.make_conf_values.has_key('CHOST') or not self.make_conf_values['CHOST']:
314 self.make_conf_values['CHOST'] = self.system_chost
315 self.chost_combo.get_model().clear()
316 for i, chost in enumerate(GLIUtility.get_chosts(self.controller.cc.get_arch())):
317 self.chost_combo.append_text(chost)
318 if chost == self.make_conf_values['CHOST'] or i == 0:
319 self.chost_combo.set_active(i)
320 if self.controller.install_profile.get_install_stage() > 1:
321 self.chost_combo.set_sensitive(False)
322 else:
323 self.chost_combo.set_sensitive(True)
324 # Parsing MAKEOPTS
325 if not self.make_conf_values.has_key('MAKEOPTS') or not self.make_conf_values['MAKEOPTS']:
326 self.make_conf_values['MAKEOPTS'] = self.system_makeopts
327 self.makeopts_entry.set_text(self.make_conf_values['MAKEOPTS'])
328
329 def next(self):
330 temp_use = ""
331 sorted_use = self.use_flags.keys()
332 sorted_use.sort()
333 for flag in sorted_use:
334 if self.use_flags[flag]:
335 temp_use += " " + flag
336 else:
337 temp_use += " -" + flag
338 self.make_conf_values['USE'] = temp_use
339 self.make_conf_values['CFLAGS'] = "-march=" + self.arch_procs[self.controller.cc.get_arch()][self.proc_combo.get_active()] + " " + self.optimizations[self.optimizations_combo.get_active()] + " " + self.custom_cflags_entry.get_text()
340 if self.unstable_packages_check.get_active():
341 self.make_conf_values['ACCEPT_KEYWORDS'] = "~" + self.controller.cc.get_arch()
342 else:
343 self.make_conf_values['ACCEPT_KEYWORDS'] = ""
344 temp_features = ""
345 if self.build_binary_check.get_active():
346 temp_features += "buildpkg "
347 if self.use_distcc_check.get_active():
348 temp_features += "distcc "
349 if self.use_ccache_check.get_active():
350 temp_features += "ccache "
351 self.make_conf_values['FEATURES'] = temp_features.strip()
352 if self.controller.install_profile.get_install_stage() > 1:
353 if 'CHOST' in self.make_conf_values:
354 del self.make_conf_values['CHOST']
355 else:
356 self.make_conf_values['CHOST'] = GLIUtility.get_chosts(self.controller.cc.get_arch())[self.chost_combo.get_active()]
357 self.make_conf_values['MAKEOPTS'] = self.makeopts_entry.get_text()
358 self.etc_files['make.conf'] = self.make_conf_values
359 self.controller.install_profile.set_etc_files(self.etc_files)
360
361 progress = ProgressDialog(self.controller, ("configure_make_conf", ), self.progress_callback)
362 progress.run()
363
364 def progress_callback(self, result, data=None):
365 if result == PROGRESS_DONE:
366 self.controller.load_screen("RootPass")
367 else:
368 GLIScreen.progress_callback(self, result, data)

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20