Re: [dev] Reasonable Makefiles

From: Roberto E. Vargas Caballero <>
Date: Tue, 11 Feb 2014 17:02:36 +0100

> The disadvantage of that is that having files called Makefile and
> makefile in the same directory, users may well look for the former to
> make changes, leading to confusion. I certainly didn't know that

Yes, it is true, you have to be carefull with this point, but usually
is not a problem.

> Also, having created the makefile, does the Makefile invoke make
> again automatically, or does the user have to re-enter their

user has to write something like:

        make dep

and then the new makefile is created. Next time user executes 'make' then
makefile will be used instead of Makefile. I have these rules:

                (cat Makefile ; \
                for i in $(OBJS:.o=.c) ;\
                do \
                        $(CC) $(CPPFLAGS) $(CFLAGS) -MM $$i ; \
                done) > makefile

        disctclean: clean
                rm -f makefile

You can do something similar using only a Makefile and these rules:

                (echo '#Cut here'
                for i in $(OBJS:.o=.c) ;\
                do \
                        $(CC) $(CPPFLAGS) $(CFLAGS) -MM $$i ;\
                done) >> Makefile ;\

        distclean: clean
                printf "/^#Cut here/,$d\nw\nq\n" | ed -s Makefile

but then you will have problems with your control version system.
You can avoid the confusion of Makefile and makefile if you use other
names: for example (and it generates Makefile, so the user knows
that he is working with a generated Makefile). I usually don't like this
way because the user should read the documentation and see the
Makefile/makefile issue.


Roberto E. Vargas Caballero
Received on Tue Feb 11 2014 - 17:02:36 CET

This archive was generated by hypermail 2.3.0 : Tue Feb 11 2014 - 17:12:06 CET