another Makefile fix

Matthew Fluet fluet@CS.Cornell.EDU
Wed, 3 Oct 2001 18:34:30 -0400 (EDT)


> I don't understand why the heroic Makefile voodoo is needed.  If you want
> make to do it instead of make-cm, then just have the .cm file be the target
> and have that run the cmcat.  What is the purpose of the conditional make
> dependency?

Because the mlyacc Makefile looks like this:

all:    $(NAME)

$(NAME): $(NAME).cm $(shell $(MLTON) -stop f $(NAME).cm)
        @echo 'Compiling $(NAME)'
        time $(MLTON) $(FLAGS) $(NAME).cm
        strip $(NAME)
        size $(NAME)

ifeq ($(MAKECMDGOALS),$(NAME).cm)
.PHONY: $(NAME).cm
$(NAME).cm: src/yacc.lex.sml src/yacc.grm.sig src/yacc.grm.sml
        (                                                               \
                echo 'Group is' &&                                      \
                cmcat sources.cm | grep -v 'mlton-stubs-in-smlnj' &&    \
                echo 'call-main.sml';                                   \
        ) >$(NAME).cm
endif

(* more stuff for clean, yacc.lex.sml and friends *)

mlyacc depends on mlyacc.cm and all the files listed in it.

If we eliminate the ifeq... test, then we're back to what started this
discussion: the generated yacc.lex.sml and friends appear fresh, which
cause mlyacc.cm to be made, but some people might not have cmcat
installed.

If we eliminate the ifeq... test and the dependencies of mlyacc.cm on
yacc.lex.sml and friends, then make mlyacc.cm is idempotent when mlyacc.cm
exists.  Furthermore, make mlyacc.cm will fail if mlyacc doesn't exist and
yacc.lex.sml and friends don't exist (i.e., clean sources and I've deleted
mlyacc.cm), because cmcat will fail.

My (selfish) requirement is that make mlyacc.cm really does make a new
mlyacc.cm by invoking cmcat, and that this invocation of cmcat won't fail
because yacc.lex.sml and friends don't exist.  Whereas, make <anything
else> should not make a new mlyacc.cm