DEV Community

Cover image for Makefile, in practice
Suspir0n
Suspir0n

Posted on

5 3

Makefile, in practice

What is Makefile ?

According to the Guia Linux "The make utility is used to check which files need to be compiled (have changed since the last compilation or have never been compiled) and to issue the compilation (and linking) order."

OBS: Rewritten text in English.

The makefile is utilized in sereval programming languages, like: C, C++, C#, Python, JavaScript, TypeScript, PHP between others.

To use, we have some commands:

  • -f: specific the file
  • -e: for variable of file makefile

How to use Makefile:

Alt Text

when starting a command, you have to create a file with a specific nomenclature, make will search your directory for:

  • GNUmakefile
  • makefile
  • Makefile

Write a Makefile

First create a file called "Makefile", how I will utilize python how example, inside him, you add the next:

.PHONY: help
SHELL := /bin/bash

help: ##This help.
    @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help
Enter fullscreen mode Exit fullscreen mode

In it, you are creating the command help, passing the terminal, it goes list all the command of makefile that you can use.

Then create:

run-file: ## run the file main.py
    python main.py
Enter fullscreen mode Exit fullscreen mode

When you run this command in terminal thus make run-file, it will run what have inside of file main.py. Note that have two "#" later of command, it suits to describe the command.

Complete code:

Alt Text

This example demonstrates how to optimize your time and your project is, more robust, reducing commands that you would have to execute among others, solving your problem. This was logbook #05 we are saying goodbye here. We will return with another logbook.

Was this article useful for you?
Leave a comment below.

References

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay