help-make
[Top][All Lists]
Advanced

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

Re: Building some targets serially, others in parallel


From: Kaz Kylheku (gmake)
Subject: Re: Building some targets serially, others in parallel
Date: Sat, 22 Aug 2020 22:26:41 -0700
User-agent: Roundcube Webmail/0.9.2

On 2020-08-22 13:46, dan soucy wrote:
takes longer than running `make` serially.

However, if the object files are already built, then `server`, `client`, and
`demo` can be built faster in parallel.

I don't see the big problem here other than the need to represent the
shared object files as if they are a single artifact.

The server, client and demo targets have to depend on some sort of file entity
with a time stamp which, if it is up to date, indicates that the objects
are ready to go.

Note that this would happen naturally if we were, say, putting C .o files
into a .a archive, and then linking the archive:

   libcommon.a: x.o y.o z.o

   server: server.o libcommon.a

   client: client.o libcommon.a

If there is no archive, we can make a fake timestamp file that serves in
its place.

   .PHONY: all
   all: server client

   timestamp: $(SOURCES)
       compiler $? # invoke compiler on all sources newer than timestamp
       touch $@    # create or refresh stamp

   server: server.src timestamp   # server.src is the server source file
       compiler $< -o $(OBJECTS)

   client: client.src timestamp
       compiler $< -o $(OBJECTS)

server and client are done in parallel. They both depend on timestamp,
which is updated once.

If the timestamp doesn't exist, then $? expands to all the $(SOURCES).

Otherwise, it expands to just that subset of them which are newer, so
you get incremental rebuilds. E.g. if $(SOURCES) contains 17 files but
we touched just two, then those two are fed to the compiler to make
the corresponding object files.

Then the server and client rules are triggered.

Don't forget to have your "clean" target remove the timestamp,
and give that file a better name.



reply via email to

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