News for hackers. Stuff that matters.
Re:Time for Makefiles to Make a Comeback by Iv on Tuesday September 05, 2017 @09:08AM (#15174715)
If you compare Makefiles to the JavaScript ecosystem it will do so favorably, but many things will.

Make is a good build system but it is a shitty deployment system. Yes, you can do everything you want if you put enough effort in it as it is a complete scripting system, something many alternatives are not.

It does not mean that it is a good idea to do so.

Recently a client made me begrudgingly try Maven. 'Yet another make system' I thought. Yup, pretty standard one: 'mvn install' ,I'll compile everything and will also do something make has never done for me: install dependencies.

Sure, it is doable to do this with a makefile. With a lot of efforts multiplied by the number of platforms you target. In Maven you just add repos and dependencies to your pom file.

So yes, there recent build systems that are worse than Make but it does not mean that make is the perfect system with all the features we need.

It is minimalistic. It works. But it should not be your only option.

Re:Time for Makefiles to Make a Comeback by orclev on Tuesday September 05, 2017 @09:36AM (#15174919)
That last bit is really key. Nearly every modern build system is also a dependency management system, something that really isn't possible using Make. There have been tools introduced to address that particular need for C/C++, but they integrate poorly if at all with the build system, so it turns all your builds into (at least initially) three step processes of run dependency installer, run config tool to figure out exactly which flavor of C compiler/linker/etc. to invoke, run make to actually build the thing.

It's also possible to do some truly awful things with make. I once worked on an embedded device that the SDK provided by the OEM was written using a truly horrific makefile system. There were no less than 80 makefiles all tied together to build an entire system image, including the building of the linux kernel, all the bintools, and a bunch of other custom stuff the OEM provided. Trying to understand, much less modify any part of that build system was an absolute nightmare, and is one of the few times I've actually wished they had used shell scripts instead of make for some of that stuff.

As for Maven, it was quite a pioneer in its day, but it hasn't aged well, in particular being written in XML which just adds needless verbosity. For a more modern take, look at Gradle, which provides everything that Maven does (and uses mavens dependency system), but is a lot more flexible because it's a DSL for project building instead of a declarative system like Maven.

Re:Time for Makefiles to Make a Comeback by snuxoll on Tuesday September 05, 2017 @10:15AM (#15175372)
I think the declarative model is why I prefer Maven over any other build system I've worked with, yeah XML is a little noisy but if it's really that big of a deal there's the polyglot plugin. Maven POM's are pretty easy to figure out once you've worked with them for a while, there's a learning curve when you start adding plugins and have to get at least a basic understanding of build phases - but a large chunk of projects need nothing more than the default plugin bindings, they just add their dependencies and go off to the races.
Re:Time for Makefiles to Make a Comeback by JdeBP on Wednesday September 06, 2017 @06:40AM (#15182585)
redo is mentioned elsewhere in this very discussion.

One of the things that Daniel J. Bernstein did in his packages is merge steps two and three. There would be makefile/redo rules for detecting the presence of operating-system-specific stuff, and linking the appropriate source/header files into place.

Here's an example from ucspi-tcp that auto-configures whether the platform supports waitpid():

* https://github.com/comotion/ucspi-tcp/blob/master/Makefile#L...

* https://github.com/comotion/ucspi-tcp/blob/master/choose.sh

* https://github.com/comotion/ucspi-tcp/blob/master/trywaitp.c

* https://github.com/comotion/ucspi-tcp/blob/master/haswaitp.h...

* https://github.com/comotion/ucspi-tcp/blob/master/haswaitp.h...

When I extended redo to the whole of djbwares, this system was fairly simple to convert. Here is haswaitp.h.do which is what redo ends up running whenever something reveals a dependency from haswaitp.h :

    #!/bin/sh -e
    redo-ifchange trywaitp.c compile link
    if ( ./compile trywaitp.o trywaitp.c trywaitp.d && ./link trywaitp trywaitp.o ) >/dev/null 2>&1
    then
            echo \#define HASWAITPID 1 > "$3"
    else
            echo '/* sysdep: -waitpid */' > "$3"
    fi
* http://jdebp.eu./Softwares/djbwares/
Re:Time for Makefiles to Make a Comeback by rleigh on Tuesday September 05, 2017 @12:26PM (#15176697)
> Nearly every modern build system is also a dependency management system, something that really isn't possible using Make

The BSD Ports tree provides exactly this functionality. All package dependencies provided via standard make variables and rules, enabling recursive resolution of all package dependencies.

Re:Time for Makefiles to Make a Comeback by mikegerwitz on Tuesday September 05, 2017 @09:39AM (#15174959)
Make isn't intended to be used for dependency management. With traditional `./configure && make && make install`, dependencies are detected by the configure script, or manually provided by the user if they have custom library paths. Dependencies are handled by your package manager or something else (be it submodules in git, custom scripts, etc). There's a separation of concerns.

For generating those configure files, Autoconf is extremely powerful (and really not that complicated once you have a basic understanding). If you use Automake, you get all the standard targets (including `make dist`, which will build your distribution archive, as is being done manually in this article) generated for you.

Re:Time for Makefiles to Make a Comeback by orclev on Tuesday September 05, 2017 @09:50AM (#15175095)
That's a rather dated view of what a build system should be. Most developers these days don't want to have to manually install all of a projects dependencies in order to build it. More importantly, there's also been a push towards wherever possible installing dependencies into sandboxes to try to prevent things like DLL hell, which isn't possible if you install dependencies at the OS level. I much rather just check out a project and run its build system to fetch all the dependencies instead of what we used to have to do with C projects, which is go read the docs to find the list of mandatory and optional dependencies, then go look through the distribution package manager to try to match up package names with library names (including a few head scratchers where something is included inside of a differently named package), and finally install the whole mess and hope that the projects config script properly finds them all.
Re:Time for Makefiles to Make a Comeback by mikegerwitz on Tuesday September 05, 2017 @09:58AM (#15175184)
> That's a rather dated view of what a build system should be

The author mentions JavaScript, which has npm as the package manager, which isn't a build system. It can _invoke_ a build system, but the build output produced is separately published to npm, or the build is triggered by e.g. a post-install hook.

I use GNU Make with npm. Some use e.g. Grunt. Etc.

> More importantly, there's also been a push towards wherever possible installing dependencies into sandboxes to try to prevent things like DLL hell, which isn't possible if you install dependencies at the OS level.

Make has been used this way for quite some time. Debian has its reproducible builds project. GNU Guix builds everything in an isolated environment, and even handles multiple versions of multiple packages---if you have five different packages that each depend on five different versions of the same library, then it'll install five different versions of the library and work just fine.

> I much rather just check out a project and run its build system to fetch all the dependencies instead of what we used to have to do with C projects

Make is just _part_ of a build system---it isn't necessarily one in itself. Some projects might use it exclusively in their build system, but others use a suite of tools. I use Autoconf (which generates configure) and Automake, which in turn generates a Makefile with all standard targets. If you check out a git repository for one of my JS projects, you run `npm install` to get the dependencies before building. Usually they're runtime dependencies, though, so they're not needed for the build. Other dependencies are detected via the configure script (e.g. I use graphviz for certain project, and the script makes sure it's installed and supports the feature I need).

Re:Time for Makefiles to Make a Comeback by orclev on Tuesday September 05, 2017 @10:32AM (#15175559)
For the most part, JavaScript doesn't need a build system, so from a practical standpoint npm is its build system. Most JS projects shouldn't require anything more complicated than npm install to put them in the proper location. Now you can argue for something like a minifier, and things like Typescript add a wrinkle (as it actually does need a build system), but all that should still be able to be handled by npm.

I'm curious how you would use Make to install dependencies. I'm aware of Guix, but that's probably an extreme example, most people probably aren't willing to sandbox literally their entire OS install, plus it's entirely unreasonable to require a particular OS in order to handle dependencies of your project. It shouldn't matter what OS I'm using (within reason), the project should have an automated way to install any dependencies it requires.

Here's the thing with Make, even if used only as part of a build system, it's both too complicated, and not complicated enough at the same time. The makefile format when used very sparingly isn't too bad, but once you pass needing more than 2 or 3 rules it gets unwieldy, and on any significantly sized project it will need more than 2 or 3 rules. Using autoconf and automake just proves the point, now you're using a build system to build your build system. Autoconf in particular is way too complicated, and an absolute nightmare to try to extend or customize.

Instead of using a tiny little sliver of make as essentially build system glue to connect the actual build tools together, why not just use slightly more powerful build tools and get rid of make all together?

Re:Time for Makefiles to Make a Comeback by rekado on Thursday September 07, 2017 @03:27AM (#15189752)
You wrote:

> I'm aware of Guix, but that's probably an extreme example, most people probably aren't willing to sandbox literally their entire OS install, plus it's entirely unreasonable to require a particular OS in order to handle dependencies of your project. It shouldn't matter what OS I'm using (within reason), the project should have an automated way to install any dependencies it requires.

Guix is just a package manager, not an operating system. The Guix System Distribution, on the other hand, is a GNU system. You can use Guix on any GNU+Linux system; you do not need GuixSD for that.

Re:Time for Makefiles to Make a Comeback by hyperpape on Tuesday September 05, 2017 @12:41PM (#15176835)
JavaScript needs a build system: https://tomdale.net/2017/04/making-the-jump/
Re:Time for Makefiles to Make a Comeback by jolson88 on Thursday September 07, 2017 @03:49AM (#15189847)
Author here. Great feedback! Thanks for taking the time to share it :).

If I were creating a JavaScript library package that I was just going to push up to npm, I don't think I'd use Make either. yes, Typescript adds a wrinkle, but like you mention, that can all be handled by npm scripts as well. If it was just a JavaScript library, I'd definitely just use npm scripts and call out to eslint, and other tools just fine and not be any less happy.

However, big front-end applications I think are starting to become more and more complex and can benefit from this. Part of the reason is perhaps more because of the lack-of-functionality around incremental builds in the compilers themselves (thinking less/sass/minify/uglify/etc., this is where I've seen people usually fall back to using Gulp). As the application becomes larger, I think the lack of incremental build becomes more and more of a tax on the developer because the builds become longer and longer (I've worked on several projects like that).

I think perhaps the biggest impact on this project where Make is used had more to do with the modular project architecture than anything else. If it weren't for that, I'm not sure I'd ever even think of Make. And frankly, I think a modular project structure in a single github repository like this project uses is most likely not the right solution (or even a good idea) for a vast number of JavaScript/TypeScript projects out there.

When the article talks about dependencies, it is more talking about dependencies within the project itself (due to the modular architecture). Before I switched it over to Make, it was using a combination of preinstall, postinstall, and custom "prestart" scripts to do everything in the right order because it wasn't as simple as using `npm link` or doing a single npm install in the root of the project. These various scripts become a total mishmash of different approaches and it became increasingly difficult to understand and visualize what was being built when and in what order.

It wasn't uncommon to run into issues as well where one project would be `npm install`'d before it's dependencies were actually ready to be used (since they hadn't been compiled and packaged yet).

With that said, Make in this project doesn't install dependencies in the sense that I think you are discussing. This project is most definitely a Node.js project and uses npm for all that stuff. It's just within the project itself, there are sub-projects that are NPM packages themselves that can be built and deployed separately. That's where it began to fall down. But the project still most definitely uses "npm install", "npm start", and such. It's just the build component of issuing "npm run build" just shells out to "make -r" to build everything in the right order, in an incremental fashion, and to get it where it needs to be.

There are many reasons behind this modular architecture that I never went into in the post for good reasons. And like I said, I would be sad if lots of projects thought all-the-sudden it was a good idea to do it :P.

All that said, over the last 10+ years, I've grown increasingly tired of new frameworks coming out every 18 months (or less) that simply re-invent the wheel, but do it in a different way. I think there are plenty of situations where Make would perfectly suffice yet people immediately pull in a code-based build tool with tons of dependencies because it's what "everybody is using now."

Re:Time for Makefiles to Make a Comeback by Iv on Tuesday September 05, 2017 @02:25PM (#15177839)
Well ./configure does not install dependencies either. Even worse: it fails at the first missing dependency instead of listing them. Making an automake project to compile is actually a long and manual process.

Just today I had to compile an older version of gimp, just a 2 years old one. Configure. Fails. Apt-get this. Configure. Fails. Apt-get that. Oh, no, configure doesn't want obscure-package4, it wants obscure-package2, that has been removed from your distribution's repos. Arrrrrr! Truth be told, I just rebooted on windows and dowloaded a binary from an archive.

With maven, I can just tell it which release I want and it just fetches it and all its dependencies, compiles them and installs them. Full auto. If I add a lib in my project, it adds it automatically and the intellisense works, the source navigation works.

Make is years behind.

Re:Time for Makefiles to Make a Comeback by mikegerwitz on Tuesday September 05, 2017 @02:55PM (#15178091)
> Even worse: it fails at the first missing dependency instead of listing them.

Yes, this is a fair criticism. Fortunately, many projects state their dependencies. But not all do. If I'm already on a Debian system that has another version of the package, `apt-get build-dep' is very helpful to get most of the way there. Of course this is completely outside Autoconf.

Whether it fails immediately or not depends on how the author writes `configure.ac'. Usually `AC_MSG_ERROR' is used right away, because it's convenient. Instead, some authors choose to set a flag and fail at the end.

Re:Time for Makefiles to Make a Comeback by JdeBP on Wednesday September 06, 2017 @05:45AM (#15182331)
Why wasn't

    apt-get build-dep gimp
or

    aptitude build-depends gimp
the easy answer?
Re:Time for Makefiles to Make a Comeback by athenot on Tuesday September 05, 2017 @09:56AM (#15175165)
Yes Make does one thing and one thing well.

Having said that, if you really want to manage dependencies with Make, it's still trivial to do a curl/yum/rpm install when some component is missing. I've done that in the form of a `make deps` pseudo-target, to prevent doing anything that the user doesn't expect.

Re:Time for Makefiles to Make a Comeback by Iv on Tuesday September 05, 2017 @02:30PM (#15177885)
> it's still trivial to do a curl/yum/rpm install when some component is missing.

Oh yeah? Which one? curl, yum, rpm, apt-get? All of them? Which revisions are you targeting? Which package names? And that only covers windows. A lot of apps need to be deployable under windows and OSX too.

If you start being even slightly cross-platform, you soon have your own build system.

Re:Time for Makefiles to Make a Comeback by mikegerwitz on Tuesday September 05, 2017 @10:20AM (#15175433)
Yes having a separate target that isn't automatically invoked unexpectedly is important---the user doesn't expect network requests during build traditionally. Environments that build in isolation with no network access would fail as well.
Re:Time for Makefiles to Make a Comeback by dozzie on Tuesday September 05, 2017 @03:13PM (#15178237)
> Make is a good build system but it is a shitty deployment system.

Because you really should not deploy things with your build system. It's the today's tooling that got this backward. For deployment you have much saner tools, like package systems.

Re:Time for Makefiles to Make a Comeback by mst on Friday September 08, 2017 @01:07PM (#15201989)
But only 'git pull' is web scale!!!!

(sigh)

Re:Time for Makefiles to Make a Comeback by abritinthebay on Tuesday September 05, 2017 @12:22PM (#15176656)
Eh, different strokes. Every time I have to use Makefiles I yearn for the comparative flexibility and simplicity of the JS ecosystem.

Make files just seem good to users of the due to experience. They work, but let’s not pretend they’re easy to work with.

Re:Time for Makefiles to Make a Comeback by stephenr on Tuesday September 05, 2017 @04:13PM (#15178714)
> simplicity of the JS ecosystem

[citation needed]

Re:Time for Makefiles to Make a Comeback by abritinthebay on Tuesday September 05, 2017 @04:27PM (#15178833)
Citation: I work with it every day. You can make it complex but that’s true of everything.

It’s not hard or complex to get working initially, or maintain, which is not true of makefiles

Re:Time for Makefiles to Make a Comeback by stephenr on Wednesday September 06, 2017 @03:11AM (#15181763)
> It’s not hard or complex to get working initially, or maintain, which is not true of makefiles

Again, [citation needed].

I use Makefiles in a variety of projects:

- building Vagrant base boxes

- building environment-specific configuration for LAMP-ish CRUD apps

- testing and building a range of shell-script based packages

Does Make have some warts? Sure, everything does. I'm not claiming it's perfect.

But it's a far sight clearer - to me at least - what's going on with a Makefile.

Makefiles also don't need to be replaced by something new in 6 months because the entire community has decided that its time for a new tool to do basically the same thing, solve 1 problem with the old tool and introduce 5 new ones.