[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

topological sort

From: Stefan Monnier
Subject: topological sort
Date: Sun, 13 May 2012 22:36:39 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

Some compilers/linkers care about the order in which the files are given
to them.  I currently have a build rule which takes a .depend file,
massages it with a sed script and then passes it to `tsort', but I feel
silly: `make' already has those dependencies at hand, and it knows very
well how to do a topological sort, so it would make a lot more sense if
`make' could do that sorting for me.
Does anyone have an idea how to do it?
For reference, see appended the heart of my current hack.


# OCAMLC wants its object files in the right order so the modules get
# initialized correctly.  Ideally `make' should do this job (it already has
# the dependency info and knows all too weel how to do a topological sort),
# but I don't know how to get `make' to do what I want, so I used some `sed'
# magic to massage the .depend in a form that `tsort' can take.
ORDERED_OBJECTS = $(shell sed -e '/\([^ :]*\.cmo\):/{ : start; s/^\([^ :]*\): 
*\([^ :\\][^ :\\]*\)/\2 \1\n\1:/; t loop2; /\\$$/{; N; s/\\.//; b start}; d; : 
loop2; P; D}; d' .depend | tsort)

foo: $(ORDERED_OBJECTS) # $(
        $(OCAMLC) -o $@ $(ORDERED_OBJECTS)

        $(OCAMLDEP) $(FILES) > .depend

-include .depend

reply via email to

[Prev in Thread] Current Thread [Next in Thread]