* [gentoo-dev] CUSTOM cflags replacement snippet
@ 2004-11-20 6:14 Chris White
2004-11-20 11:28 ` Eldad Zack
2004-11-22 18:27 ` Aron Griffis
0 siblings, 2 replies; 7+ messages in thread
From: Chris White @ 2004-11-20 6:14 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]
All,
I created this quick little function to recursively patch Makefiles
with custom CFLAGS.
custom_cflags() {
for directories in *
do
if [ -d $directories -a -e $directories/Makefile ]
then
cd $directories
for subdirectories in *
do
if [ -d $subdirectories -a -e $subdirectories/Makefile ]
then
custom_cflags
fi
done
sed -i \
-e "s:^CFLAGS.*:CFLAGS = ${CFLAGS}:" Makefile \
-e "s:^CXXFLAGS.*:CXXFLAGS = ${CXXFLAGS}:" Makefile \
|| die "Could not patch $directories/Makefile for custom CFLAGS"
cd ..
fi
done
}
Known issues:
if CFLAGS have something such as -Iblah or -D__BREAKS__WITHOUT__THIS__,
you're screwed.
if CFLAGS are added onto at some point (CFLAGS = $CFLAGS -mnewflag),
you're screwed.
It's not perfect, but it works for me in most cases.
Go ahead and flame, just thought I'd toss it here to make people's lives
2% easier :).
--
Chris White <chriswhite@gentoo.org>
------------------------
Sound | Video | Security
Mozilla | Haskell | Lang-misc
ChrisWhite @ irc.freenode.net
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-dev] CUSTOM cflags replacement snippet
2004-11-20 6:14 [gentoo-dev] CUSTOM cflags replacement snippet Chris White
@ 2004-11-20 11:28 ` Eldad Zack
2004-11-20 11:31 ` Eldad Zack
2004-11-22 18:27 ` Aron Griffis
1 sibling, 1 reply; 7+ messages in thread
From: Eldad Zack @ 2004-11-20 11:28 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 523 bytes --]
On Saturday 20 November 2004 08:14, Chris White wrote:
> I created this quick little function to recursively patch Makefiles
> with custom CFLAGS.
wouldn't it be simpler to do:
for dir in $(find -name "Makefile" .)
do
sed -i \
-e "s:^CFLAGS.*:CFLAGS = ${CFLAGS}:" \
-e "s:^CXXFLAGS.*:CXXFLAGS = ${CXXFLAGS}:" \
${dir} \
|| die "Could not patch $directories/Makefile for custom CFLAGS"
done
--
Eldad Zack <eldad@gentoo.org>
Key/Fingerprint at pgp.mit.edu, ID 0x96EA0A93
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-dev] CUSTOM cflags replacement snippet
2004-11-20 11:28 ` Eldad Zack
@ 2004-11-20 11:31 ` Eldad Zack
2004-11-20 11:49 ` [gentoo-dev] " Michael Sterrett -Mr. Bones.-
2004-11-20 15:18 ` [gentoo-dev] " Georgi Georgiev
0 siblings, 2 replies; 7+ messages in thread
From: Eldad Zack @ 2004-11-20 11:31 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 592 bytes --]
On Saturday 20 November 2004 13:28, Eldad Zack wrote:
> On Saturday 20 November 2004 08:14, Chris White wrote:
> > I created this quick little function to recursively patch Makefiles
> > with custom CFLAGS.
>
> wouldn't it be simpler to do:
What I really meant was:
for makefile in $(find -name "Makefile" .)
do
sed -i \
-e "s:^CFLAGS.*:CFLAGS = ${CFLAGS}:" \
-e "s:^CXXFLAGS.*:CXXFLAGS = ${CXXFLAGS}:" \
${makefile} \
|| die "Could not patch ${makefile} for custom CFLAGS"
done
--
Eldad Zack <eldad@gentoo.org>
Key/Fingerprint at pgp.mit.edu, ID 0x96EA0A93
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [gentoo-dev] Re: CUSTOM cflags replacement snippet
2004-11-20 11:31 ` Eldad Zack
@ 2004-11-20 11:49 ` Michael Sterrett -Mr. Bones.-
2004-11-20 15:18 ` [gentoo-dev] " Georgi Georgiev
1 sibling, 0 replies; 7+ messages in thread
From: Michael Sterrett -Mr. Bones.- @ 2004-11-20 11:49 UTC (permalink / raw
To: Eldad Zack; +Cc: gentoo-dev
On Sat, 20 Nov 2004, Eldad Zack wrote:
> for makefile in $(find -name "Makefile" .)
> do
> sed -i \
> -e "s:^CFLAGS.*:CFLAGS = ${CFLAGS}:" \
> -e "s:^CXXFLAGS.*:CXXFLAGS = ${CXXFLAGS}:" \
> ${makefile} \
> || die "Could not patch ${makefile} for custom CFLAGS"
> done
This stuff all fails if C*FLAGS has a ':' in it. There's a bug about
bad sed like this in bugzilla.
Also, sed takes a list. So never loop when you can just pass all the files
to sed. And don't forget about filenames with whitespace in the name...
Michael Sterrett
-Mr. Bones.-
mr_bones_@gentoo.org
--
gentoo-dev@gentoo.org mailing list
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-dev] CUSTOM cflags replacement snippet
2004-11-20 11:31 ` Eldad Zack
2004-11-20 11:49 ` [gentoo-dev] " Michael Sterrett -Mr. Bones.-
@ 2004-11-20 15:18 ` Georgi Georgiev
2004-11-22 5:30 ` Aron Griffis
1 sibling, 1 reply; 7+ messages in thread
From: Georgi Georgiev @ 2004-11-20 15:18 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 937 bytes --]
maillog: 20/11/2004-13:31:42(+0200): Eldad Zack types
> On Saturday 20 November 2004 13:28, Eldad Zack wrote:
> > On Saturday 20 November 2004 08:14, Chris White wrote:
> > > I created this quick little function to recursively patch Makefiles
> > > with custom CFLAGS.
> >
> > wouldn't it be simpler to do:
>
> What I really meant was:
>
> for makefile in $(find -name "Makefile" .)
> do
> sed -i \
> -e "s:^CFLAGS.*:CFLAGS = ${CFLAGS}:" \
> -e "s:^CXXFLAGS.*:CXXFLAGS = ${CXXFLAGS}:" \
> ${makefile} \
> || die "Could not patch ${makefile} for custom CFLAGS"
> done
Instead of replacing all Makefiles, couldn't one simply
make "CFLAGS=${CFLAGS}" "CXXFLAGS=${CXXFLAGS}"
?
--
) Georgi Georgiev ) RAM wasn't built in a day. )
( chutz@gg3.net ( (
) +81(90)6266-1163 ) )
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [gentoo-dev] CUSTOM cflags replacement snippet
2004-11-20 6:14 [gentoo-dev] CUSTOM cflags replacement snippet Chris White
2004-11-20 11:28 ` Eldad Zack
@ 2004-11-22 18:27 ` Aron Griffis
1 sibling, 0 replies; 7+ messages in thread
From: Aron Griffis @ 2004-11-22 18:27 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 1506 bytes --]
Chris,
Chris White wrote: [Sat Nov 20 2004, 01:14:46AM EST]
> Go ahead and flame, just thought I'd toss it here to make people's lives
> 2% easier :).
As was mentioned later in the thread, this is not the right approach.
Sedding the Makefiles is error-prone because you use a variable in the
RHS of the sed expression. Whether it works for you in your limited
tests is irrelevant. You shouldn't be willingly inserting error-prone
code into ebuilds.
There are two different ways you can deal with the CFLAGS issue
instead. Both are better than the sed method.
1. If the Makefiles are well-constructed and flags are appropriate
passed to sub-makes, then you can do:
emake CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}"
2. If the Makefiles do lazy assignment of variables instead of
immediate assignment, then you can simply append a new assignment
to the bottom of the ebuild. Here is the comparison of lazy vs.
immediately assignment:
# lazy assignment
CFLAGS = -g
# immediate assignment
CFLAGS := -g
Almost all Makefiles use lazy assignment. In that case you can use
a snippet like the following which will override all previous
assignments in the ebuild:
find "${S}" -name Makefile | while read mf; do
printf "\n\nCFLAGS = %s\nCXXFLAGS = %s\n" \
"${CFLAGS}" "${CXXFLAGS}" >> "$mf"
done
Regards,
Aron
--
Aron Griffis
Gentoo Linux Developer
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-11-22 18:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-20 6:14 [gentoo-dev] CUSTOM cflags replacement snippet Chris White
2004-11-20 11:28 ` Eldad Zack
2004-11-20 11:31 ` Eldad Zack
2004-11-20 11:49 ` [gentoo-dev] " Michael Sterrett -Mr. Bones.-
2004-11-20 15:18 ` [gentoo-dev] " Georgi Georgiev
2004-11-22 5:30 ` Aron Griffis
2004-11-22 18:27 ` Aron Griffis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox