GNU Cross Compiler 編譯程序

寫了一個 Makefile,可以半自動的編譯 GNU Cross Compiler
做個記錄,怕以後忘記

#TARGET      = arm-elf
#TARGET      = mips-elf
TARGET      = sparc-elf

PKG_DIR     = $(CURDIR)/PKG
SRC_DIR     = $(CURDIR)/SRC
BUILD_DIR   = $(CURDIR)/BUILD-$(TARGET)
TARGET_DIR  = /srv/xfile/compiler/$(TARGET)-4.7.0

BINUTILS_VER = binutils-2.22
GCC_VER      = gcc-4.7.0
MPC_VER      = mpc-0.9
MPFR_VER     = mpfr-3.1.0
GMP_VER      = gmp-5.0.4
NEWLIB_VER   = newlib-1.20.0
GDB_VER      = gdb-7.3.1
INSIGHT_VER  = insight-6.8-1

GCC_PACKAGE        = $(PKG_DIR)/gcc/$(GCC_VER).tar.bz2
GCC_SRC_DIR        = $(SRC_DIR)/$(GCC_VER)
GCC_BUILD_DIR      = $(BUILD_DIR)/$(GCC_VER)

GMP_PACKAGE        = $(PKG_DIR)/gmp/$(GMP_VER).tar.bz2
GMP_SRC_DIR        = $(SRC_DIR)/$(GMP_VER)
GMP_BUILD_DIR      = $(BUILD_DIR)/$(GMP_VER)

MPFR_PACKAGE       = $(PKG_DIR)/mpfr/$(MPFR_VER).tar.bz2
MPFR_SRC_DIR        = $(SRC_DIR)/$(MPFR_VER)
MPFR_BUILD_DIR      = $(BUILD_DIR)/$(MPFR_VER)

MPC_PACKAGE        = $(PKG_DIR)/mpc/$(MPC_VER).tar.gz
MPC_SRC_DIR        = $(SRC_DIR)/$(MPC_VER)
MPC_BUILD_DIR      = $(BUILD_DIR)/$(MPC_VER)

BINUTILS_PACKAGE   = $(PKG_DIR)/binutils/$(BINUTILS_VER).tar.bz2
BINUTILS_SRC_DIR   = $(SRC_DIR)/$(BINUTILS_VER)
BINUTILS_BUILD_DIR = $(BUILD_DIR)/$(BINUTILS_VER)

GDB_PACKAGE        = $(PKG_DIR)/gdb/$(GDB_VER).tar.gz
GDB_SRC_DIR        = $(SRC_DIR)/$(GDB_VER)
GDB_BUILD_DIR      = $(BUILD_DIR)/$(GDB_VER)

NEWLIB_PACKAGE     = $(PKG_DIR)/newlib/$(NEWLIB_VER).tar.gz
NEWLIB_SRC_DIR     = $(SRC_DIR)/$(NEWLIB_VER)
NEWLIB_BUILD_DIR   = $(BUILD_DIR)/$(NEWLIB_VER)

INSIGHT_PACKAGE    = $(PKG_DIR)/insight/$(INSIGHT_VER).tar.bz2
INSIGHT_SRC_DIR    = $(SRC_DIR)/$(INSIGHT_VER)
INSIGHT_BUILD_DIR  = $(BUILD_DIR)/$(INSIGHT_VER)

CONFIG_FLAGS       = --target=$(TARGET) 
                     --prefix=$(TARGET_DIR)
note:
        @echo ----------------------------------------
        @echo make binutils    # Build binutils
        @echo make gcc-p0      # Build GMP, MPFR, MPC
        @echo make gcc-p1      # Build GCC Pass-1
        @echo make newlib      # Build newlib
        @echo make gcc-p2      # Build GCC Pass-2
        @echo make insight     # Build insight
        @echo ----------------------------------------

all: binutils gcc-p0 gcc-p1 newlib gcc-p2 insight

dir : src_dir

# Source Decompress

