LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   CFLAGS to compile kernel (https://www.linuxquestions.org/questions/linux-software-2/cflags-to-compile-kernel-291657/)

frzburn 02-17-2005 09:25 PM

CFLAGS to compile kernel
 
HI, I rebuild my system on Slackware 10 yesterday, and installed the 2.4.29 kernel from CURRENT tree. I recompile the kernel to suits my needs, and configure my system, etc, etc...
So, I put custom CFLAGS at the end of my /etc/profile to optimize everithing I compile. But, I noticed that those CFLAGS weren't used when compiling the kernel. I looked in the Makefile of ther kernel source, and I found that CFLAGS where defined, ignoring those I put in /etc/profile.

So, my question is: Is there a problem using my custom CFLAGS + those in the kernel Makefile, or should I let the defaults CFLAGS? (Because compiling the kernel with different CFLAGS may cause some errors...)

My CFLAGS in /etc/profile are:
CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"

and in the kernel Makefile:
CFLAGS := -D__KERNEL__ -I$(HPATH) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common

So, what do you think about it?

frzburn 02-17-2005 10:22 PM

OK, couldn't wait any longer, so I just tried it ;)
So, here's what I have done:
in /usr/src/linux/Makefile, I added '-march=athlon-xp' and changed '-02' for '-03' to HOSTCFLAGS so it looks like:
Code:

HOSTCFLAGS        = -Wall -Wstrict-prototypes -march=athlon-xp -pipe -O3 -fomit-frame-pointer
I did the same changes to CFLAGS, so I now looks like:
Code:

CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -march=athlon-xp -Wno-trigraphs -O3 \
          -fno-strict-aliasing -fno-common

Now, the compiled kernel works perfectly, but I didn't check the speed gain (if there is any).
The resulting bzImage is bigger (for the same config file) than the old one, as expected.

That's all. Sorry for asking a question I could answer myself!!
But maybe it'll be useful to someone...

__J 02-18-2005 05:30 AM

might have to export it. if you do it on the command line:

export CFLAGS=" -march-athlon-xp etc..."

it should show up ( I always leave the kernel alone.... not sure what a -O3 will do ( keep in mind with -O3 it inherits all of -O1 and -O2 levels plus some extra, I'd have to look it up but -fomit-frame-pointer might already be defined in -O3)). you have to leave the rest of the CFLAGS in the makefile intact.

frzburn 02-18-2005 08:21 AM

I did export my CLFAGS. Here's my /etc/profile section where I set them:
Code:

# Setting compile flags for optimization
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="$CFLAGS"
export CHOST CFLAGS CXXFLAGS

But still, when I compiled the kernel it just ignored it.
Whatever, I changed them in the Makefile, and everything's working fine now... :)

denning 03-05-2005 05:42 AM

wicked!! That is cool. I am trying to speed things up by compiling stuff with CFLAGS instead of using binary packages. Now I can even optimize the kernel.

Did you notice any speed improvements?


All times are GMT -5. The time now is 02:18 PM.