DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Makefiles and alternatives?

I don't know how to use Makefile. Do I need to install cmake first?

Recently, I have found https://github.com/tj/robo, which is a YAML-based Makefile runner. It also mentions

I'm aware of the million other solutions (Sake, Thor, etc)

So, what do you recommend I use for standardization? Otherwise, I might use npm init -y with scripts section (but too bad, it isn't YAML).

I am also looking for alternatives of concurrently -- https://github.com/tj/robo/issues/40

Top comments (10)

Collapse
 
jotafeldmann profile image
Jota Feldmann • Edited on

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 Author

Makefile seems namespace-limited and unpredictable to me.

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

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
 
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
 
avalander profile image
Avalander • Edited on

I don't know how to use Makefile. Do I need to install cmake first?

No, you need to install make. Although if you're not using Windows, it's most likely already installed in your system.

I mean, there are many alternatives. Few as ubiquitous as make. I'd suggest to just read through the guide and learn you some make for the greater good.

Collapse
 
louy2 profile image
Yufan Lou

The concept of make is three prong: tracking dependency, monitoring recency, and executing commands based on the previous two. Sounds simple enough.

However, since each system is different, standardization on the concept of make means almost nothing. Almost each programming language has a slightly different way to track dependency, especially when external dependency is involved, so they often make their own tool. If you mostly write JavaScript, sticking to npm is not bad. If you like YAML, nothing wrong with robo. There are also significant communities around gulp and grunt.

Another route is to adopt an integrated build system made by a big company with existing polyglot build rules. On this front we have Google's Bazel and Facebook's Buck, both coming from Google's internal build system Blaze. They are reasonably supported with rules for many languages. A community one is Nix, which you can try if you feel scholarly and adventurous.

An alternative of concurrently is npm-run-all, which is specific to npm scripts.

Collapse
 
smac89 profile image
smac89

In your search for make alternatives, remember that make is primarily concerned with input/output of files, and managing dependencies between tasks which create those files.

The ability to run arbitrary commands, is just a sideeffect. If your goal is to run arbitrary commands, then tools like npm, yarn, sake, robo, just, will do just fine.

If your goal is to find an alternative to make, then you really should be asking about alternative build tools, and I've found tools like cmake, and ninja to be quite good. Alternative to Makefile itself can be CMakeLists.txt or meson.build.

Collapse
 
jozsefsallai profile image
JΓ³zsef Sallai • Edited on

depends on what you're working with and the complexity of the stuff you want to do
when I work with node/npm, I just use npm scripts

also, cmake is a tool used for setting up and compiling C/C++ projects

Collapse
 
yuu profile image
yuu

would you like a Rake?

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt Author

Looks Ruby specific -- github.com/ruby/rake

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.