0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Makeのwildcardの出力はソートされない

Posted at

Makefileのwildcard関数はパターンにマッチするファイル(あるいはディレクトリ)を列挙してくれます。
ファイル名をすべて書くのが面倒なときやmake時にしか実際のファイル名がわからない時に便利です。

以下はwildcard関数の使用例です。.txtで終わるファイル(あるいはディレクトリ)を取得しFILESに代入しています。

FILES=$(wildcard *.txt)

all:
	@echo $(FILES)

このwildcardの結果はソートされていると思っていたのですが、実はそうではないことがわかりました。
例えば次のように.txtで終わるファイルがいくつかあるとします。

$ ls *.txt
a.txt b.txt c.txt 

ここでmakeを実行すると

$ make
c.txt a.txt b.txt

となりました。出力結果をソートしたいときは、以下のようにsort関数をwildcard関数の結果に適用します。

FILES=$(sort $(wildcard *.txt))

all:
	@echo $(FILES)

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?