Closed2

【Makefile】macとwindowsでコマンドの中身を変える

やむやむ

macではopenコマンドを使用しているが、windowsだとstartコマンドを使用することになる。
どちらも同じコマンドで実行したい。

やむやむ

対処法

OSにより分岐させて変数に設定し、それをコマンド登録する。
さらに、windowsではstartコマンドを直接書くとうまく動かないため、startコマンドを記載したbatファイルを呼び出す。

Makefile
current_dir := $(shell cd)

ifeq ($(OS),Windows_NT)
    # Windows
    OPEN_COVERAGE_CMD = call open_coverage.bat "$(current_dir)"
else
    OPEN_COVERAGE_CMD = open ./app/build/reports/jacoco/test/html/index.html
endif

# カバレッジをhtmlを開く
open-coverage:
	$(OPEN_COVERAGE_CMD)
open_coverage.bat
@echo off
start "" "chrome.exe" "%1\app\build\reports\jacoco\test\html\index.html"
このスクラップは3ヶ月前にクローズされました