Last active
October 27, 2021 13:23
-
-
Save peter-dolkens/69dfcebbe7a5f9fc2c6a6bf2d6295804 to your computer and use it in GitHub Desktop.
Make batch file to ensure make is available in windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
SET TOOLS_PATH=C:\Tools | |
IF NOT DEFINED GIT_PATH ( | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where git`) do (IF NOT DEFINED GIT_PATH (SET "GIT_PATH=%%g")) | |
IF NOT DEFINED GIT_PATH ( | |
SET "PATH=%PATH%;%ProgramFiles%\Git\cmd" | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where git`) do (IF NOT DEFINED GIT_PATH (SET "GIT_PATH=%%g")) | |
) | |
IF NOT DEFINED GIT_PATH ( | |
echo Git not found - please install Git for Windows | |
exit /b 1 | |
) | |
) | |
IF NOT DEFINED DOCKER_PATH ( | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where docker`) do (IF NOT DEFINED DOCKER_PATH (SET "DOCKER_PATH=%%g")) | |
IF NOT DEFINED DOCKER_PATH ( | |
SET "PATH=%PATH%;%ProgramFiles%\Docker\Docker\resources\bin" | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where docker`) do (IF NOT DEFINED DOCKER_PATH (SET "DOCKER_PATH=%%g")) | |
) | |
IF NOT DEFINED DOCKER_PATH ( | |
curl https://desktop.docker.com/win/stable/46911/Docker%20Desktop%20Installer.exe -o %TMP%\docker-2.3.0.4.46911.exe | |
%TMP%\docker-2.3.0.4.46911.exe install --quiet | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where docker`) do (IF NOT DEFINED DOCKER_PATH (SET "DOCKER_PATH=%%g")) | |
) | |
) | |
IF NOT DEFINED GREP_PATH ( | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where grep`) DO IF NOT DEFINED GREP_PATH SET "GREP_PATH=%%g" | |
IF NOT DEFINED GREP_PATH ( | |
SET "PATH=%PATH%;%GIT_PATH:cmd\git.exe=usr\bin%" | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where grep`) DO IF NOT DEFINED GREP_PATH SET "GREP_PATH=%%g" | |
) | |
IF NOT DEFINED GREP_PATH ( | |
IF NOT EXIST "%TOOLS_PATH%\GnuWin32\bin\grep.exe" ( | |
echo Installing Grep... | |
curl https://deac-ams.dl.sourceforge.net/project/gnuwin32/grep/2.5.4/grep-2.5.4-bin.zip -o %TMP%\grep-2.5.4-bin.zip | |
curl https://deac-ams.dl.sourceforge.net/project/gnuwin32/grep/2.5.4/grep-2.5.4-dep.zip -o %TMP%\grep-2.5.4-dep.zip | |
IF NOT EXIST "%TOOLS_PATH%\GnuWin32" mkdir "%TOOLS_PATH%\GnuWin32" | |
tar -C "%TOOLS_PATH%\GnuWin32" -xf %TMP%\grep-2.5.4-bin.zip | |
tar -C "%TOOLS_PATH%\GnuWin32" -xf %TMP%\grep-2.5.4-dep.zip | |
) | |
SET "GREP_PATH=%TOOLS_PATH%\GnuWin32\bin\grep.exe" | |
SET "PATH=%PATH%;%TOOLS_PATH%\GnuWin32\bin" | |
) | |
) | |
IF NOT DEFINED MAKE_PATH ( | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where make ^| grep -v make.bat`) do (IF NOT DEFINED MAKE_PATH (SET "MAKE_PATH=%%g")) | |
IF NOT DEFINED MAKE_PATH ( | |
IF NOT EXIST "%TOOLS_PATH%\GnuWin32\bin\make.exe" ( | |
echo Installing Make... | |
curl https://deac-ams.dl.sourceforge.net/project/gnuwin32/make/3.81/make-3.81-bin.zip -o %TMP%\make-3.81-bin.zip | |
curl https://deac-ams.dl.sourceforge.net/project/gnuwin32/make/3.81/make-3.81-dep.zip -o %TMP%\make-3.81-dep.zip | |
IF NOT EXIST "%TOOLS_PATH%\GnuWin32" mkdir "%TOOLS_PATH%\GnuWin32" | |
tar -C "%TOOLS_PATH%\GnuWin32" -xf %TMP%\make-3.81-bin.zip | |
tar -C "%TOOLS_PATH%\GnuWin32" -xf %TMP%\make-3.81-dep.zip | |
) | |
SET "MAKE_PATH=%TOOLS_PATH%\GnuWin32\bin\make.exe" | |
SET "PATH=%PATH%;%TOOLS_PATH%\GnuWin32\bin" | |
) | |
) | |
IF NOT DEFINED BASH_PATH ( | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where bash`) do (IF NOT DEFINED BASH_PATH (SET "BASH_PATH=%%g")) | |
IF NOT DEFINED BASH_PATH ( | |
SET "PATH=%PATH%;%GIT_PATH:cmd\git.exe=usr\bin%" | |
FOR /F "tokens=* USEBACKQ" %%g IN (`where bash`) DO IF NOT DEFINED BASH_PATH SET "BASH_PATH=%%g" | |
) | |
IF NOT DEFINED BASH_PATH ( | |
echo Git not found - please install Git for Windows | |
exit /b 1 | |
) | |
) | |
echo ============ PATHS ============= | |
echo DOCKER_PATH: %DOCKER_PATH% | |
echo GREP_PATH: %GREP_PATH% | |
echo MAKE_PATH: %MAKE_PATH% | |
echo BASH_PATH: %BASH_PATH% | |
echo GIT_PATH: %GIT_PATH% | |
"%MAKE_PATH%" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHELL := /usr/bin/env bash | |
.PHONY : help | |
## Show help | |
help: | |
@echo '' | |
@echo 'Usage:' | |
@echo ' make ${YELLOW}<target>${RESET} ${GREEN}<description>${RESET}' | |
@echo '' | |
@echo 'Targets:' | |
@awk '/^[a-zA-Z0-9_-]+:/ { \ | |
helpMessage = match(lastLine, /^## (.*)/); \ | |
if (helpMessage) { \ | |
helpCommand = substr($$1, 0, index($$1, ":")); \ | |
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ | |
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \ | |
} \ | |
} \ | |
{ lastLine = $$0 }' $(MAKEFILE_LIST) | |
@echo '' | |
@echo 'TF_ACTION:' | |
@echo ' ${YELLOW}plan${RESET} ${GREEN}TF_ACTION=plan${RESET}' | |
@echo ' ${YELLOW}apply${RESET} ${GREEN}TF_ACTION=apply${RESET}' | |
@echo ' ${YELLOW}import${RESET} ${GREEN}TF_ACTION=import IMPORT_RESOURCE_NAME=xxx IMPORT_RESOURCE_ID=yyy${RESET}' | |
# make example ARGS=value | |
example: | |
@echo 'This is just an example' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment