help-make
[Top][All Lists]
Advanced

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

Re: Compute dependencies from target name


From: Kaz Kylheku (gmake)
Subject: Re: Compute dependencies from target name
Date: Sun, 13 Dec 2020 11:28:32 -0800
User-agent: Roundcube Webmail/0.9.2

On 2020-12-12 20:40, Stefan Monnier wrote:
I'm trying to make a rule along the following lines:

    packages/%.tar.gz : $(shell find packages/% -name '*.el' -print |
sed 's/\.el/.elc/')
        tar -zcf packages/$*.tar.gz packages/$*

I'd say this is wrongheaded, because you're saying that the materials
which belong to this package, for the purposes of computing this
tarball, consist of whatever .el files are scattered in the directory
tree of that package.

What if you have local 'foo.el' just for testing something; it gets
pulled in.

Also, do you want to be running recursive find jobs each time you run
make?

Think about it: this is pretty much the same problem as getting
a bunch of .o files (which depend on corresponding .c) files to
go into their specific lib$(name).a archive file.

How C makefiles do that is (for instance) is that there will be
some variable specific to the library.

  # objects for foo library
  OBJS_foo := foo/parser.o foo/lexer.o ...

The declaration is hand-maintained. If you want a new object in the
foo library, you have to add it there.


The following dummy Makefile full of phony targets produces
the following output:

  $ make
  building lib_foo.a from foo/parser.o foo/lexer.o
  building lib_bar.a from bar/lib.o bar/main.o

The code follows. It uses eval to generate rules, but those are
direct rules, stuffed with the right concrete targets and
prerequisites.

OBJS_foo := foo/parser.o foo/lexer.o
OBJS_bar := bar/lib.o bar/main.o

OBJS := $(OBJS_foo) $(OBJS_bar)
COMPONENTS := foo bar
ARCHIVES := $(patsubst %,lib_%.a,$(COMPONENTS))
OBJS := $(foreach comp,$(COMPONENTS),$(OBJS_$(comp)))

define COMPRULE
lib_$(1).a: $$(OBJS_$(1))
        @echo building $$@ from $$^
endef

# All is phony for purposes of example
.PHONY: all $(ARCHIVES) $(OBJS)

all: $(ARCHIVES)

# generate direct rule for each component
$(foreach comp,$(COMPONENTS),$(eval $(call COMPRULE,$(comp))))




reply via email to

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