makefile 작성시 궁금한점..

lee16abc의 이미지

안녕하세요.

이번에 프로젝트를 쉽게 관리 하려구 makefile 을 작성하였는데요.

매크로를 정의해서, 입력된 매크로에 따라서 폴더 나뉘고 / 라이브러리 파일도 적절하게 조절하고 있습니다.

헌데, 궁금한점이..

제가 프로젝트에 따라서 , make 커맨드 입력시 정의해줘야 할 매크로가 2개 또는 3개 정도로 나뉘는데요.

매크로 디폴트 값은 주고싶지 않아서, 만약 정의해줘야할 매크로 갯수만큼 입력 되지 않으면

이후 컴파일 작업을 수행하지 않고, 에러 메세지를 띄우고 싶습니다.

저는 그냥 매크로 걸러내는 IF 문에서 ELSE 문에 Echo 문으로 추가하면 될줄 알았는데,

Echo 문을 쓰니까 자꾸 에러가 나는거 같습니다.

간단하게 아래와 같이 작성했는데 , 무슨 문제라도 있는지 조언좀 부탁드립니다.

ifeq ($(MODE),D)
CFLAG=-g3
else ifeq ($(MODE),R)
CFLAG=-O
else
echo "[Error] Usage : make all MODE=D(R)"
endif

간단하게 MODE 에 "D" 나 "R" 이 입력되지 않을경우( D,R 외에 다른 문자가 입력되거나, 아예 입력되지 않을경우도..) else 문에

걸려서 에러를 띄우고 싶어서 위와같이 작성했는데 잘 되질 않네요.

게다가, 만약에 된다해도..에러도 띄우고 이후에 컴파일 작업도 진행될거 같은데..

원하는 매크로가 입력되지 않았을시 makefile 안에서 break 를 걸게 할수는 없을까요?

ktd2004의 이미지

보통은 이런식으로 합니다.
대강 원리만 이해하시면 될 것 같아서 테스트해보진 않았습니다.

ifeq ($(MODE),D)
CFLAG=-g3
else ifeq ($(MODE),R)
CFLAG=-O
else
ERROR=y
endif
 
ifeq ($(ERROR),y)
 
all :
    echo "[Error] Usage : make all MODE=D(R)"
 
else
 
all :
    정상적인 동작...
 
endif

에러가 발생하는 이유는 타켓이 없이 echo 명령어가 존재하기 때문입니다.
위에 제가 예로 든 것처럼, 디폴트 타켓인 all을 정상적인 경우와 에러인 경우로 나누어서
처리하면 됩니다.

커널 소스의 Makefile을 분석해보시면 도움이 될 듯 합니다.

라키시스의 이미지

GNU make 에 이런 것이 있습니다 : GNU online documentation 에서 인용합니다 :-)

Quote:
8.12 Functions That Control Make

These functions control the way make runs. Generally, they are used to provide information to the user of the makefile or to cause make to stop if some sort of environmental error is detected.

$(error text...)
Generates a fatal error where the message is text. Note that the error is generated whenever this function is evaluated. So, if you put it inside a command script or on the right side of a recursive variable assignment, it won't be evaluated until later. The text will be expanded before the error is generated.

For example,

              ifdef ERROR1
              $(error error is $(ERROR1))
              endif

will generate a fatal error during the read of the makefile if the make variable ERROR1 is defined. Or,

              ERR = $(error found an error!)
 
              .PHONY: err
              err: ; $(ERR)

will generate a fatal error while make is running, if the err target is invoked.

$(warning text...)
This function works similarly to the error function, above, except that make doesn't exit. Instead, text is expanded and the resulting message is displayed, but processing of the makefile continues.

The result of the expansion of this function is the empty string.

$(info text...)
This function does nothing more than print its (expanded) argument(s) to standard output. No makefile name or line number is added. The result of the expansion of this function is the empty string.

라키시스의 이미지

$(error function을 만나면 make는 거기서 실행을 중단... 했던 걸로 기억됩니다 ( '-');;;

댓글 달기

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 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <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].
  • 사용할 수 있는 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>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <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].
  • You can use Textile markup to format text.
  • 사용할 수 있는 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>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <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].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 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>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.