bug-make
[Top][All Lists]
Advanced

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

gnu make manual tweak/fix to example used in 8.8 The eval Function


From: James Coleman
Subject: gnu make manual tweak/fix to example used in 8.8 The eval Function
Date: Wed, 10 Aug 2005 12:05:17 +0100
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

Hello,

8.8 The eval Function has an example of using eval, foreach, ... and I am
planning on using something a bit like that myself. The example provided
has a two problems and I have a fixed version
 (tested on GNU Make 3.80 on solaris).

You might like to incorporate this fixed version in the manual?
Or something like it.
I know examples are just that and it's a bit pendantic to get them
 fully working but you might find this useful.

Attached here please find a tgz of dummy c files and working Makefile.
(my "working" makefile does @echo $(CC) etc; touch FileThatWouldBeCreated
 so it can be tested in dummy mode)

Two lines had problems: (see original Makefile and modified one (as in tgz) below)
  $(1): $$($(1)_OBJ) $$($(1)_LIBS:%=-l%)
and
     $(LINK.o) $^ $(LDLIBS) -o $@

The first makes e.g. -lpriv and -lprotocol dependancies of server or client.
Probably not what is intended. So it could simply be replaced with:
  $(1): $$($(1)_OBJ)
Usually making the build dependant on the lib files is not done unless
the lib files are also built in the same makefile. But this is what I am
doing so a more interesting replacement would be:
  $(1): $$($(1)_OBJS) $$($(1)_LIBS:%=lib%.a)

On the second line the $(LINK.o) looks quite dodgy.
Maybe it could be defined but I replaced it with $(CC) -r

Okay well, small change, lots of guff from me,
Not too sure where the gnu make manual source is so apologies for not
submitting in patch format :-7

In the hopes it is slightly useful to someone ....

James.

Gnu make manual referred to as is on web here:
http://www.gnu.org/software/make/manual/html_chapter/make_8.html#SEC85



Original example:


PROGRAMS    = server client

server_OBJS = server.o server_priv.o server_access.o
server_LIBS = priv protocol

client_OBJS = client.o client_api.o client_mem.o
client_LIBS = protocol

# Everything after this is generic

.PHONY: all
all: $(PROGRAMS)

define PROGRAM_template
$(1): $$($(1)_OBJ) $$($(1)_LIBS:%=-l%)
ALL_OBJS   += $$($(1)_OBJS)
endef

$(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))

$(PROGRAMS):
   $(LINK.o) $^ $(LDLIBS) -o $@

clean:
   rm -f $(ALL_OBJS) $(PROGRAMS)




Modified "fixed" (but dummy link/lib) version:

CC = gcc
PROGRAMS    = server client

server_OBJS = server.o server_priv.o server_access.o
server_LIBS = priv protocol

client_OBJS = client.o client_api.o client_mem.o
client_LIBS = protocol

# Everything after this is generic

.PHONY: all
all: $(PROGRAMS)

define PROGRAM_template
$(1): $$($(1)_OBJS) $$($(1)_LIBS:%=lib%.a)
ALL_LIB_FLAGS += $$($(1)_LIBS:%=-l%)
ALL_OBJS   += $$($(1)_OBJS)
endef

$(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))

# dummy link and library creation
$(PROGRAMS):
   @echo $(CC) -r $^ $(LDLIBS) -o $@

libpriv.a:
   touch libpriv.a

libprotocol.a:
   touch libprotocol.a

clean:
   rm -f $(ALL_OBJS) $(PROGRAMS) libpriv.a libprotocol.a

Attachment: mksrvcli-sample-dummy-makefile-with-template.tgz
Description: application/compressed


reply via email to

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