How to personalize a package’s CFLAGS in Gentoo

Ok, last attempt to revive this blog ;-)

Well, there’s a little trick that I’d like to share with you guys that use Gentoo. Some time ago, I had to modify the value of the $CFLAGS environment variable for 2 packages in the Portage because they had some problems when the debugging option was enabled for configure. After some search, I’ve found the solution for this. Here goes the step-by-step (it’s pretty easy, I promise):

1) First, find the package’s path inside the Portage. This path is basically compounded by <category>/<package_name>. Let’s suppose that this path is app-editors/vim, so if your Portage is under /etc/portage, you should have a directory called /usr/portage/app-editors/vim/.

2) Now, you should create a file named /etc/portage/env/<category>/<package_name>, just like that:

#> touch /etc/portage/env/app-editors/vim

3) Edit this file with you preferred editor and put there the $CFLAGS value that you want, like that:

CFLAGS=”-D_HAVE_XYZ_”

If you want to append some value to the existing $CFLAGS, just do it:

CFLAGS=”${CFLAGS} –D_HAVE_XYZ_”

4) You are ready to go! :D

See? It’s pretty easy. Note that you can also add other variables (like $LDFLAGS), and emerge will handle them for you. If you have some trouble with the procedure, just let me know :-).

See ya!

6 Responses to How to personalize a package’s CFLAGS in Gentoo

  1. Donnie Berkholz says:

    You can also do other really cool stuff with those like add arbitrary code to run before or after any ebuild phase. This is called ebuild phase hooks: http://dev.gentoo.org/~zmedico/portage/doc/portage.html#config-bashrc-ebuild-phase-hooks

  2. sergiosdj says:

    Hey Donnie,

    Thanks for your comment. I appreciated your “improvement” over my post :-).

    Regards.

  3. otubo says:

    Sergiosdj,

    I never had the need to add some extra/diferent CFLAGS to specific packages. But when I do, I’ll know how.

    See ya on monday ;-)
    []’s

  4. anselmolsm says:

    sergiosdj, what a nice surprise!

    I’ve just googled about it and the first result was this post =D

    []’s

  5. mike says:

    sergiosdj, for some reason i am unable to touch files in /etc/portage/var…i wonder why…

  6. sujeet says:

    Hi,

    I was just wondering if it was possible to specify CFLAGS like this for a _particular_ version of a package. For example, I use -march=barcelona in my CFLAGS for everything, but, I do not want this setting when compiling gcc-3.4.6-r2 since this will break the install.

    Personally, I believe this is a defect in the gcc-3.4.6-r2 ebuild, as the temporary xgcc compiler inherits the CFLAGS from make.conf, but I nonetheless would like an appropriate work around. (Creating version-specific entry in /etc/portage/env would be ideal.)

    Best,

    Sujeet Akula

Leave a reply to anselmolsm Cancel reply