## How can I use the `make` cli tool to install development environment binaries depending on my OS?
You can create a `Makefile` in your working directory that looks like this:
```cmake
# Detect the OS
ifeq ($(OS),Windows_NT)
OS_DETECTED := Windows
else
OS_DETECTED := $(shell uname -s)
endif
# Set the command for checking if the tool is installed
CHECK_TOOL = command -v
# Set the command for installing the tool depending on the OS
ifeq ($(OS_DETECTED),Linux)
INSTALL_TOOL = sudo apt-get install -y
else ifeq ($(OS_DETECTED),Darwin) # macOS
INSTALL_TOOL = brew install
else ifeq ($(OS_DETECTED),Windows) # Windows with WSL
INSTALL_TOOL = sudo apt-get install -y
else
$(error Unsupported OS: $(OS_DETECTED))
endif
TOOLS = example_tool1:example_tool1_package example_tool3:example_tool3_package
.PHONY: install
install:
@for tool_mapping in $(TOOLS); do \
binary_name=$(echo $tool_mapping | cut -d: -f1); \
package_name=$(echo $tool_mapping | cut -d: -f2); \
if ! $(CHECK_TOOL) $binary_name >/dev/null 2>&1; then \
echo "$binary_name is not installed."; \
echo "Installing $binary_name for $(OS_DETECTED)..."; \
$(INSTALL_TOOL) $package_name; \
else \
echo "$binary_name is already installed."; \
fi; \
done
```
You'll need to edit the `TOOLS` variable to reference the binary name and package-manager name
Run ```make install``` in the terminal!
This will run the `install` command in the `Makefile` we just made and install the binaries you asked for if not already installed
## !Important syntax note!
Make expects `tab` characters instead of `space` characters!
Ensure your indentation is converted in order for this to work!
## What is Make?
See: https://thoughtbot.com/blog/the-magic-behind-configure-make-make-install
# Related
- [[What are the basic concepts and pieces of a Makefile]]
- [[The History of CMake and GNUMake]]