From: Rui Maciel on
Is it possible to define targets from a given list? For example, let's say that I have the
following files:

a.c++, a.h++
b.c++, b.h++
c.c++, c.h++


And let's say we have the following list defined in a makefile:

LIST = a b c

Is it possible to built the following targets from that list?

a.o: a.c++ a.h++
gcc -c a.c++ -o a.o


b.o: b.c++ b.h++
gcc -c b.c++ -o b.o


c.o: c.c++ c.h++
gcc -c c.c++ -o c.o


Thanks in advance,
Rui Maciel
From: Pascal J. Bourguignon on
Rui Maciel <rui.maciel(a)gmail.com> writes:

> Is it possible to define targets from a given list? For example, let's say that I have the
> following files:
>
> a.c++, a.h++
> b.c++, b.h++
> c.c++, c.h++
>
>
> And let's say we have the following list defined in a makefile:
>
> LIST = a b c
>
> Is it possible to built the following targets from that list?
>
> a.o: a.c++ a.h++
> gcc -c a.c++ -o a.o
>
>
> b.o: b.c++ b.h++
> gcc -c b.c++ -o b.o
>
>
> c.o: c.c++ c.h++
> gcc -c c.c++ -o c.o
>


Just write:

%.o : %.c++ %.h++
gcc -c %.c++ -o %.o


and have a target depending on the .o files you want:

all : a.o b.o c.o


From your LIST, I don't know if it's possible to derive with GNU make
builtins a.o b.o c.o, but from:

SOURCES=a.c++ b.c++ c.c++

or

SOURCES=$(shell echo *.c++)

you could build:

OBJECTS=$(SOURCES:.c++=.o)

and then just write:

all:$(OBJECTS)


To sum up:

#------------------------------------
PGM=mypgm
SOURCES=$(shell echo *.c++)
LIBS=-lm # ...
#------------------------------------
OBJECTS=$(SOURCES:.c++=.o)
all : $(PGM)
$(PGM) : $(OBJECTS)
g++ -o $(PGM) $(OBJECTS) $(LIBS)
%.o:%.c++ %.h++
g++ -c $< -o $@
clean:
- rm -f *.o $(PGM)
#------------------------------------


So, with only test.c++ and test.h++ in the directory with this Makefile
you can type:

make -k

and have make execute:

g++ -c test.c++ -o test.o
g++ -o mypgm test.o -lm




--
__Pascal Bourguignon__
From: Rui Maciel on
Pascal J. Bourguignon wrote:

> Rui Maciel <rui.maciel(a)gmail.com> writes:
>
>> Is it possible to define targets from a given list? For example, let's
>> say that I have the following files:
>>
>> a.c++, a.h++
>> b.c++, b.h++
>> c.c++, c.h++
>>
>>
>> And let's say we have the following list defined in a makefile:
>>
>> LIST = a b c
>>
>> Is it possible to built the following targets from that list?
>>
>> a.o: a.c++ a.h++
>> gcc -c a.c++ -o a.o
>>
>>
>> b.o: b.c++ b.h++
>> gcc -c b.c++ -o b.o
>>
>>
>> c.o: c.c++ c.h++
>> gcc -c c.c++ -o c.o
>>
>
>
> Just write:
>
> %.o : %.c++ %.h++
> gcc -c %.c++ -o %.o
>
>
> and have a target depending on the .o files you want:
>
> all : a.o b.o c.o
>
>
> From your LIST, I don't know if it's possible to derive with GNU make
> builtins a.o b.o c.o, but from:
>
> SOURCES=a.c++ b.c++ c.c++
>
> or
>
> SOURCES=$(shell echo *.c++)
>
> you could build:
>
> OBJECTS=$(SOURCES:.c++=.o)
>
> and then just write:
>
> all:$(OBJECTS)
>
>
> To sum up:
>
> #------------------------------------
> PGM=mypgm
> SOURCES=$(shell echo *.c++)
> LIBS=-lm # ...
> #------------------------------------
> OBJECTS=$(SOURCES:.c++=.o)
> all : $(PGM)
> $(PGM) : $(OBJECTS)
> g++ -o $(PGM) $(OBJECTS) $(LIBS)
> %.o:%.c++ %.h++
> g++ -c $< -o $@
> clean:
> - rm -f *.o $(PGM)
> #------------------------------------
>
>
> So, with only test.c++ and test.h++ in the directory with this Makefile
> you can type:
>
> make -k
>
> and have make execute:
>
> g++ -c test.c++ -o test.o
> g++ -o mypgm test.o -lm

I've tried it out and it appears that it works just as expected. Good stuff.


Thanks for the help,
Rui Maciel
From: Thad Smith on
Rui Maciel wrote:
> Pascal J. Bourguignon wrote:
>
>> Rui Maciel <rui.maciel(a)gmail.com> writes:
>>
>>> Is it possible to define targets from a given list? For example, let's
>>> say that I have the following files:
>>>
>>> a.c++, a.h++
>>> b.c++, b.h++
>>> c.c++, c.h++
>>>
>>>
>>> And let's say we have the following list defined in a makefile:
>>>
>>> LIST = a b c
>>>
>>> Is it possible to built the following targets from that list?
>>>
>>> a.o: a.c++ a.h++
>>> gcc -c a.c++ -o a.o
>>>
>>>
>>> b.o: b.c++ b.h++
>>> gcc -c b.c++ -o b.o
>>>
>>>
>>> c.o: c.c++ c.h++
>>> gcc -c c.c++ -o c.o

Yes, but does that express all the dependencies? Does b.o depend on a.h++, for
example?

--
Thad