Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 46816 - molden ebuild uses error-prone syntax
Summary: molden ebuild uses error-prone syntax
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All All
: High normal
Assignee: Donnie Berkholz (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-04 19:54 UTC by Aron Griffis (RETIRED)
Modified: 2004-04-21 11:25 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
patch for molden-4.0.ebuild (molden-4.0.ebuild.patch,1.98 KB, patch)
2004-04-04 20:06 UTC, Aron Griffis (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Aron Griffis (RETIRED) gentoo-dev 2004-04-04 19:54:21 UTC
The molden ebuilds use error-prone syntax.  Here is a patch that prevents the need for sedding the makefile.  The problem with the previous code was that it assumed none of the variables would contain a colon, and there's no reason to do all that work.
Comment 1 Aron Griffis (RETIRED) gentoo-dev 2004-04-04 20:06:08 UTC
Created attachment 28714 [details, diff]
patch for molden-4.0.ebuild
Comment 2 Aron Griffis (RETIRED) gentoo-dev 2004-04-19 12:35:16 UTC
Full explanation of the patch:

1. Remove all the sedding.  There are a few problems with using sed like this: First it relies on future versions of the Makefile using the same formatting.  Second it uses ${CFLAGS} in a sed expression, which has the potential to screw up sed if anything in ${CFLAGS} is a sed meta-character.  Third, there was no checking (|| die) after the expressions, so you'd never know if sed were to stop working.  Fourth, it makes a lot more sense to move variable dependencies into src_compile() where they're actually used.

2. The "use alpha && append-flags -mieee" was something I found in the molden documentation or Makefile while reading through.  Since I work on alpha I know essentially what it does: protection against floating point exception on divide-by-zero.  Additionally it makes floating point math work correctly instead of just quickly.

3. Next, declare an array named args.  We use an array because it lets us have a list with items that include spaces, similar to using positional parameters ($1, $2, "$@", etc) but storing in a named location.

4. Assign a list to the array.  Here are the elements in the array:
     CC="${CC} ${CFLAGS}"
        This is a single element in the array, which contains spaces.
        It will be passed to make as an argument to override the Makefile's
        default CC

     ${FC:+FC="${FC}" LDR="${FC}"}
        Okay, this takes a little explanation.  :-)  The first thing to
        understand is this: ${VAR:+blah}.  This means: If VAR is empty then
        substitute nothing, otherwise substitute blah.  In this case VAR is
        FC and blah is FC="${FC}" LDR="${FC}".

        So the result?  If FC is set, then we'll add 2 elements to the array:
        FC="${FC}" and LDR="${FC}".  If FC is unset or empty, then we'll add
        nothing to the array.  Make sense?  This construct is particularly 
        useful when making conditional assignments to an array.

     ${FFLAGS:+FFLAGS="${FFLAGS}"}
        This is pretty much the same as FC above

     emake "${args[@]}"
        This passes the args array to emake on the cmdline, preserving spacing.
        It's exactly like doing "$@" but uses the args array instead of the
        positional parameters.  The result would look something like this:
           emake CC="gcc -mcpu=alphaev67 -O3 -pipe -mieee" \
              FFLAGS="-my -fflags"

     emake "${args[@]}" moldenogl
        This is the reason we stuffed everything into args instead of putting
        it all on the cmdline.  It's because we need to call emake more than
        once and we want to avoid duplicated information in the ebuild.

Hope this helps!
Comment 3 Donnie Berkholz (RETIRED) gentoo-dev 2004-04-21 11:25:54 UTC
Fixed. Thanks for inspiring me to read up on some advanced bash.