Linux

How to compile the linux kernel on mac ox x

황승곤 2012. 4. 28. 14:13

mac에서 리눅스 커널 컴파일을 하는 방법을 적는다. (나중에 까먹으면 봐야지, 근데 왜 내가 이런 삽질을??)


mac에서 리눅스 커널 컴파일을 하는 방법.

1. mac port를 설치 한다. ( google 에서 검색하면 나옴)

2. 다음과 같이 패키지를 검색 후 설치 한다.

   1)port list | grep arm-none-eabi-

   위와 같이 명령어를 내리면 아래와 같이 결과가 나온다.

  arm-none-eabi-binutils         @2.21.53.0.1    cross/arm-none-eabi-binutils

 arm-none-eabi-gcc              @4.6.2          cross/arm-none-eabi-gcc

 arm-none-eabi-gdb              @7.3            cross/arm-none-eabi-gdb

  뒤에 버전은 다를 수 있다. 난 위에 두개만 설치

  2) sudo port install arm-none-eabi-binutils arm-none-eabi-gcc

  3) sudo port install libelf

      elf관련 에러를 내뿜기 때문에 libelf를 만든다.


3. /usr/include/elf.h 파일을 만든다.

  어떻게 만드냐면, libelf를 설치하게 되면 /opt/local에 설치되게 되어 있는데 여기서 gelf.h를 검색한다.

  1) find . -name "gelf.h" -print

  하게 되면 /opt/local/include/libelf/gelf.h  라는 결과를 내뿜는다.

  2) sudo vim /usr/include/elf.h

  위와 같이 해서 elf.h 파일을 만들고 아래와 같이 기술한다.

  #include <gelf.h>


#define R_386_NONE        0

#define R_386_32          1

#define R_386_PC32        2

#define R_ARM_NONE        0

#define R_ARM_PC24        1

#define R_ARM_ABS32       2

#define R_MIPS_NONE       0

#define R_MIPS_16         1

#define R_MIPS_32         2

#define R_MIPS_REL32      3

#define R_MIPS_26         4

#define R_MIPS_HI16       5

#define R_MIPS_LO16       6


4. 이제는 컴파일이다.

아래와 같이 내리면된다.

make ARCH=arm CROSS_COMPILE=arm-none-eabi- HOSTCFLAGS="-I/opt/local/include/libelf -I." -j32

위에가 안되면,

make ARCH=arm CROSS_COMPILE=arm-none-eabi- HOSTCFLAGS="-I/opt/local/include -I/opt/local/include/libelf -I." -j32


그럼 무리 없이 컴파일이 되고 결과인 Image가 나온다. 굿~~~~~~~~~~