News for hackers. Stuff that matters.
Re:The Makefile I use with JavaScript projects by sebcat on Wednesday February 28, 2018 @12:38PM (#16484853)
> 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
Re:The Makefile I use with JavaScript projects by dima55 on Wednesday February 28, 2018 @12:47PM (#16484952)
Fun fact: your Makefile above is redundant. You can delete it entirely, and the implicit rules you're using here continue to work just fine.
Re:The Makefile I use with JavaScript projects by LukeShu on Wednesday February 28, 2018 @02:21PM (#16485872)
Not quite: it does declare "foo" as the default target. Without the Makefile, it would be necessary to type `make foo` instead of just `make`.
Re:The Makefile I use with JavaScript projects by nickez on Wednesday February 28, 2018 @01:37PM (#16485435)
The built in rule to copy 'build.sh' to 'build' and make it executable is also interesting.. confused the hell out of me
Re:The Makefile I use with JavaScript projects by sebcat on Wednesday February 28, 2018 @12:52PM (#16485001)
That doesn't work for me. Tried with empty Makefile, no Makefile, with make (PMake) and gmake (GNU Make).
Re:The Makefile I use with JavaScript projects by dima55 on Wednesday February 28, 2018 @12:57PM (#16485043)
Don'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.
Re:The Makefile I use with JavaScript projects by therein on Wednesday February 28, 2018 @01:11PM (#16485179)
I had fun learning about that.
Re:The Makefile I use with JavaScript projects by mhei on Wednesday February 28, 2018 @12:56PM (#16485030)
Try "make foo" instead of "make"
Re:The Makefile I use with JavaScript projects by sebcat on Wednesday February 28, 2018 @12:59PM (#16485066)
Ah, that works!
Re:The Makefile I use with JavaScript projects by klmr on Wednesday February 28, 2018 @01:14PM (#16485211)
Then you did something wrong — it definitely works with GNU make (can’t speak for PMake):

https://asciinema.org/a/zVu7sYyh7lQZTNAgAsbKUmocr

Re:The Makefile I use with JavaScript projects by oso2k on Wednesday February 28, 2018 @01:04PM (#16485107)
Yeah

   make foo.c

Should just work. No makefile needed.
Re:The Makefile I use with JavaScript projects by majewsky on Wednesday February 28, 2018 @01:17PM (#16485251)
No, `make foo`. You need to state the target, not the input.
Re:The Makefile I use with JavaScript projects by oso2k on Wednesday February 28, 2018 @03:37PM (#16486635)
You're correct.

   make foo

or

   make foo.o
Re:The Makefile I use with JavaScript projects by peterwwillis on Wednesday February 28, 2018 @12:45PM (#16484927)
Yeah. 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.
Re:The Makefile I use with JavaScript projects by rschloming on Wednesday February 28, 2018 @12:54PM (#16485014)
The 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.

Re:The Makefile I use with JavaScript projects by coliveira on Wednesday February 28, 2018 @04:32PM (#16487206)
The 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.
Re:The Makefile I use with JavaScript projects by rschloming on Wednesday February 28, 2018 @05:41PM (#16487900)
I 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.)

Re:The Makefile I use with JavaScript projects by LukeShu on Wednesday February 28, 2018 @02:36PM (#16486022)
> 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.