-4

GNU Make under MinGW is known to be very slow under certain conditions due to how it executes implicit rules and how Windows exposes file information (per "MinGW “make” starts very slowly").

That previous question and all other resources on the issue that I've found on the internet suggest working around the problem by disabling implicit rules entirely with the -r flag. But is there another way?

I have a "portable" Makefile that relies on them, and I'd like to make it so that it does not take around a minute to start it up each time, rather than having to get the Makefile owner to alter it just for me.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • 1
    The question is why is it taking a long time to start up. The default rules and variables certainly matter but plenty of other things matter too. Cygwin and MinGW are not speedy at anything from what I've seen/heard so that doesn't help. Is the makefile doing anything fancy with `$(shell)` or `$(wildcard)`, etc.? – Etan Reisner Jan 27 '15 at 17:54
  • I read the linked question. It indicates *one* thing that can speed up make starting. It is by *far* not the only thing that can slow down make processing. The amount of work make does (even when no building is required) is dependent on the contents of the makefile. – Etan Reisner Jan 27 '15 at 18:15

1 Answers1

5

You should use make -d to see all the things make is doing and try to see where the time is going. One common reason for lengthy make times are match-anything rules which are used to determine whether or not a makefile needs to be rebuilt. Most of the match-anything rules CAN be removed; they're rarely needed anymore.

You can add this to your makefile and see if it helps:

%:: %,v
%:: RCS/%,v
%:: RCS/%
%:: s.%
%:: SCCS/s.%

And, if you don't need to auto-create your makefile you can add:

Makefile: ;

(also put any included makefiles there that you don't need to auto-create).

ETA It seems your real question can be summed up as, "why does make take so much longer to start on Windows than on Linux, and what can I do to fix that without changing makefiles?"

The answer is, nothing. Make does exactly the same amount of work on both Windows and Linux: there are no extra rules or procedures happening on Windows that could be removed. The problem is that Windows NTFS is slower than typical Linux filesystems for these lookups. I know of no system setting, etc. that will fix this problem. Your only choice is to get make to do less work so that it's faster, and the only way to do that is by removing built-in rules you don't need.

If the problem is you really don't want to edit the actual makefiles, that's simple enough to solve: just write the rules above into a small separate makefile, maybe something like speedup.mk, then set the environment variable MAKEFILES=speedup.mk before invoking make. Make will parse that makefile as well without you having to change any makefiles.

bobbogo
  • 14,989
  • 3
  • 48
  • 57
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • No, I already know _why_ it's slow (follow the link in the question). What I'm asking now is whether there's another workaround or fix. – Lightness Races in Orbit Jan 27 '15 at 18:09
  • @LightnessRacesinOrbit You don't know (unless you've profiled and didn't tell us) you have a theory that it might be the built-in rules (again unless you know that using `-r` in your case speeds things up immensely). Also the suggestions in this post *are* removing a number of the built-in rules manually. – Etan Reisner Jan 27 '15 at 18:16
  • 1
    I _gave_ you a fix. Did you try the changes I suggested? Did they work? Did you try my suggestion of running `make -d` to see what things make is doing, that you might be able to avoid? If you're not going to try what we suggest and provide feedback on how it worked for you then we can't help you. – MadScientist Jan 27 '15 at 18:54
  • 1
    @LightnessRacesinOrbit The solution presented here removes many of the most expensive built-in rules without disabling all of the built-in rules. Which, it seems, is *exactly* what you said you were looking for. If it isn't, and you still don't want to accept that any other possible things might be contributing to startup time (or this isn't a question about your situation and simply a more general one), then explain again please. Or were you referring to the "alter the Makefile for me" bit? – Etan Reisner Jan 27 '15 at 20:31
  • @EtanReisner: My hope is that the _root cause_ can be fixed. Something that doesn't involve changing the Makefile. Something that either stops MinGW's GNU Make from generating more rules than the "native" Linux versions generate, or that makes Windows behave sensibly w.r.t. executing the MinGW version. Take the root cause of the linked question, and I'm asking whether it can be fixed in a way that does not involve changing the makefile. – Lightness Races in Orbit Jan 27 '15 at 20:56
  • 1
    Do you have reason to believe make on Windows *has* more rules? I don't. I do believe, as indicated in that linked answer, that Windows (at least as used by MinGW make) is *much* slower at processing the file checks that those rules involve. As such, disabling the rules is the solution. Short of finding an alternative (quicker) way to test for that and modifying make itself or fixing Windows itself to be faster at the required checks. – Etan Reisner Jan 27 '15 at 21:03
  • @Etan Reisner is correct. The list of built-in rules in the MinGW version of GNU make are virtually identical to the Linux version. If your real question is "why does the MinGW version of GNU make take longer to start up than the Linux version, given the same makefile", then that's what you should ask. The answer to that is (as I understand it) that the Windows NTFS filesystem is not as efficient at lookup or caching as the typical Linux filesystem, and so the same number of file lookups takes longer on Windows. – MadScientist Jan 27 '15 at 21:20
  • You can easily see this by running `make -d` on both systems and verifying that the amount of output generated is the same. So the answer to your question is no, unless you're aware of a way to make NTFS significantly faster at the kinds of operations make does than it is today, changing the makefile is your only option for speedup. – MadScientist Jan 27 '15 at 21:23
  • @MadScientist: Could you please write that as an answer? – Lightness Races in Orbit Jan 28 '15 at 00:43
  • Finally got around to trying this out. It's _better_ (compare [second and third runs](http://pastebin.com/t126W9bj)) but still not quite there. I will see what other rules I can remove. In the meantime, do you have any quick suggestions as to that? And shall we clean-up old comments? /cc @EtanReisner – Lightness Races in Orbit May 09 '15 at 17:49
  • Suggestions as to what? What rules to remove? If you have a sufficiently new version of GNU make (4.0 or above) you can disable all built-in rules by adding `MAKEFLAGS += -r`. If you don't you'll have to combine the above-mentioned rules with `.SUFFIXES:` to disable the rest of the built-in rules. Use `make -d` to see what implicit rules make is using that you don't expect to delete more, if there are any. – MadScientist May 09 '15 at 19:48