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?

Makefileの環境切り替えの提案

Posted at

動機

Makefileでクロスコンパイル環境を実現したい。
切り替えの方法を楽にしたい。

一般的な方法

環境変数で指定する。

$ make ENV=linux all  # Linux環境
$ make ENV=win all    # Win環境

嫌だな、と思うところ

  • TAB補完で出てこない
  • 変数の名前を覚えてないといけない
  • どれだけの環境があるかぱっとわからない

解決方針

ターゲット指定で環境を切り替えられるようにしたい

実現方法

サンプル

.PHONY: all DEV_LINUX DEV_WIN

# MAKECMDGOALS による環境自動設定
# 最初に指定された DEV_XXX を ENV にいれる
ENV :=  $(firstword $(filter DEV_LINUX DEV_WIN,$(MAKECMDGOALS))

#####################################
# ENVによるコンパイラなどの切り替え
#####################################

# デフォルトターゲット
all: 
	@echo "building for $(ENV) with $(CC)"

# 環境切替ターゲット 何もしない
DEV_LINUX DEV_WIN:
	@:

実行サンプル

$ make DEV_WIN all
building for DEV_WIN with cc

$ make DEV_LINUX all
building for DEV_LINUX with cc
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?