DEV Community

Discussion on: Makefiles and alternatives?

Collapse
 
jotafeldmann profile image
Jota Feldmann • Edited

Hi Pacharapol,

I recommend Makefile for some reasons:

  • Exists since 1976 (old, battle-tested);
  • It's included in Linux and macOS versions;
  • It's some sort of industry standard for common tasks.

Example: you're working in a polyglot stack (Node, Python, Java, Go). Even when you're experienced in one or two languages, you don't know how to execute some tasks (NPM for Node, Pipenv for Python, Maven/Gradle for Java, so on).

One simple way to solve that is using a common approach to create common tasks using the Makefile, and wrap the language-specific command, like make dev for npm run dev (developer profile to watch and reload changes), make test for npm test, make run for npm start (for production), make deploy, etc.

In the end, you don't need to know the tasks or read all the README.md in the repositories. And better: you can check the Makefile for all available tasks and how its work for all languages :)

Makefile its not hard: cs.colby.edu/maxwell/courses/tutor...

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Makefile seems namespace-limited and unpredictable to me.

I cannot use folder name as a task name...

Collapse
 
jotafeldmann profile image
Jota Feldmann

As with everything, including computers, there are trade-offs. Don't judge ONLY by the first contact or StackOverflow responses. We need to dig that kind of long term solution by its possibilities.

About using the folder name, try:

.PHONY: task-with-same-folder-same
task-with-same-folder-same:

Collapse
 
andyvanee profile image
Andy Vanee

You can use a folder/file name as a task name and this actually highlights one of the benefits of make that a lot of other systems either don't do, or make difficult.

Suppose you have the following rules:

.PHONY: deploy
deploy: .env node_modules

node_modules: package.json
    npm install

.env:
    cp example.env .env
Enter fullscreen mode Exit fullscreen mode

Now when you run make deploy, npm install will run if the package.json file is newer than the node_modules directory and the .env file will be created if it doesn't exist.

Collapse
 
bdmorin profile image
Brian

makefile has a lot of things to complain about, unpredictable I simply don't see. It's rock solid, and hasn't changed massively in over a decade.