Originally posted by abs
i was going through the files on disk4 and while reading the line build script for mpg321, i found this line:
CFLAGS="-O2 -march=i486 -mcpu=i686" ./configure --prefix=/usr i486-slackware-linux
is there a functional difference between i486 and i686 in the march flag? after reading about checkinstall, i've been using it and it has a section on architecture. it was i386, i've changed it to i686 in the conf. shouldn't that make a difference when compiling?...
Yes there is a difference. The '-march=' flag tells the compiler to build specifically for that CPU architecture, making it unusable for earlier CPU architectures. The allowable flags for the gcc-3.2.x are:
There is a way to optimize the code when compiling for a specific CPU arch yet making it usable for earlier architectures by using the '-mcpu=' flag, instead. It uses the same CPU types listed above, but allows you to build packages for earlier CPU types while optimizing it mostly for the type specified by the '-mcpu=' flag. Specifying these flags can make a noticable difference in the speed of the binary.
When using the '-march=' flag you can specify an architecture that is earlier than the one you are currently using, due to backward compatibility of the CPU. You cannot use a binary built for a later arch type than what you currently are running without issues.
Both flags, '-march=' and 'mcpu=', can be used at the same time to optimize for a certain CPU arch, while making it compatible for earlier architectures. For example, I use '-march=i586' and '-mcpu=athlon' when building my packages. This means the binaries in the package are optimized for the AMD Athlon processor (since I currently have an Athlon 900), yet it will still run fine on any Pentium/AMD machine, but not any pre-Pentium machine. (First generation Pentium chips are i586 chips, such as P75 or P100.)
Originally posted by abs
wrt the code above, how is the configure script running? i mean, it starts with a variable assignment. unless it's understood (by the shell) that the assignment has ended and ./configure --... is the next line/command. in which case, how does it differentiate between diff commands in the same lines and their arguments?
Using several commands on the same line requires the use of a semi-colon ( ; ) to separate the commands. It doesn't matter if you have spaces before or after the semi-colon as the shell interpreter will ignore any white spaces (blank spaces, tabs, etc.). So the following examples are the same:
command1; command2; command3
command1 ; command2 ; command3
command1 ;command2; command3
You get the idea.
When defining a vaiable on the command line, that variable will be valid for a long as that shell is running. If you exit the shell and then start a new one, the variable data will be gone. Defining a variable doesn't count as a command on the command line, so there is no need to use a semi-colon after it if followed by other commands on the same line. But in order to not confuse it with a command's option, it is written before any commands on the same line. This also makes the variable available for the command being used, since it makes no sense to define the variable after issuing a command.
To make the data available for all shell sessions, you need to use the 'export' command, such as:
export CFLAGS="-O2 -march=i486 -mcpu=i686"
Now you can open and close any number of shells and the variable $CFLAGS will still carry those values until the next reboot. To make it available between reboots without having to type the 'export' command by hand, you can put the command in your startup script, such as ~/.bashrc, or to make it available to everyone place the command in /etc/profile.
When using the 'export' command on the same line with other commands, you will need to separate the commands with the semi-colon. Using your line above, if 'export' was used in defining the variable you would need to write it like this:
export CFLAGS="-O2 -march=i486 -mcpu=i686" ; ./configure --prefix=/usr i486-slackware-linux
Arguments (options) always follow the command given, with each option usually separated by a space. For your line above, only two options, or arguments, are given: --prefix=/usr
Here's a couple of links to follow, which may help make things clearer.
The first links lists the availabe flags used by GCC for the Intel x86 (and compatible) architecture. The second is recommended variables for compiling in Gentoo, but are usable for other distros as well. The variables are used by the 'make' command, if they are valid, and not empty, variables. The last link lists all the options currently supported by GCC.
NOTE: In the Gentoo link, 'CHOST' is the target machine being compiled on and is equivalent to the second './configure' option, i486-slackware-linux
Hope that helps
EDIT: Made some edits to clarify things a bit more.