Gentoo Archives: gentoo-amd64

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-amd64@l.g.o
Subject: [gentoo-amd64] Re: CFLAGS question from a AMD64 newbie
Date: Wed, 17 Dec 2008 08:41:42
Message-Id: pan.2008.12.17.08.41.28@cox.net
In Reply to: Re: [gentoo-amd64] Re: CFLAGS question from a AMD64 newbie by Branko Badrljica
1 Branko Badrljica <brankob@××××××××××.com> posted
2 49485D48.9000001@××××××××××.com, excerpted below, on Wed, 17 Dec 2008
3 03:00:40 +0100:
4
5 > Duncan wrote:
6 >
7 >> The feature is somewhat limited, in that these files are sourced in the
8 >> bash portion of portage (basically, ebuild.sh) -- the python portion
9 >> knows nothing about them.
10 > GREAT !
11 > Can I use them for switching gcc compiler etc, not just for simple
12 > variable settings ?
13
14 I've never tried anything but variable settings, but it's sourced as
15 bash, so you should be able to do pretty much anything you could do in a
16 bash script, so yes, gcc-config ..., etc, should work... again, for the
17 bash side only.
18
19 I'm not sure how much the python might depend on gcc, etc, however. I do
20 know that any deps (say if the package is in fortran or java and it tests
21 gcc to see if it was merged with the appropriate USE flags) are resolved
22 in the python bit, in emerge itself after it has sourced the ebuilds for
23 deps, but before it actually starts on any of the ebuild phases. Thus,
24 if you go messing with that on a package where it's a dependency, you're
25 likely to have "undesired results". However, I'm not sure if portage/
26 emerge depends on gcc and/or anything else staying stable beneath it or
27 not.
28
29 There's also the parallel merge ability in newer portage to think about.
30 If you use it and invoke one of these env scripts, who knows /what/ stage
31 some other package might be at in parallel merge! That'd DEFINITELY be
32 an invitation to trouble, since gcc-config switches things system-wide,
33 and switching versions of gcc in the middle of compiling say glibc could
34 literally bring the entire system crashing down around your ears when it
35 tries to qmerge that half-n-half glibc to the running system!
36
37 Thus I'd certainly recommend sticking to stuff that's going to affect
38 only that single package, setting environment variables, etc. Don't do
39 anything that will affect the system globally unless you are seriously
40 looking for trouble.
41
42 What I'd suggest, if you want to push the boundaries, is to either just
43 try it and see what you can get away with, or go looking in the forums
44 and etc. There's gotta be a thread or two on the subject. You could
45 also see if there's anything on the gentoo-user list archive (I use
46 gmane, Gentoo has its own archive, and I think there's at least one more
47 archive, Mark's or some such) about it, and/or ask there. There's some
48 pretty knowledgeable people out there -- way more than just what I know
49 on it.
50
51 > And btw, is there a way to switch gcc back after emerge without changing
52 > ebuild file ?
53
54 Well, yes, but you're getting yet another layer deeper into the advanced
55 stuff. I haven't played around with them myself directly, but there are
56 pre-phase and post-phase hooks for each phase. Presumably you'd stick
57 the switch back in the post-compile-hook (and I'm not sure I got the name
58 exactly right) routine. More below...
59
60 > Or maybe there is some other mechanism to be able to compile package
61 > with particular gcc ?
62
63 This doesn't directly answer that question, but it should give you a
64 better idea the sort of flexibility available...
65
66 In addition to the per-package env files, there's the general
67 /etc/portage/bashrc (see the file list and descriptions in
68 man (5) portage). This is actually cascaded in a specific order (which
69 IDR ATM) with the profile.bashrc(s) at the various levels of your
70 (cascading) profile. Among other things, the Gentoo/amd64 project was I
71 believe the first to use this method to filter invalid cflags (say you
72 use gcc-4.3.x normally, with certain cflags only valid from it on, and
73 gcc-config back to a gcc-4.2.x version that doesn't recognize these
74 cflags, one of the bashrc layers filters the invalid ones). Take a look
75 at the various *bashrc files in the profiles to get an idea of what
76 Gentoo is already using them for! (Actually, I believe the env files
77 were first implemented this way but at a global not profile level, tho in
78 newer portage they may be called directly.)
79
80 There's actually some pretty advanced bashrc and phase hooks
81 implementations around. Ed Catmur, the guy who wrote udept, has a nice
82 one that allows all sorts of interesting stuff. Unfortunately, he seems
83 to have disappeared (and udept is in the process of being masked since
84 there's no upstream any more and it doesn't support the latest EAPIs,
85 I've no idea if he simply disappeared without warning or if he got in an
86 argument with a Gentoo dev or what, but the Gentoo stuff on his site now
87 says it needs a password, which could as easily mean it doesn't exist
88 there anymore at all), but I have a copy of his tarballs from a year or
89 so ago.
90
91 I use only one of the several features his bashrc and phase hooks scripts
92 made possible, FEATURES=patchtree. The idea and implementation is
93 similar to but not identical to the env tree, in this case, a
94 category/package based tree under /etc/portage/patches/, only the package
95 is in this case another subdir instead of a file as it is with the env
96 tree.
97
98 Here's an example of how I use it. As I regularly install and set as my
99 normal system gcc still-hard-masked versions, I'm used to checking bugs
100 for patches to enable various packages to compile with the newer gcc,
101 well before the patches actually find their way into the tree. If I can
102 find an appropriate patch, I can dump the patch file into an
103 appropriately versioned patches/category/package-ver subdir, and with his
104 scripts in place and that feature turned on, portage will automatically
105 apply the patch post-unpack-phase. His scripts are even smart enough to
106 determine in many cases whether auto-conf, etc, needs rerun, and handle
107 it automatically, altho they don't handle every possibility. While I
108 used to nearly always have at least a half dozen ebuilds in my overlay,
109 with various patches and etc applied so they'd build with the latest gcc
110 or glibc or whatever, now I just dump the patches in an appropriately
111 created subdir and let portage and Ed's FEATURES=patchtree handle it!
112 Between that and the env tree, I seldom have to carry patched ebuilds in
113 my overlay any more, and it's often empty and seldom has more than a
114 couple more complex case ebuilds in it.
115
116 Another feature I do NOT use from his scripts, is
117 FEATURES=installsources, which keeps the sources around for reference. I
118 think a number of Gentoo devs are actually using this feature, so they
119 can keep sources around for what they're working on. I think it can be
120 toggled per package but as I said I don't use it so I haven't looked too
121 deeply into how it works.
122
123 There's some more, as well. IDR the details, but looked at them and
124 decided I didn't need them here.
125
126 If you're interested in the tarballs, maybe even only to take a look at
127 for ideas to see what's actually possible, ask, and I'll mail them to
128 you. Of course with him apparently disappeared and no longer involved
129 with Gentoo, if/when they eventually start to break, you'll need to deal
130 with that, but they're working fine so far with the portage-2.2-rcs I've
131 been running, and I think the portage hooks they use are intended to stay
132 around for awhile, so if it breaks, it'll probably be inadvertent (as I
133 said I believe a number of devs use those scripts...), and a portage bug
134 report and/or a bit of bash hacking should hopefully get it working again.
135
136 > One more question:
137 >
138 > What if two or more files match the package ?
139 >
140 > Like:
141 >
142 > env/sys-kernel/vanilla-sources
143 > env/sys-kernel/vanilla-sources-2
144 > env/sys-kernel/vanilla-sources2.6
145 > env/sys-kernel/vanilla-sources-2.6.27
146 >
147 > Do they all get included in some /un/specified order or just
148 > first/last/unspecified one ?
149
150 I don't remember the specific details, in part because as I described, I
151 have the patch tree to think about as well, and I never remember the
152 versioning formats for either. I know the first and the last example
153 above should work, and 2.6.27 would work for -rX versions as well (found
154 that out the other day, the ~ and = prefixes don't work, but just the
155 version applies for all revisions, too), but generally get confused and
156 often end up simply trying it until I get it to work, for the odd cases.
157
158 Matter of fact, I spent a bit of time looking for documentation on
159 exactly what version format to use for env files myself, the other day,
160 but didn't find it. That's when I discovered the versioning info
161 mentioned above, simply by testing until I got it working.
162
163 --
164 Duncan - List replies preferred. No HTML msgs.
165 "Every nonfree program has a lord, a master --
166 and if you use the program, he is your master." Richard Stallman