It's unfortunate that most programmers only experience with make is automake/autoconf. This is fantastic.
Using Make – writing less Makefile
11–20 of 200 posts
Re: Using Make – writing less Makefile
#12If you want to write less makefile, you don't need to define foo. `foo` is an implicit target if foo.c is present. You can use make in this form without a makefile even: ~ % echo '#include \nvoid main() { printf("OHAI\\n"); }' > ohai.c ~ % make CFLAGS=-DDEFINE_ME_A_MAKEFILE ohai cc -DDEFINE_ME_A_MAKEFILE ohai.c -o ohai ~ % ./ohai OHAI
In that case why call make at all?
Re: Using Make – writing less Makefile
#13With gnu make you don't even need OBJs for a simple directory in which all the .c files are compiled: .SECONDEXPANSION foo: $$(patsubst %.c,%.o,$$(wildcard *.c)) $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ Admittedly you can end up with short, very general Makefiles that look like they were a Prolog program written in TECO. But the advantage is that they are general so don't need to be fiddled with as your project grows. I m…
I know we don't do general-purpose "I like this" comments on HN, but, as a Christmas treat to myself, I'm just going to say how happy this little sentence fragment makes me.
Re: Using Make – writing less Makefile
#14Re: Using Make – writing less Makefile
#15It's unfortunate that most programmers only experience with make is automake/autoconf. This is fantastic.
Autoconf, that's the thing that spends time making sure that my software can be built on BeOS and A/UX?
Re: Using Make – writing less Makefile
#16 I think an important thing to know about make(1) is that you don't need to write a Makefile to use it. There are default rules for C, C++ and probably Fortran.
And then it goes against its own spirit... You don't need this: OBJS = foo.o bar.o baz.o
foo: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
Just do: foo: foo.o bar.o baz.o
It respects LDFLAGS and LDLIBS.Re: Using Make – writing less Makefile
#17I like the man page format each post has on this website. A little hard to read, but very unique.
I guess it's fitting for a tool (make) that is also unergonomic by today's standards.
Re: Using Make – writing less Makefile
#18Re: Using Make – writing less Makefile
#19With gnu make you don't even need OBJs for a simple directory in which all the .c files are compiled: .SECONDEXPANSION foo: $$(patsubst %.c,%.o,$$(wildcard *.c)) $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ Admittedly you can end up with short, very general Makefiles that look like they were a Prolog program written in TECO. But the advantage is that they are general so don't need to be fiddled with as your project grows. I m…
.SECONDEXPANSION
foo: $$(patsubst %.c,%.o,$$(wildcard *.c))
No need to tell Make how to invoke a C compiler for the billionth time.Re: Using Make – writing less Makefile
#20The article reads I think an important thing to know about make(1) is that you don't need to write a Makefile to use it. There are default rules for C, C++ and probably Fortran. And then it goes against its own spirit... You don't need this: OBJS = foo.o bar.o baz.o foo: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@ Just do: foo: foo.o bar.o baz.o It respects LDFLAGS and LDLIBS.
This would only make sense if the only rule that needed the list was that one that builds, no install/uninstall/package/modify/audit/hash/clean/etc, which is never the case. You also don't want to use globbing in place of an explicit list either.