4 ms·
> It actually doesn't know anything at all about how to build C, C++, or any other kind of code. I guess it depends on how you define "know", but there are imp
by sebcat 9y ago
> It actually doesn't know anything at all about how to build C, C++, or any other kind of code.
I guess it depends on how you define "know", but there are implicit rules.
$ cat foo.c
#include <stdio.h>
int main() {
printf("Hello\n");
return 0;
}
$ cat Makefile
foo: foo.c
$ make
cc -O2 -pipe foo.c -o foo
$ ./foo
Hello
- peterwwillis 9y agoYeah. There is a metric crap-ton of the design of Make that is solely for the purpose of compiling and linking and document processing. That's actually part of what makes it annoying to use it for projects other than C or C++, when you don't need to compile or transform or depend on different formats.
- rschloming 9y agoThe core of make is really just a control flow model that understands file dependencies as a first class thing, and permits arbitrary user supplied actions to be specified to update those files. All those default rules around how to handle C files are really more like a standard library and can be easily overridden as desired. IMHO what makes it annoying for projects other than C or C++ is that there isn't an equivalent portion of makes "standard library" that applies to e.g. java, but this is largely because java went down a different path to develop its build ecosystem. In an alternate reality java tooling might have been designed to work well with make, and then make would have a substantial builtin knowledge base around how to work with java artifacts as well as having a really nice UX for automating custom workflows, but instead java went down the road of creating monolithic build tooling and for a long time java build tooling really sucked at being extensible for custom workflows.
- coliveira 9y agoThe thing about Java is that it has its own dependency system embedded in the compiler. This design decision made it difficult to integrate with a tool like make.
- rschloming 9y agoI don't think having dependencies built into the language and/or compiler means it needs to be difficult to integrate with something like make. In fact gcc has dependency analysis built into it. It just knows how to output that information in a simple format that make can then consume. I feel like this choice has more to do with early java culture and/or constraints as compared to unix/linux. With "the unix way" it is really common to solve a problem by writing two separate programs that are loosely coupled by a simple text based file format. When done well, this approach has a lot of the benefits of well done microservices-style applications built today. By contrast, (and probably for a variety of reasons) this approach was always very rare in early java days. It seemed for a while like the norm was to rewrite everything in java and run it all in one giant JVM in order to avoid JVM startup overhead. ;-) The upshot being you often ended up with a lot more monolithic/tightly coupled designs in Java. (I think this is less true about Java today.)
- LukeShu 9y ago> There is a metric crap-ton of the design of Make that is solely for the purpose of compiling and linking and document processing. Not really. The bit being pointed out here certainly isn't. It's not any special design going on, it's just a built-in library of rules and variables for C/C++/Pascal/Fortran/Modula-2/Assembler/TeX. These rules are no different than if you had typed them in to the Makefile yourself. And if you don't like them, you can say --no-builtin-rules --no-builtin-variables. The only actual bit of C-specific design I can think of is .LIBPATTERNS library searching.
- dima55 9y agoFun fact: your Makefile above is redundant. You can delete it entirely, and the implicit rules you're using here continue to work just fine.
- sebcat 9y agoThat doesn't work for me. Tried with empty Makefile, no Makefile, with make (PMake) and gmake (GNU Make).
- mhei 9y agoTry "make foo" instead of "make"
- sebcat 9y agoAh, that works!
- dima55 9y agoDon't know why that would be. I'm using GNU Make 4.1, but this has worked for years and years as far as I knew. Not a particularly useful feature, so I it doesn't really matter, but you messed up my fun fact. dima@fatty:/tmp$ mkdir dir dima@fatty:/tmp$ cd dir dima@fatty:/tmp/dir$ touch foo.c dima@fatty:/tmp/dir$ make -n foo cc foo.c -o foo dima@fatty:/tmp/dir$ make --version GNU Make 4.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
- therein 9y agoI had fun learning about that.
- klmr 9y agoThen you did something wrong — it definitely works with GNU make (can’t speak for PMake): https://asciinema.org/a/zVu7sYyh7lQZTNAgAsbKUmocr https://asciinema.org/a/zVu7sYyh7lQZTNAgAsbKUmocr