3 ms·
The fastest shell is to not use shell special characters. For example, if you say `foo bar >/dev/null` then Make needs to launch your program as `sh -c 'foo bar
by jart 4y ago
The fastest shell is to not use shell special characters. For example, if you say `foo bar >/dev/null` then Make needs to launch your program as `sh -c 'foo bar >/dev/null`. But if you say just `foo bar` then Make can pass that directly to execve(), bypassing the shell entirely. Sometimes I actually do this:
SHELL := /bin/false
Just to make sure my Makefile doesn't use shell syntax. If you want a `.STRICT` mode, then try Landlock Make.
- jwilk 4y agoDoesn't work for me: $ make -v | head -n1 GNU Make 4.3 $ printf 'SHELL := /bin/false\nall:\n\tls\n' > Makefile $ make ls make: *** [Makefile:3: all] Error 1
- jart 4y agoI completely forgot that the GNU Make source code has a check to see if the shell is bourne-compatible (it just strcmp's with sh, bash, and a hard coded list), and then only applies that optimization if it is. I deleted that code in my Landlock Make fork so I could use shells like /bin/false and still get the optimization. So sorry about that! Give it a try with Landlock Make https://github.com/jart/landlock-make https://github.com/jart/landlock-make and https://justine.lol/make/ https://justine.lol/make/
- nrclark 4y agoWoah, interesting! I didn't know that Make could launch programs directly. Is that specific to GNU Make?
- jwilk 4y agoAt least NetBSD make (also used by FreeBSD, and packaged as bmake in some distros) has the same optimization: https://github.com/NetBSD/src/blob/netbsd-9/usr.bin/make/compat.c#L298 https://github.com/NetBSD/src/blob/netbsd-9/usr.bin/make/com...