Как запустить Make на Windows
Make — это широко используемая для автоматизации сборки проектов утилита, которую бывает проблематично установить и запустить на windows. Сегодня я поделюсь самым простым способом, который позволит вам это сделать. Использовать мы будем Chocolatey.
Chocolatey (choco) — это менеджер пакетов для Windows, который позволяет устанавливать и управлять программным обеспечением из командной строки. Вот как установить утилиту make на Windows с помощью Chocolatey:
-
Установка Chocolatey:
-
Откройте PowerShell от имени администратора.
-
Вставьте следующую команду и нажмите Enter:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Эта команда скачает и запустит скрипт установки Chocolatey. Подтвердите выполнение команды, если будет запрошено разрешение.
-
Установка make с помощью Chocolatey:
После установки Chocolatey выполните следующую команду в PowerShell:
choco install make
Chocolatey автоматически загрузит и установит утилиту make и все необходимые зависимости.
-
Проверка установки:
make --version
Если установка прошла успешно, вы увидите вывод с информацией о версии make.
Далее, для использования make можно использовать обычный CMD, но, всегда в режиме администратора.
Если было полезно — подписывайтесь и ставьте лайки. Благодарю за внимание.
A Makefile is a special file that contains information about a program’s flow, targets, and libraries. To use it, we need to access the Make command. However, it is not preinstalled on Windows. In this post, we will learn how to install and run Makefile on Windows.
A Makefile is a file that contains information about a program’s flow, targets, and libraries. It is also known as a description file as it includes a group of targets and the sources on which they depend. Additionally, the Makefile contains libraries that support the source code. This type of file is executed using the make command. To install and run Makefile on your computer, you are supposed to follow the steps mentioned below.
- Download and install MinGW
- Configure Environmental Variable
- Install the Make command
- Rename mingw32-make.exe to Make
- Create and run the Makefile
Let us talk about them in detail.
1] Download and install MinGW
MinGW is the Windows adaptation of the GNU Compiler Collection (GCC), offering freely distributable import libraries and header files essential for developing native Windows applications. To use Make, we first need to download the MinGW installation media. Once downloaded, run the installation media, make sure to untick“also install support for the graphical user interface.”, and follow the on-screen instructions to complete the process. It will take some time to complete the installation process, so wait, and once done, click on Continue or Quit.
2] Configure Environmental Variable
After installing MinGW, we need to add the environmental variable to access the ‘Make’ command. For this, we need to first fetch the path of MinGW and add it to the environmental variables. Follow the steps mentioned below to copy the path of the mingw-get file.
- Open File Explorer by Win + I.
- Go to the location where you have installed MinGW. If you didn’t make any changes to the default location, go to C:\MinGW.
- Double-click on Bin to open the folder.
- You need to copy the path of the folder, as that would be the path of mingw-get.
Once you know the path of the file, follow the steps mentioned below to add it to the Environmental Variable.
- Open Control Panel.
- Search for “Environmental Variables”.
- Click on Edit the system environmental variable.
- Now, click on the Environmental Variable button.
- From the System variables section, click on Path, and then on Edit.
- Click on New and then paste the path we asked you to copy earlier.
- Click on Ok.
Now you can close all interfaces as we have added the environmental variable.
3] Install the Make command
After adding the environmental variable, we can install the Make command. However, you won’t be able to run the Make command without following the previous steps. To do so, open the Command Prompt as an administrator and then run the following command.
mingw-get install mingw32-make
When you run this command, MinGW will install all the modules related to Make; however, it will take a while to do so.
To know if it is installed, you can run mingw32-make --versioncommand. It will give you the version information about the MinGW installation.
4] Rename mingw32-make.exe to Make
Don’t you think, running ‘mingw32-make’ every time to use the ‘make’ command is a bit of a hassle? If yes, we would rename mingw32-make to Make so that next time we can just use the ‘make’ command. To do so, follow the steps mentioned below.
- Open File Explorer.
- Go to the location where you have installed mingw32.
- Now, double-click on Bin, and then rename mingw32-make file to make.
To verify this, run make --version. If the command is running without throwing any error, you can rest assured that renaming worked.
5] Create and run the Makefile
Upon installing the Make command, we can create a Makefile. There are various ways to do this, but we have listed a general guide below that you can follow.
- You can create a new folder with a name of your choice or the Makefile on your desktop; that’s what we did.
- Now, create a text file. To do so, right-click on a space and select New > Text document.
- Open the file and paste the following lines of code. Make that before starting the second line, you give a Tab.
firstmakefile:
echo "Getting started with Makefile";
- To save it, go to File > Save as.
- Give it a name, let’s say, Makefile, change the Save as type to All files, and click on Ok.
- To run the file, open Command Prompt.
- Navigate to the location where you have created the folder, for that, run the cd command. Since my location is C:\Users\yusuf\OneDrive\Desktop, I ran cd C:\Users\yusuf\OneDrive\Desktop.
- Run dir to list all the files present in that particular directory.
- To run the file, just run
make -f filename.
That’s how you can create and run a Makefile.
Read: How to install NumPy using PIP on Windows
What is the command to run a makefile?
To run a makefile, you are required to use the make command. However, if you want to call a file, use -f option so that the command would look like make -f filename.
Read: How to create a file without Extension in Windows
How do I install Make on Windows?
To install Make on your computer, we can install MinGW first, then add the environmental variable path, and finally, install Make. We recommend that you follow the guide mentioned earlier to install Make on your system.
Read: 5 System Information Tools in Windows.
Make is an incredibly powerful tool for managing application compilation, testing and installation, or even setting up the development environment. It comes standard on Linux and macOS, and it is therefore widely adopted. But how can you get started with Make on Windows?
I’ve previously written about using Make for Python development, you might find it interesting.
If you are using Windows Subsystem for Linux (WSL/WSL2), then you can easily install make with the sudo apt install make command. However, if you want to have the command available natively on a normal terminal prompt then you need to install a Windows-specific version.
How to install Make on Windows?
The easiest way to configure Make is to use the Chocolatey package manager for Windows. It will handle downloading the correct executable, installing it, and making sure that the command is added to the system path.
- Install Chocolatey if you don’t already have it installed
- Open an elevated terminal (Run as administrator)
- Type the command
choco install make, approve the installation if prompted
Next, verify that make works, and then you can start using it normally:
>> make --version
GNU Make 4.3
Built for Windows32
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Alternatively, if you’d prefer to use the new native Windows package manager you can use this winget command:
>> winget install GnuWin32.Make
This will download the installer and run it for you automatically. Make will also be added to the list of installed programs so you can uninstall it from the Add or remove programs section. You will still get the following error since the installer does not add make to the system path:
make : The term 'make' is not recognized as the name of a cmdlet,
function, script file, or operable program...
To make it executable you need to open the Start menu and search for Edit the system environment variables. Click Environment Variables, then under System variables choose Path and click Edit. Click New and insert C:\Program Files (x86)\GnuWin32\bin, then save the changes. Open a new terminal and test that the command works.
As of writing this article the current version that gets installed with winget is 3.81, so it is older than the one from Chocolatey. You may want to take that into consideration when choosing the installation method. You can check which version would be installed with winget show GnuWin32.Make.
Using Make on Windows
From a syntax perspective there is no difference between Linux and Windows. You still need to write a Makefile and define the shell commands in tab-indented sections. However, the commands themselves need to be adjusted for the changed operating system.
Normally on a Makefile each line runs on a separate shell. If you need to run many commands from the same shell instance then they should be defined on the same line and chained together with the && operator.
.PHONY: test
test: venv
.\venv\Scripts\activate && python -m unittest discover
.PHONY: venv
venv:
python -m venv venv
The above example defines phony Make targets for setting up a Python virtual environment and running unit tests. Assuming that you have installed Python, running make test should execute successfully, running zero unit tests since it couldn’t find any.
If you need to make your Makefile support different operating systems, then you have to also detect the operating system to be able to run a different set of commands for each OS. With Windows the added difficulty is that in some cases (MSYS, MINGW) you actually need to use the Linux commands.
This answer on Stack Overflow has one solution for finding the correct environment, relying on how the system Path is delimited by semicolons ; unlike all other OSes. We can use that information to make our small example Makefile work natively on both Windows and Linux:
ACTIVATE := ./venv/bin/activate
PYTHON := python3
ifeq '$(findstring ;,$(PATH))' ';'
ACTIVATE := .\venv\Scripts\activate
PYTHON := python
endif
.PHONY: venv
venv:
$(PYTHON) -m venv venv
.PHONY: test
os: venv
$(ACTIVATE) && $(PYTHON) -m unittest discover
The command for activating the virtual environment is different on Windows compared to other OSes. Also the Python executable is named python on Windows, but on Linux you need to use python3. The conflicting commands can be defined as variables and then referenced in the targets.
Similarly, if you’re compiling C or C++ code, you need to use gcc or g++ on Linux, and cl on the Windows developer command prompt. Also the command arguments will need to be different.
Conclusion
It’s possible to use Make natively on Windows, and it’s not even that difficult. If you’re accustomed to using Bash and Linux commands then the switch to PowerShell commands might require a bit of adaptation. Definitely the biggest challenge is to write Makefiles that support different operating systems, but as we saw that can be accomplished with some tricks.
WINDOWS
GNU Make is a powerful build automation tool that automatically builds executable programs and libraries from source code. It reads a file called Makefile to determine how to build your project. In this article, we’ll explore how to install GNU Make on Windows, focusing on two primary methods.
Why Install GNU Make on Windows?
-
Automation: Effortlessly compile and manage dependencies for large projects.
-
Efficiency: Save time by automating repetitive tasks.
-
Cross-Platform Compatibility: Running GNU Make on Windows allows for greater consistency when working on cross-platform projects.
Let’s Keep It Short. There Are 2 Options (There Are More, But We’ll See Two).
Option 1: Using MinGW
MinGW (Minimalist GNU for Windows) is a popular choice for installing GNU Make along with other GNU utilities. Here’s how to do it:
Step 1: Download MinGW
-
Visit the MinGW-w64 website.
-
Click on the “Downloads” section.
-
Select the installer that is compatible with your system architecture (32-bit or 64-bit).
Step 2: Install MinGW
-
Run the downloaded installer.
-
During installation, select “Basic Setup” and make sure to include
mingw32-baseandmingw32-gcc-g++. This will provide the necessary GNU commands includingmake. -
Click on “Installation” → “Apply Changes” to install the selected packages.
Step 3: Add MinGW to the System Path
To use make from any command prompt window, you need to add the MinGW bin directory to your system PATH.
-
Right-click on “This PC” or “My Computer” and select “Properties”.
-
Click on “Advanced system settings”.
-
Click on the “Environment Variables” button.
-
Under “System Variables”, find and select the
Pathvariable then click “Edit”. -
Add the path to the MinGW
bindirectory, typicallyC:\MinGW\bin. -
Click “OK” to save changes and exit all dialogs.
Step 4: Verify Installation
Open a command prompt and type the following command:
If installed correctly, it should output the version of GNU Make.
Option 2: Using Cygwin
Cygwin provides a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
Step 1: Download Cygwin
-
Visit the Cygwin website.
-
Click on the “Install Cygwin” link to download the setup executable.
Step 2: Install Cygwin
-
Run the setup executable and follow the instructions.
-
When prompted to choose packages, search for
makein the package selection section. -
Under the
Develcategory, findmakeand click on “Skip” to mark it for installation.
Step 3: Complete the Installation
Continue with the installation process, allowing it to download and install all selected packages.
Step 4: Verify Installation
After Cygwin installation is complete, open the Cygwin terminal and run:
You should see the version of GNU Make displayed.
Troubleshooting Common Issues
-
Command not found: If you encounter this message, check that the environment path is set correctly and that the installation folders contain
make.exe. -
Makefile issues: If
makeruns but fails to find yourMakefile, ensure you’re in the correct directory where theMakefileis located.
Conclusion
Installing GNU Make on Windows can enhance your development workflow, particularly for complex projects that require automation. In this article, we’ve walked through two primary options: using MinGW and Cygwin, providing you with the flexibility to choose what suits your needs best. Whether you opt for MinGW’s simplicity or Cygwin’s comprehensive environment, you’ll be well-equipped to leverage the power of GNU Make in your projects.
Now you are ready to create, manage, and automate your builds effectively on Windows. Happy coding!
Suggested Articles
WINDOWS
WINDOWS
WINDOWS
WINDOWS
WINDOWS
WINDOWS
Make in Windows
Description of how to install and use Make in Windows OS.
There are several ways to install Make on Windows. In this tutorial we will use Git Bash because it is also needed for on Windows, so you might already have that if you followed the steps in . The steps follow the instructions detailed . After installing Git & Git Bash:
-
Download
make-4.4-without-guile-w32-bin.zip(get the version without guile). -
Copy the contents to your
C:\Program Files\Git\mingw64\merging the folders, but do NOT overwrite/replace any existing files.
Using Makefiles in different environments
Commands are called differently in different environments, for example, if you want to run Stata in Git Bash terminal on Windows you should use StataMP-64, but stata on Mac and Linux. Aliases don’t work well in our setting (as Make is run in Git Bash, but Make itself uses the sh shell). Although if you include an operation system detector part at the beginning of your Makefile, it provides a simple solution for a reproducible Makefile in different environments.
Let’s create a project folder called trial/, where the codes can be run with a Makefile both on Windows and Mac or Linux. There should be 2 files in the folder: trial.do and Makefile. The trial.do creates a trial.log just to see and check whether Make runs correctly. The content of trail.do is the following:
capture log close
log using "trial.log", replace text
disp "DateTime: $S_DATE $S_TIME"
log close
You can copy the following content in your Makefile:
#OS detector part
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... STATA := StataMP-64 else STATA := stata endif
#Code starts here
trial.log: trial.do $(STATA) -e do $<
When you finished, open the Git Bash terminal, go to the trial/ folder where the trail.do and your Makefile is, and then run make.
$ cd ~/.../trial/
$ ls
trial.do
Makefile
$ make
Afterward, you should see the trial.log created by the Makefile.
