🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by GSCOTT Wed, 18 Nov 1992 03:59
(none)
#1110
Author: GSCOTT
Date: Wed, 18 Nov 1992 03:59
74 lines
2221 bytes
This problem is with make 3.62 running on AIX 3.2.2

Problem:  improper expansion of "$<" when using the following makefile.

---

CC = gcc
CFLAGS = -g -Wall
LIBS = -lm
PROG = lfa_null

OBJS = lfan_main.o lfan_track.o lfan_bf.o tb_bf.o
SOURCES = lfan_main.c lfan_track.c lfan_bf.c tb_bf.c
INCLUDES = lfa_null.h tb.h

all: $(PROG)

$(PROG): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)

$(OBJS): $(SOURCES) $(INCLUDES)
	$(CC) $(CFLAGS) -c $<

---

Below is a script illustrating the problem.
/bin/make is the default AIX make
/usr/local/gnu/make is gnu make 3.62

---

$ /bin/make -n

gcc -g -Wall -c lfan_main.c
gcc -g -Wall -c lfan_track.c
gcc -g -Wall -c lfan_bf.c
gcc -g -Wall -c tb_bf.c
gcc -g -Wall -o lfa_null lfan_main.o lfan_track.o lfan_bf.o tb_bf.o -lm

$ /usr/local/gnu/make -n

gcc -g -Wall -c lfan_main.c
gcc -g -Wall -c lfan_main.c
gcc -g -Wall -c lfan_main.c
gcc -g -Wall -c lfan_main.c
gcc -g -Wall -o lfa_null lfan_main.o lfan_track.o lfan_bf.o tb_bf.o -lm

---

Below is a script of what happens when the files must be retrieved
with RCS.  Note, it retrieves all of the correct files, but still only
tries to compile the first file in OBJS

---

$ /usr/local/gnu/make -n

test -f lfan_main.c || co  RCS/lfan_main.c,v lfan_main.c
test -f lfan_track.c || co  RCS/lfan_track.c,v lfan_track.c
test -f lfan_bf.c || co  RCS/lfan_bf.c,v lfan_bf.c
test -f tb_bf.c || co  RCS/tb_bf.c,v tb_bf.c
test -f lfa_null.h || co  RCS/lfa_null.h,v lfa_null.h
test -f tb.h || co  RCS/tb.h,v tb.h
gcc -g -Wall -c lfan_main.c
gcc -g -Wall -c lfan_main.c
gcc -g -Wall -c lfan_main.c
gcc -g -Wall -c lfan_main.c
gcc -g -Wall  -o lfa_null lfan_main.o lfan_track.o lfan_bf.o tb_bf.o -lm

---

George Scott
gms2@po.cwru.edu
gscott@manvm1.vnet.ibm.com
Re: (none)
#1131
Author: Jason Merrill
Date: Sat, 21 Nov 1992 23:27
72 lines
2661 bytes
>>>> GSCOTT@manvm1.vnet.ibm.COM writes:

>OBJS = lfan_main.o lfan_track.o lfan_bf.o tb_bf.o
>SOURCES = lfan_main.c lfan_track.c lfan_bf.c tb_bf.c

>$(OBJS): $(SOURCES) $(INCLUDES)
>	$(CC) $(CFLAGS) -c $<

>$ /bin/make -n

>gcc -g -Wall -c lfan_main.c
>gcc -g -Wall -c lfan_track.c
>...

>$ /usr/local/gnu/make -n

>gcc -g -Wall -c lfan_main.c
>gcc -g -Wall -c lfan_main.c
>...

This is not a bug in gcc, but rather a documented feature :).  If you look
in the GNU Make manual (make.texi), you will see that $< is always set to
the FIRST dependency, not to the dependency with the same name as the
target.  Consider the line

>$(OBJS): $(SOURCES) $(INCLUDES)

AIX make is interpreting it one of three ways:

If there are multiple targets and multiple dependencies, then a given
target depends on:

1) The dependency at the same index, plus all dependencies to which no
   target corresponds.
2) The dependency with the same name (minus extension) as the target, plus
   all dependencies to which no target corresponds.

Try rearranging the SOURCES line in your makefile and see if AIX make still
does the right thing; that will tell you which rule it is using.

GNU make is interpreting it as follows:

If there are multiple targets and multiple dependencies, then a given
target depends on ALL of the dependencies.

I think that the GNU behavior makes perfect sense.  To make your Makefile
work under GNU make, you must use an implicit rule.  Change the lines

>$(OBJS): $(SOURCES) $(INCLUDES)
>	$(CC) $(CFLAGS) -c $<

to

%.o: %.c $(INCLUDES)
	$(CC) $(CFLAGS) -c $<

Of course, this won't work under AIX make.  This will probably work under
both:

.c.o: $(INCLUDES)
	$(CC) $(CFLAGS) -c $<

>Below is a script of what happens when the files must be retrieved
>with RCS.  Note, it retrieves all of the correct files, but still only
>tries to compile the first file in OBJS

Yes, because it is using an implicit rule to retrieve the files from RCS,
but not to compile them.

--
Jason Merrill					jason@jarthur.claremont.edu
This is a self-referential .sig which is not particularly interesting.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads