LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How do I specify i686 arch/cpu when compiling? (https://www.linuxquestions.org/questions/slackware-14/how-do-i-specify-i686-arch-cpu-when-compiling-309310/)

Seiken 04-03-2005 02:48 PM

How do I specify i686 arch/cpu when compiling?
 
I see all the packages with "i686" in their names, and whenever I create one it always has "i386" instead (on a P4). How do I compile with i686 optimized code? I have done many searched on LQ and Google, but none of it (so far) has actually showed me how (instead just said it can be done).

gbonvehi 04-03-2005 02:56 PM

You've to specify that in the ./configure step (or directly in the gcc if you're building your own program or don't use a configure script).
Take a look here for flags: http://linuxreviews.org/howtos/compiling/
And quoting a configure script:
"
Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
"

Hope this helps.

keefaz 04-03-2005 03:13 PM

With some software, better is to unset CFLAGS and CXXFLAGS before configure and compile as
it set the optimization level for you and some other optimizing options, I used to export my CFLAGS
as this : -O2 -march=athlon-xp -pipe -fomit-frame-pointer but I saw a warning at configure time
that advised me to not use custom CFLAGS, so I unset them (export CFLAGS= ) and at compile time
I realized that mplayer uses -O4 as optimisation level ! (and it uses -pipe end -fomit-frame-pointer)

AxeZ 04-03-2005 03:14 PM

Something like this

CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"

Seiken 04-03-2005 03:16 PM

Okay... so would I be correct in assuming "./configure march=i686" is what I'm looking for in this case? According to that howto, mcpu (or mtune) will just default to whatever march is. Thanks again,

gbonvehi 04-03-2005 04:07 PM

No, something like ./configure CFLAGS="-march=i686" but be carefull becaue this will override program default flags...
Another way could be to edit the Makefile generated by configure adding the flag.

Seiken 04-03-2005 08:37 PM

That makes a lot of sense now. Is there a way to automatically set my system to compile with i686 every time? Or will the make file of each package always override that?

jong357 04-03-2005 09:24 PM

Yea, adding CFLAGS to ./configure will override which is bad for whatever your building. Setting it as global is what you want. Then it will just add your Cflags onto whatever the program wants to use. I use a ~/.bashrc and /etc/bashrc to define CFLAGS and any aliases that I want. That way, they are exported as soon as you open your terminal.

Code:

# Begin /etc/bashrc

# System wide aliases and functions.

alias ls='ls -A --color=always'

alias bt5='bittorrent --max_upload_rate 5'
alias bt10='bittorrent --max_upload_rate 10'
alias bt15='bittorrent --max_upload_rate 15'

alias shutdown='shutdown -h now'

alias start='/etc/rc.d/rc.pcmcia start'
alias stop='/etc/rc.d/rc.pcmcia stop'
alias restart='/etc/rc.d/rc.pcmcia restart'

# Lets set some good Slackware  environment variables:
export CFLAGS="-march=i486 -mtune=i686 -pipe -O2"
export CXXFLAGS="${CFLAGS}"
export MAKEOPTS="-j3"

# If we are using XTERM, tell it to keep walking
# We'll get it there eventually
if [ "$TERM" = "xterm" ]; then
  source /etc/profile
fi

# End /etc/bashrc

And for your home folder
Code:

# Begin ~/.bashrc
#
# Personal aliases and functions.

if [ -f "/etc/bashrc" ] ; then
        source /etc/bashrc
fi

# End ~/.bashrc


Seiken 04-04-2005 03:53 PM

jong357:

I have done exactly what your example shows (create /etc/bashrc and ~/.bashrc), but when I start a new session as my user, and "echo $CFLAGS", it outputs nothing. I thought maybe I had to make /etc/bashrc executable (even though none of the other rc files are +x in /etc), but that didn't help. Any idea what I'm not doing right?

Btw, if I login as my user and then "export CFLAGS="whatever" from the command line, and then echo $CFLAGS, it works. so I'm guessing my ~/.bashrc file isn't executing? (or is it even supposed to execute)

keefaz 04-04-2005 05:35 PM

Create a ~/.bash_profile with this content :
Code:

if [ -f ~/.bashrc ]; then
        source ~/.bashrc
fi

so the ~/.bashrc will be read at login if it exists

jong357> if you compile mplayer with your flags, it will be less optimized as
it uses default optimization level -O4 if $CFLAGS is not set

Seiken 04-04-2005 05:55 PM

that works, thanks :)

ps: why in jong356's /etc/bashrc does he export CXXFLAGS="${CFLAGS}" when export CXXFLAGS=$CFLAGS does the same thing? do the quotes and curly brackets do something special? thanks.

keefaz 04-04-2005 06:17 PM

In bash ${} is used for parameter expansion, more infos at :
http://itb.biologie.hu-berlin.de/~be...ware/bash.html

but in this case "${CFLAGS}" is the same thing as $CFLAGS because
there is no need to protect the variable name, I mean ${} is needed
for example:
Code:

s=1
echo "there is $svariable"
echo "there is ${s}variable"


Seiken 04-04-2005 06:34 PM

ah, ok.

one more question (sorry if you're getting tired of this thread). checkinstall is still naming the tgz packages with "i386" in them. should I take this to mean it is still only using i386, or is it just because I'm not changing the "architecture" field of the description before checkinstall finishes (ie: it IS compiled with i686, just not named that way)

cathectic 04-04-2005 06:58 PM

It's just that you're not changing the field. You can either change it each time, or edit checkinstall and change the default architecture (for example, I have it set to i486).

jong357 04-06-2005 12:00 AM

Quote:

Originally posted by keefaz


jong357> if you compile mplayer with your flags, it will be less optimized as
it uses default optimization level -O4 if $CFLAGS is not set

I know... ;) I just compiled mplayer and it's optional 20 deps last month.. I think -O4 is too agressive. I purposefully compile EVERYTHING with -02.. Mplayer runs fast and clean with those opts....

I find that strange that bash wasn't reading ~/.bashrc... Altho, now that I look, I have a long forgotten .bash_profile that does the same thing... I was under the impression that I only needed a .bash_profile if I wanted to stay in init3 and still have my /etc/bashrc sourced... That was the conclusion I came to long ago anyway. Maybe I'm wrong... ;)


All times are GMT -5. The time now is 03:16 PM.