:: Re: [DNG] What can be improved in t…
Top Pagina
Delete this message
Reply to this message
Auteur: Edward Bartolo
Datum:  
Aan: Rainer Weikusat
CC: dng
Onderwerp: Re: [DNG] What can be improved in this Makefile?
Hi Rainer,

Thanks for trying to help me.

Rainer wrote:
-------------------------------
SRC := src
TMP := tmp
SRCS := auxiliaries.c signal_functions.c main_gui.c dialog_gui.c
sn-lightweight.c
OBJS := $(addprefix $(TMP)/, $(SRCS:.c=.o))

sn-lightweight: $(OBJS)
        $(CC) $(GTK2FLAGS) -o $@ $^


$(TMP)/%.o: $(SRC)/%.c
        $(CC) $(CFLAGS) -o $@ $<
----------------------------



SRC, TMP and SRCS are macros. The ':=' to me seems equivalent to '='
and in the code snippet you sent me is used as an assignment operator
like '='.

':.c=.o' is telling the interpreting program to iteratively assign the
.c file to $@ and a .o file with the same name to $^.

> OBJS := $(addprefix $(TMP)/, $(SRCS:.c=.o))

addprefix $(TMP) is used to iteratively to prepend 'tmp/' to every
file listed in SRCS.


> sn-lightweight: $(OBJS)
>        $(CC) $(GTK2FLAGS) -o $@ $^

This is telling gcc to take the .o file and link them into an
executable with the name sn-lightweight. The $^ stands for files taken
from OBJS and the $@ stands for sn-lightweight, the target.

> $(TMP)/%.o: $(SRC)/%.c
>        $(CC) $(CFLAGS) -o $@ $<

This time the % is telling gcc to iteratively create a .o file in tmp
taking the source file with the same name from src/.

I think, gcc should take -c to create .o files instead of a complete
executable as you noted in your last email. -c should go in:
> $(TMP)/%.o: $(SRC)/%.c
>        $(CC) $(CFLAGS) -c $@ $<



Thanks, Edward.

On 21/03/2016, Rainer Weikusat <rainerweikusat@???> wrote:
> Rainer Weikusat <rainerweikusat@???> writes:
>
> [...]
>
>
>> $(TMP)/%.o: $(SRC)/%.c
>>     $(CC) $(CFLAGS) -o $@ $<

>
> A -c is needed with this command to request that the compile just
> compiles the source file in question without also trying to link it.
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>