1
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.

Makefileでディレクトリ生成する覚書

Posted at

コンパイル実行時にオブジェクトディレクトリやバイナリディレクトリがなかったときに,ディレクトリ生成するMakefileはいくらでも検索したら出てくるが,ディレクトリだけを生成するターゲットとmakeのルールの書き方がすぐに見つからなかったのでメモ.

オブジェクトファイルに依存してなければ作れば良い?

Makefile
BIN_DIR = ../bin
MAIN = $(BIN_DIR)/main
MAIN_SRC = $(addsuffix .cpp, $(MAIN))
MAIN_OBJ = $(MAIN_SRC:%=%.o)


all: $(BIN_DIR) $(MAIN)

$(BIN_DIR): $(wildcard *.o)
	@if [ ! -d $(BIN_DIR) ]; then \
		echo ";; mkdir $(BIN_DIR)"; mkdir $(BIN_DIR); \
	fi

$(MAIN): $(MAIN_OBJ)
...(以下略)
1
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
1
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?