4 ms·
WHY CAN'T WE JUST USE MAKEFILES
by endlessvoid94 15y ago
WHY CAN'T WE JUST USE MAKEFILES
- jmtulloss 15y agoWhile perhaps not eloquently stated, the point is valid. Makefiles work as well as anything for most of these sorts of tasks.
- snprbob86 15y ago> Makefiles work as well as anything I'd argue that they always work better than any of these language-specific alternatives ever do. I'm not saying that GNUMake or BSD's Make or any particular Make is perfect. Surely there is still a lot of evolution to happen in build systems. What I am saying is that if you have a bunch of scripts to run & a bunch of files they produce, you can't beat a general purpose dependency graph with files for nodes and command lines for edges. Lately, I `touch Makefile` as one of the absolute first things I do on a project, regardless of language or framework, even when just hacking around. I'll even write a Makefile if I'm just doing some data analysis, like multi-stage log grepping. I find `rm intermediate.file; make` to be a nice alternative to putzing with command history and avoiding waisting time redoing expensive steps. Hell, we completely manage the configuration on our servers using Make instead of something like Puppet or Chef. So far, it's working pretty well, bit I'm still a newbie at sysadmin stuff. We've even replaced all of the db migration & other common Rails rake tasks with a few short bash scripts and ~10 lines of Make. We use .sql files for migrations and store db/schema.sql instead of db/schema.rb. It's two orders of magnitude faster to run our tiny script/dump-schemas.sh against psql instead of loading the Rails environment to query the db.
- phtrivier 15y agoCause sometimes you need your tasks to have, you know, logic and stuff ? Or am I the only one who want to do the equivalent of a "if" in a build script from times to times, and feel completely helpless with Make ?
- endlessvoid94 15y agohttp://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_chapter/make_7.html http://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_...
- phtrivier 15y agoThanks. Did not knew about this (I should have pointed that I haven't been using Makefiles for a while). However : "Conditionals control what make actually "sees" in the makefile, so they cannot be used to control shell commands at the time of execution." (emphasis mine). So I get that is would not solve the kind of issues I had in mind... Never mind.
- snprbob86 15y agoYou're not supposed to put significant logic in a makefile. You've already got tons of tools for real logic. A makefile is a dependency graph. If statements are for defining slightly different graphs in slightly different environments. If you need to add real logic, write a shell script. A well written Makefile has a small preamble of variable definitions, followed by a couple of named convenience .PHONY targets (without any commands), followed by a small handful of pattern rules, followed by the dependency graph. Each edge in the dependency graph should include as few commands as possible, preferably just one!
- batista 15y agoMight as well asks "why use Fabric/Capistrano/Chef/etc" instead of Makefiles. We have progressed beyond that, and beyond caps-lock only keyboards. Why not "just use makefiles". Because they use a BS syntax and are not as convenient as Python. Because they are not even portable, whereas Python scripts run on Windows just fine. Because they weren't even invented for that purpose, but for compiling stuff, and they failed even that so much, that every other project has it's own implementation (cmake, qmake, ant, scons, ...) or at the very least uses automation tools on top make, like the autotools, etc.
- batista 15y agoN downvotes from people suggesting we use Makefiles for the purposes we use Rake etc? And they call themselves "hackers"? Probably the embodiment of all that's wrong with legacy cruft and voodoo practices.
- endlessvoid94 15y agoNo, it's mostly because the Makefile grammar is incredibly well suited to any of the things you've mentioned -- it's just seen as "old", and most people don't know it anymore. It's neither legacy nor voodoo. Your statement that if you suggest using one tool in place of another makes you something besides a hacker is incomprehensible. PUppet/chef/capistrano are specialized versions of Make. Rake is a misnomer, as it's just a collect of "tasks". Again, it's a subset of what Makefiles can do. It's a little bit like using Lisp -- it's a "dilapidated", "old" tool but most modern tools are subsets of it in some manner.
- batista 15y agoNo, it's mostly because the Makefile grammar is incredibly well suited to any of the things you've mentioned -- it's just seen as "old", and most people don't know it anymore. It's not just seen as old. It is old, and not in a good way. The only thing it has got going for it, is being generally available. Make has poor support for many common needs. For example, it doesn't track dependencies itself. It lacks proper namespace support. The whitespace rules can get you. It lacks higher level constructs that one can build with other tools. You can't programmatically introspect the make script to see how it goes or debug it if it behaves unexpectedly. It doesn't know anything about the stuff you're working with -- i.e you're stuck with plain old command line instead of smart context based scripting ("now I want to update some configuration file", "now I want to sftp stuff", "now I want to ... on a non POSIX machine", "now I want to interface with a database"). It's also bad for managing multiple different environments, leading to the autotools et co development. Your statement that if you suggest using one tool in place of another makes you something besides a hacker is incomprehensible. A hacker should use the right tool for the right job. So, yes, using one tool in place of another (that fits better) makes you less of a hacker, at least in the tool selection aspect. PUppet/chef/capistrano are specialized versions of Make. Rake is a misnomer, as it's just a collect of "tasks". Again, it's a subset of what Makefiles can do. And C, Lisp, Haskell are just specialized versions of what assembly can do. This is beside the point, which is those tools are better for their perspective uses (and the tool mentioned in the post link is not about building C projects).