src_dir: $(BINUTILS_SRC_DIR) $(NEWLIB_SRC_DIR) $(GCC_SRC_DIR) $(GDB_SRC_DIR) $(INSIGHT_SRC_DIR) $(GMP_SRC_DIR) $(MPFR_SRC_DIR) $(MPC_SRC_DIR)

build_dir: $(BINUTILS_BUILD_DIR) $(NEWLIB_BUILD_DIR) $(GCC_BUILD_DIR) $(GDB_BUILD_DIR)

# ------------- BINUTIL ----------------

BINUTILS_CONF = $(CONFIG_FLAGS) --disable-nls

binutils: $(BINUTILS_BUILD_DIR)
        @echo "****** Build $(BINUTILS_VER) ***********"
        (cd $(BINUTILS_BUILD_DIR); $(BINUTILS_SRC_DIR)/configure $(BINUTILS_CONF);)
        (cd $(BINUTILS_BUILD_DIR); make all install)

$(BINUTILS_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(BINUTILS_PACKAGE) ***********"
        -@mkdir $(BINUTILS_SRC_DIR)
        (cd $(SRC_DIR); tar -jxvf $(BINUTILS_PACKAGE))

$(BINUTILS_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(BINUTILS_BUILD_DIR) ***********"
        -@mkdir $(BINUTILS_BUILD_DIR)

# ------------- NEWLIB ----------------

NEWLIB_CONF  = $(CONFIG_FLAGS) --disable-nls

newlib: $(NEWLIB_BUILD_DIR)
        @echo "****** Build $(NEWLIB_VER) ***********"
        (set path = $(TARGET_DIR)/bin;cd $(NEWLIB_BUILD_DIR);$(NEWLIB_SRC_DIR)/configure $(NEWLIB_CONF);)
        (cd $(NEWLIB_BUILD_DIR); make all install)

$(NEWLIB_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(NEWLIB_PACKAGE) ***********"
        (cd $(SRC_DIR); tar -zxvf $(NEWLIB_PACKAGE))

$(NEWLIB_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(NEWLIB_BUILD_DIR) ***********"
        -@mkdir $(NEWLIB_BUILD_DIR)

# ------------- GDB ----------------

GDB_CONF = $(CONFIG_FLAGS) --disable-nls

gdb: $(GDB_BUILD_DIR)
        @echo "****** Build $(GDB_VER) ***********"
        (cd $(GDB_BUILD_DIR); $(GDB_SRC_DIR)/configure $(GDB_CONF);)
        (cd $(GDB_BUILD_DIR); make all install))

$(GDB_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(GDB_PACKAGE) ***********"
        (cd $(SRC_DIR); tar -zxvf $(GDB_PACKAGE))

$(GDB_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(GDB_BUILD_DIR) ***********"
        -@mkdir $(GDB_BUILD_DIR)

# ------------- INSIGHT ----------------
INSIGHT_CONF = $(CONFIG_FLAGS) --disable-nls --disable-werror

insight: $(INSIGHT_BUILD_DIR)
        @echo "****** Build $(INSIGHT_VER) ***********"
        (cd $(INSIGHT_BUILD_DIR); $(INSIGHT_SRC_DIR)/configure $(INSIGHT_CONF);)
        (cd $(INSIGHT_BUILD_DIR); make all install)

$(INSIGHT_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(INSIGHT_PACKAGE) ***********"
        (cd $(SRC_DIR); tar -jxvf $(INSIGHT_PACKAGE))

$(INSIGHT_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(INSIGHT_BUILD_DIR) ***********"
        -@mkdir $(INSIGHT_BUILD_DIR)

# ------------- gcc-p0 ----------------

gcc-p0: gmp mpfr mpc

# ------------- GMP ----------------

GMP_CONF = --prefix=$(TARGET_DIR)

gmp: $(GMP_BUILD_DIR)
        @echo "****** Build $(GMP_VER) ***********"
        (cd $(GMP_BUILD_DIR); $(GMP_SRC_DIR)/configure $(GMP_CONF);)
        (cd $(GMP_BUILD_DIR); make all install)

$(GMP_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(INSIGHT_PACKAGE) ***********"
        (cd $(SRC_DIR); tar -jxvf $(GMP_PACKAGE))

$(GMP_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(GMP_BUILD_DIR) ***********"
        -@mkdir $(GMP_BUILD_DIR)

# ------------- MPFR ----------------

MPFR_CONF = --prefix=$(TARGET_DIR) 
            --with-gmp=$(TARGET_DIR)

mpfr: $(MPFR_BUILD_DIR)
        @echo "****** Build $(MPFR_VER) ***********"
        (cd $(MPFR_BUILD_DIR); $(MPFR_SRC_DIR)/configure $(MPFR_CONF);)
        (cd $(MPFR_BUILD_DIR); make all install)

$(MPFR_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(MPFR_PACKAGE) ***********"
        (cd $(SRC_DIR); tar -jxvf $(MPFR_PACKAGE))

$(MPFR_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(MPFR_BUILD_DIR) ***********"
        -@mkdir $(MPFR_BUILD_DIR)

# ------------- MPC ----------------

MPC_CONF = --prefix=$(TARGET_DIR)   
           --with-gmp=$(TARGET_DIR) 
           --with-mpfr=$(TARGET_DIR)

mpc: $(MPC_BUILD_DIR)
        @echo "****** Build $(MPC_VER) ***********"
        (cd $(MPC_BUILD_DIR); $(MPC_SRC_DIR)/configure $(MPC_CONF);)
        (cd $(MPC_BUILD_DIR); make all install)

$(MPC_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(MPC_PACKAGE) ***********"
        (cd $(SRC_DIR); tar -zxvf $(MPC_PACKAGE))

$(MPC_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(MPC_BUILD_DIR) ***********"
        -@mkdir $(MPC_BUILD_DIR)

# ------------- GCC ----------------
GCC_CONF = $(CONFIG_FLAGS)          
           --enable-interwork       
           --disable-multilib       
           --disable-nls            
           --disable-shared         
           --disable-threads        
           --disable-decimal-float  
           --disable-libmudflap     
           --disable-libssp         
           --disable-libgomp        
           --disable-libquadmath    
           --without-ppl            
           --without-cloog          
           --enable-languages=c,c++ 
           --with-newlib            
           --with-headers=$(NEWLIB_SRC_DIR)/newlib/libc/include 
           --with-gmp=$(TARGET_DIR)  
           --with-mpfr=$(TARGET_DIR) 
           --with-mpc=$(TARGET_DIR) 
           --enable-obsolete        

#           --with-mpfr-include=$(GCC_SRC_DIR)/mpfr/src 
#           --with-mpfr-lib=$(GCC_SRC_DIR)/mpfr/src/.lib

gcc-p1: $(GCC_BUILD_DIR)
        @echo "****** Build $(GCC_VER) Phase-1  ***********"
        (cd $(GCC_BUILD_DIR); $(GCC_SRC_DIR)/configure $(GCC_CONF);)
        (cd $(GCC_BUILD_DIR); make all-gcc install-gcc)

gcc-p2: 
        @echo "****** Build $(GCC_VER) Phase-2  ***********"
        (cd $(GCC_BUILD_DIR); make all install)

$(GCC_SRC_DIR): $(SRC_DIR)
        @echo "****** Decompress $(GCC_PACKAGE) ***********"
        (cd $(SRC_DIR); tar -jxvf $(GCC_PACKAGE))

$(GCC_BUILD_DIR): $(BUILD_DIR)
        @echo "****** create directory $(GCC_BUILD_DIR) ***********"
        -@mkdir $(GCC_BUILD_DIR)

# ------------- misc ----------------

$(SRC_DIR):
        @echo "****** create directory $(SRC_DIR) ***********"
        -@mkdir $(SRC_DIR)

$(BUILD_DIR):
        @echo "****** create directory $(BUILD_DIR) ***********"
        -@mkdir $(BUILD_DIR)

$(PKG_DIR):
        @echo ERROR! No $(GNU_DIR) found!
        exit

clean: clean-build clean-src

clean-src:
        @rm -rf $(SRC_DIR)

clean-build:
        @rm -rf BUILD-*

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *