免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1510 | 回复: 0
打印 上一主题 下一主题

gcc & configure & make [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-07-04 11:12 |只看该作者 |倒序浏览

                make LDFLAGS="-static"                  #静态编译
./configure --disable-nls               #禁止对国际化支持
gcc优化及特定编译安装示例:
#!/bin/sh
CFLAGS="-O2 -mcpu=i386 -march=i386 -pipe -fomit-frame-pointer"
CXXFLAGS="-O2 -mcpu=i386 -march=i386 -pipe -fomit-frame-pointer"
PKG_ROOT=/mnt
PKG_DIR=pkgname
export CFLAGS CXXFLAGS
./configure --prefix=/$PKG_DIR --sysconfdir=/$PKG_DIR/etc
make
make DESTDIR=$PKG_ROOT install
# end
上面编译安装脚本如果在最后一行不添加蓝色部分,
则软件最后会安装于/pkgname目录下,
配置文件会安装于/pkgname/etc目录下;
但在make install中添加DESTDIR参数,则会以此参数对应变量作为安装时根目录;
即软件会安装于/mnt/pkgname目录下,
配置文件会安装于/mnt/pkgname/etc目录下。
GCC在线文档:
http://gcc.gnu.org/onlinedocs/
GCC编译选项及优化:
http://www.linuxsir.org/bbs/showthread.php?t=222670
Compiler-optimization:http://www.linuxfromscratch.org/hints/downloads/files/optimization.txt
AUTHOR:                Jim Gifford
                Originally by Gerard Beekmans
                Originally by Thomas -Balu-Walter
                Originally by Eric Olinger  optimization2.txt
DATE:                2003-10-30
LICENSE:        GNU Free Documentation License Version 1.2
SYNOPSIS:        Compiler-optimization
DESCRIPTION:        This hint will act as a guide on how-to or not-to use
                compiler optimization routines.
PREREQUISITES:        None
HINT:
The origin of this text is the 2.4.3-version of the book - Chapter 6. I
modified it a little to create this hint.
Most programs and libraries by default are compiled with optimizing level 2
(gcc options -g and -O2) and are compiled for a specific CPU. On Intel
platforms software is compiled for i386 processors by default. If you don't
wish to run software on other machines other than your own, you might want to
change the default compiler options so that they will be compiled with a higher
optimization level, and generate code for your specific architecture.
There are a few ways to change the default compiler options. One way is to edit
every Makefile file you can find in a package, look for the CFLAGS and CXXFLAGS
variables (a well designed package uses the CFLAGS variable to define gcc
compiler options and CXXFLAGS to define g++ compiler options) and change their
values. Packages like binutils, gcc, glibc and others have a lot of Makefile
files in a lot of subdirectories so this would take a lot of time to do.
Instead there's an easier way to do things: create the CFLAGS and CXXFLAGS
environment variables. Most configure scripts read the CFLAGS and CXXFLAGS
variables and use them in the Makefile files. A few packages don't follow this
convention and those package require manual editing.
To set those variables you can do the following commands in bash (or in your
.bashrc if you want them to be there all the time):
    export CFLAGS="-O3 -march=" &&
    CXXFLAGS=$CFLAGS
This is a minimal set of optimizations that ensures it works on almost all
platforms. The option march will compile the binaries with specific
instructions for that CPU you have specified. This means you can't copy this
binary to a lower class CPU and execute it. It will either work very unreliable
or not at all (it will give errors like "Illegal Instruction, core dumped").
You'll have to read the GCC Info page to find more possible optimization flags.
In the above environment variable you have to replace  with the
appropriate CPU identifiers such as i586, i686, powerpc and others. I suggest
to have a look at the gcc-manual at http://gcc.gnu.org/onlinedocs/gcc_toc.html
"Hardware Models and Configurations".
/*
* Ed. note
* "Reboant" dropped a note about how using -Os (optimize for size) showed
* incredibly good results. So if you want is small binary size rather than fast
* execution time, you might want to take a look at this.
*/
Please keep in mind that if you find that a package doesn't compile and gives
errors like "segmentation fault, core dumped" it's most likely got to do with
these compiler optimizations. Try lowering the optimizing level by changing -O3
to -O2. If that doesn't work try -O or leave it out all together.  Also try
changing the -march variable. Compilers are very sensitive to certain hardware
too. Bad memory can cause compilation problems when a high level of
optimization is used, like the -O3 setting. The fact that I don't have any
problems compiling everything with -O3 doesn't mean you won't have any problems
either. Another problem can be the Binutils version that's installed on your
system which often causes compilation problems in Glibc (most noticable in
RedHat because RedHat often uses beta software which aren't always very stable.
"RedHat likes living on the bleeding edge, but leaves the bleeding up to you"
(quoted from somebody on the lfs-discuss mailinglist).
DEFINITIONS FOR FLAGS:
For more information on compiler optimization flags see the GCC Command
s page in the Online GCC 3.3.1 docs at:
http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Optimize-Options.html#Optimize%20Options
http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/i386-and-x86-64-Options.html#i386%20and%20x86-64%20Options
-s
        A linker option that remove all symbol table and relocation
        information from the binary.
-O3
        This flag sets the optimizing level for the binary.
                3        Highest level, machine specific code is generated.
                           Auto-magically adds the -finline-functions and
                        -frename-registers flags.
                2       Most make files have this set up as Default, performs all  
                        supported optimizations that do not involve a space-speed
                        tradeoff. Adds the -fforce-mem flag auto-magically.
                1          Minimal optimizations are performed. Default for the compiler,
                           if nothing is given.
                0       Don't optimize.
                s       Same as O2 but does additional optimizations for size.
-fomit-frame-pointer
        Tells the compiler not to keep the frame pointer in
        a register for functions that don't need one.  This
        avoids the instructions to save, set up and restore
        frame pointers; it also makes an extra register available
        in many functions. It also makes debugging impossible
        on some machines.
-march=pentium3
        Defines the instructions set to use when compiling. -mpcu is implied
        be the same as -march when only -march is used.
                i386                    Intel 386 Prcoessor
                i486                    Intel/AMD 486 Processor
                pentium                 Intel Pentium Processor
                pentiumpro              Intel Pentium Pro Processor
                pentium2                Intel PentiumII/Celeron Processor
                pentium3                Intel PentiumIII/Celeron Processor
                pentium4                Intel Pentium 4/Celeron Processor
                k6                      AMD K6 Processor
                k6-2                        AMD K6-2 Processor
                K6-3                        AMD K6-3 Processor
                athlon                  AMD Athlon/Duron Processor
                athlon-tbird                AMD Athlon Thunderbird Processor
                athlon-4                AMD Athlon Version 4 Processor
                athlon-xp                AMD Athlon XP Processor
                athlon-mp                AMD Athlon MP Processor
                winchip-c6                Winchip C6 Processor
                winchip2                Winchip 2 Processor
                c3                        VIA C3 Cyrix Processor
-mmmx
-msse
-msse2
-m3dnow
        These switches enable or disable the use of built-in functions
        that allow direct access to the MMX, SSE and 3Dnow extensions
        of the instruction set.
       
OPTIMIZATION LINKS:

Safe flags to use for gentoo-1.4  
http://www.freehackers.org/gentoo/gccflags/flag_gcc3.html
Securing & Optimizing Linux: The Ultimate Solution v2.0
http://www.openna.com/products/books/sol/solus.php
PERSON EXPERIENCE:
I have tried using all optimization levels, but to my disappointment, results varied
from package to package. Using -O(any number) using GCC 3.3.1 can give unpredictable
responses.
Some of those unpredicatable responses can be seen with the following bugs sent to GCC.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12590
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10655
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8440
VERSION:        1.2
CHANGELOG:        1.2 Fixed Typos
                1.1 Fixed Typos and Cut-n-Paste Errors
                1.0 Adopted by Jim Gifford
New Version of this document can be viewed from http://cvs.jg555.com/viewcvs.cgi/lfs-hints
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21352/showart_136171.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP