커널 2.6 의 모듈 프로그래밍 시 Makefile 만들기?

kiwist의 이미지

보통 응용 프로그램을 만들고 빌드하기 위해서 사용하는 Makefile은

"Makefile"이나 "makefile" 이라는 이름으로 만들어도 잘 동작하는 것 같은데요,

커널 2.6 용 모듈 빌드에는 반드시 "Makefile"이라는 파일명을 사용해야하는지요?

이름을 다른 것으로 바꾸니까, 빌드가 되지 않는군요 -_-;

혹시 kbuild 시스템에 이를 가능하게 해주는 옵션 같은 건 없을까요?

익명 사용자의 이미지

make 는 기본적으로 Makefile을 그 입력 파일로 간주합니다.
다른 파일명을 지정하고 싶은 경우
make -f 파일명
이렇게 합니다.

kiwist의 이미지

Anonymous wrote:
make 는 기본적으로 Makefile을 그 입력 파일로 간주합니다.
다른 파일명을 지정하고 싶은 경우
make -f 파일명
이렇게 합니다.

아~ 그건 저도 알고 있는 부분이구요, 문제는 커널 2.6에서는 kbuild 시스템의 영향으로 일반적인 make에서 지원하는 매크로나 옵션등이 통하지 않는데 있죠 ^^; 그래서 제가 다른 방법이 있는지 질문 드린겁니다. ^^

익명 사용자의 이미지

제가 질문을 잘못 이해하고 있는건지...

$ make -f xxx
make -C /lib/modules/2.6.9-1.667/build M=/home/mach/Test/kernelModule modules
make[1]: Entering directory `/lib/modules/2.6.9-1.667/build'
  CC [M]  /home/mach/Test/kernelModule/hello-1.o
  Building modules, stage 2.
  MODPOST
  CC      /home/mach/Test/kernelModule/hello-1.mod.o
  LD [M]  /home/mach/Test/kernelModule/hello-1.ko
make[1]: Leaving directory `/lib/modules/2.6.9-1.667/build'
$ ls
hello-1.c  hello-1.ko  hello-1.mod.c  hello-1.mod.o  hello-1.o  Makefile  xxx
$

$ cat xxx
obj-m += hello-1.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
$

예제를 하나 해봤습니다.
http://www.tldp.org/LDP/lkmpg/2.6/html/x181.html

질문의 의도를 이해 못했나 보네요.

kiwist의 이미지

컥~ 이상하네요 ^^; 저는 똑같이 했는데, 안되는군요.
님께서 주신 그대로 해도 안되는데요 -_-;;;
제 시스템에서는 오직 Makefile이외에는 컴팔이 되질 않습니다.
그래서 make -f ... 도 안된다고 생각할 수 밖에.. ^^;
이상하군요...
암튼 커널 모듈도 make -f ... 로 컴파일이 되는게 정상이군요.
감사합니다. 뭐가 문젠지 찾아봐야겠습니다.

Quote:
질문의 의도를 이해 못했나 보네요.

아닙니다. 질문의 의도를 잘 이해하고 계셨습니다요 ^^
익명 사용자의 이미지

이상하군요 님께서 보여주신 내용을 그대로 따라해봤습니다. xxx 라는 메이크 파일을 하나 만들고
make -f xxx
라고 컴파일 해봤더니, 아래와 같은 에러메시지가 나오더군요

