LoginSignup
6
6

More than 5 years have passed since last update.

makefile > あるフォルダの.cファイル名を取得 > wildcard使用

Last updated at Posted at 2015-02-04

makefileにおいて、あるフォルダ内の.cファイルが複数ある場合、以下のようにwildcardを用いてSRCSという変数に取得することができる。

FLD = /tmp/folder1
SRCS = $(wildcard $(FLD)/*.c)

.PHONY: all
all:
    @echo "$(SRCS)"

上記をMakefile.allcppとして保存し、最後の行の@の前タブに変更して

$ make -f Makefile.allcpp

とすると以下のように表示される (a.c, b.c, c.cがある場合)。

/tmp/folder1/a.c /tmp/folder1/b.c /tmp/folder1/c.c

ライブラリを使ったビルド用のMakefileなどにおいて使うと便利かもしれない。

その他の有用な関数については、Makefileの関数がよくまとまっている

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6