makefile을 만들고 싶습니다.

seoulbus의 이미지

초보입니다.

예를 들어, aaa.vvv라는 화일이 있을때,

aaa.vvv로 만들 수 있는 aaa.xxx, aaa.yyy, aaa.zzz 들을

aaa라는 화일의 이름을 인수로 받아서 위의 세 화일을 만들 수 있게 하려면 어떻게 하는지요?

예를 들면, bbb.vvv에서도 쓸 수 있게요.

혹은 다른 종류의 화일로도 가능한지 알고 싶습니다. 전천후 makefile을 만들 수 있는지요?

bushi의 이미지

[bushi@rose t]$ ls -l
합계 4
-rw-rw-r-- 1 bushi bushi 628  5월 25 21:15 Makefile
-rw-rw-r-- 1 bushi bushi   0  5월 25 17:42 aaa.vvv
-rw-rw-r-- 1 bushi bushi   0  5월 25 16:15 bbb.vvv
[bushi@rose t]$
[bushi@rose t]$ make
creating aaa.xxx ...
creating bbb.xxx ...
creating aaa.yyy ...
creating bbb.yyy ...
creating aaa.zzz ...
creating bbb.zzz ...
creating output ...
[bushi@rose t]$
[bushi@rose t]$ ls -l
합계 4
-rw-rw-r-- 1 bushi bushi 628  5월 25 21:15 Makefile
-rw-rw-r-- 1 bushi bushi   0  5월 25 17:42 aaa.vvv
-rw-rw-r-- 1 bushi bushi   0  5월 25 21:16 aaa.xxx
-rw-rw-r-- 1 bushi bushi   0  5월 25 21:16 aaa.yyy
-rw-rw-r-- 1 bushi bushi   0  5월 25 21:16 aaa.zzz
-rw-rw-r-- 1 bushi bushi   0  5월 25 16:15 bbb.vvv
-rw-rw-r-- 1 bushi bushi   0  5월 25 21:16 bbb.xxx
-rw-rw-r-- 1 bushi bushi   0  5월 25 21:16 bbb.yyy
-rw-rw-r-- 1 bushi bushi   0  5월 25 21:16 bbb.zzz
-rw-rw-r-- 1 bushi bushi   0  5월 25 21:16 output
[bushi@rose t]$
[bushi@rose t]$ cat Makefile
SOURCES = aaa.vvv bbb.vvv
 
TARGETS_xxx = $(shell echo $(SOURCES) | sed -e "s|.vvv|.xxx|g")
TARGETS_yyy = $(shell echo $(SOURCES) | sed -e "s|.vvv|.yyy|g")
TARGETS_zzz = $(shell echo $(SOURCES) | sed -e "s|.vvv|.zzz|g")
 
TARGETS = output
 
all: $(TARGETS)
        @echo "creating $^ ..."
        @touch $^
 
clean:
        @rm -vf $(TARGETS_xxx) $(TARGETS_yyy) $(TARGETS_zzz)
        @rm -vf $(TARGETS)
 
$(TARGETS_xxx): %.xxx: %.vvv
        @echo "creating $@ ..."
        @touch $@
 
$(TARGETS_yyy): %.yyy: %.vvv
        @echo "creating $@ ..."
        @touch $@
 
$(TARGETS_zzz): %.zzz: %.vvv
        @echo "creating $@ ..."
        @touch $@
 
$(TARGETS): $(TARGETS_xxx) $(TARGETS_yyy) $(TARGETS_zzz)
[bushi@rose t]$
seoulbus의 이미지

실제 제가 원하는 것을 제대로 쓰지 못했나 보네요.

위의 makefile에서도 SOURCE를 makefile 안에 썼는데

source이름을 인수로 받아서 각 확장자에 대해서 실행시킬 수 있는 것을 말한것인데,

가능한지 모르겠네요.

제가 쉘명령어나 정규식에 대한 지식이 없어서 넣고 쓰는 것을 잘 모르는데, 쉘 명령어로

makefile안의 source이름을 바꾸고 실행하는 것이 지금의 생각인데 아이디어만 있지

실제 구현에는 아직 머네요. 한수 가르침을 부탁드립니다.

jachin의 이미지

bash 환경을 쓰시는 것 같으니 살짝 가르쳐드릴께요.

bash 에서는 명령행에서 입력된 내용을 출력할 수 있습니다.

가령 이렇게 말이죠.

$ cat test.sh
echo $0 $1 $2
$ chmod 755 test.sh
$ ./test.sh
./test.sh
$ ./test.sh 1 2
./test.sh 1 2
$

그러나 makefile 내에서 컴파일 할 소스의 목록을 입력받는 것은 안 좋은 방법입니다.

makefile 은 프로젝트 단위의 소스 빌드 오더라고 볼 수 있는데,

외부의 인자로 컴파일 할 소스를 받는다는 것은 위험하지요.

예외 처리를 해주시거나 SOURCES=`ls *.xxx` 와 같은 얍삽한 방법을 쓰시는 것도 도움이 되실지도...

(`ls`에서 작은따옴표는 틸드(~) 표시가 있는 키의 작은 따옴표입니다.)
====
( - -)a 이제는 학생으로 가장한 백수가 아닌 진짜 백수가 되어야겠다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.