wikwon@world9:~/hello$ make -f xxx
make -C /lib/modules/2.6.10/build M=/home/wikwon/hello modules
make[1]: Entering directory `/usr/src/linux-source-2.6.10'
scripts/Makefile.build:13: /home/wikwon/hello/Makefile: 그런 파일이나 디렉토리가 없음
make[2]: *** 타겟 `/home/wikwon/hello/Makefile'를 만들 규칙이 없음.  멈춤.
make[1]: *** [_module_/home/wikwon/hello] 오류 2
make[1]: Leaving directory `/usr/src/linux-source-2.6.10'
make: *** [all] 오류 2
wikwon@world9:~/hello$

그런게 자세히 보니까, 님께서 작업하신 환경에는 아래와 같이 Makefile 이라는 파일이 하나 더 있군요? ^^;
$ make -f xxx
make -C /lib/modules/2.6.9-1.667/build M=/home/mach/Test/kernelModule modules
make[1]: Entering directory `/lib/modules/2.6.9-1.667/build'
  CC [M]  /home/mach/Test/kernelModule/hello-1.o
  Building modules, stage 2.
  MODPOST
  CC      /home/mach/Test/kernelModule/hello-1.mod.o
  LD [M]  /home/mach/Test/kernelModule/hello-1.ko
make[1]: Leaving directory `/lib/modules/2.6.9-1.667/build'
$ ls
hello-1.c  hello-1.ko  hello-1.mod.c  hello-1.mod.o  hello-1.o  Makefile  xxx
$

혹시 그걸 지우시고,
make -f xxx
라고 컴파일 해보셨나요? 혹시나 해서 다시 한번 말씀드리면, 제가 궁금한건 일반 응용은 소스 빌드를 위한 메이크파일이 "Makefile"이 아닐경우
make -f 파일명
와 같이 컴파일이 됩니다. 하지만, 커널 2.6에서 모듈을 컴파일 할 경우는 위와 같은 -f 옵션이 안먹는것 같습니다. 커널 2.6에서 모듈을 빌드할 때 메이크파일을 Makefile로 안쓰고, 다른 이름으로 쓸 수 있는 방법은 없을까요? ^^;
익명 사용자의 이미지

쿵~
음, 그렇군요.
1) 분석
그래서,
$ cd /lib/modules/`uname -r`/build/script
하고
Makefile.build
Makefile.clean
Makefile을 좀 봤더니,
$(obj)/Makefile 로 하드코딩 되어 있더군요.
그래서, 파일명이 Makefile로만 되는 것이었습니다.

2) 우격다짐으로 하기
1단계) /lib/modules/`uname -r`/build/script/Makefile.build를 손보기
가) include $(obj)/Makefile줄을 찾는다.
나) 다음과 같이 고친다.
ifndef MyMakefile # 혹시나, MyMakefile 변수를 선언안했을까봐...
MyMakfile := Makefile # 선언안되었다면, 그냥 Makefile로 하지모.
endif
include $(obj)/$(MyMakefile) # 변수로...
다) 파일내에서 $(obj)/Makefile을 찾아서, $(obj)/$(MyMakefile)로 변경한다.

2단계) /lib/modules/`uname -r`/build/script/Makefile.clean를 손보기
가) include $(obj)/Makefile줄을 찾는다.
나) 다음과 같이 고친다.
ifndef MyMakefile # 혹시나, MyMakefile 변수를 선언안했을까봐...
MyMakfile := Makefile # 선언안되었다면, 그냥 Makefile로 하지모.
endif
include $(obj)/$(MyMakefile) # 변수로...
다) 파일내에서 $(obj)/Makefile을 찾아서, $(obj)/$(MyMakefile)로 변경한다.
3단계) 이제 xxx 를 테스트 해본다.
$ cat xxx
obj-m += hello-1.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) MyMakefile=xxx modules

clean:
make -C /lib/modules/$(shell uname -r)/build MyMakefile=xxx M=$(PWD) clean
$ make -f xxx
$ make -f xxx clean
$
음... 우격다짐으로... 된다. --;

* 당연하게도 /lib/modules/$(shell uname -r)/build/script하의 파일은 root권한으로 수정해야 할 것이다.

kiwist의 이미지

컥~ 이런 제가 님의 시간을 뺏았군요 ^^; 죄송합니다.
결국은 커널 소스안의 빌드 스크립트를 수정하지 않으면 방법이 없군요.
방법을 알려주셔서 감사합니다.
좋은 하루 되세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.