Makefile: fix src/api compilation.

Submitted by Érico Rolim on July 23, 2020, 3:44 a.m.

Details

Message ID 20200723034433.24004-1-ericonr@disroot.org
State New
Series "Makefile: fix src/api compilation."
Headers show

Commit Message

Érico Rolim July 23, 2020, 3:44 a.m.
Adding all .o files in src/api to the api/main.OBJ variable led to them
being included twice when linking api/main.exe, which failed with a
double definition of the main() function. This can be tested by removing
the failing definitions from unistdc.c and running make.
---

This is a patch for libc-test.

 Makefile | 1 -
 1 file changed, 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/Makefile b/Makefile
index 86b6ff5..683c850 100644
--- a/Makefile
+++ b/Makefile
@@ -113,7 +113,6 @@  $(B)/common/mtest.o: src/common/mtest.h
 $(math.OBJS): src/common/mtest.h
 
 $(B)/api/main.exe: $(api.OBJS)
-api/main.OBJS:=$(api.OBJS)
 $(api.OBJS):$(B)/common/options.h
 $(api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
 

Comments

Szabolcs Nagy July 24, 2020, 2:33 p.m.
* Érico Rolim <ericonr@disroot.org> [2020-07-23 00:44:33 -0300]:
> Adding all .o files in src/api to the api/main.OBJ variable led to them
> being included twice when linking api/main.exe, which failed with a
> double definition of the main() function. This can be tested by removing
> the failing definitions from unistdc.c and running make.

thanks.

> ---
> 
> This is a patch for libc-test.
> 
>  Makefile | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 86b6ff5..683c850 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -113,7 +113,6 @@ $(B)/common/mtest.o: src/common/mtest.h
>  $(math.OBJS): src/common/mtest.h
>  
>  $(B)/api/main.exe: $(api.OBJS)
> -api/main.OBJS:=$(api.OBJS)
>  $(api.OBJS):$(B)/common/options.h
>  $(api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700

this is not the right fix,

the problem is that api/main.o is duplicated:
once because of the %.exe: %.o rule and once
in the api/main.OBJS.

but all other api/*.o files are not duplicated
and should be linked (so we link test all
referenced symbols not just include header test).

i'm considering doing

 $(B)/%.exe: $(B)/%.o
-       $(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $< $($*.OBJS) $(LDLIBS) $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err
+       $(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $(sort $< $($*.OBJS)) $(LDLIBS) $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err

(note: the make sort function removes duplicates)
Érico Rolim July 24, 2020, 6:23 p.m.
On Fri Jul 24, 2020 at 1:33 PM -03, Szabolcs Nagy wrote:
> * Érico Rolim <ericonr@disroot.org> [2020-07-23 00:44:33 -0300]:
> > Adding all .o files in src/api to the api/main.OBJ variable led to them
> > being included twice when linking api/main.exe, which failed with a
> > double definition of the main() function. This can be tested by removing
> > the failing definitions from unistdc.c and running make.
>
> thanks.
>
> > ---
> > 
> > This is a patch for libc-test.
> > 
> >  Makefile | 1 -
> >  1 file changed, 1 deletion(-)
> > 
> > diff --git a/Makefile b/Makefile
> > index 86b6ff5..683c850 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -113,7 +113,6 @@ $(B)/common/mtest.o: src/common/mtest.h
> >  $(math.OBJS): src/common/mtest.h
> >  
> >  $(B)/api/main.exe: $(api.OBJS)
> > -api/main.OBJS:=$(api.OBJS)
> >  $(api.OBJS):$(B)/common/options.h
> >  $(api.OBJS):CFLAGS+=-pedantic-errors -Werror -Wno-unused -D_XOPEN_SOURCE=700
>
> this is not the right fix,
>
> the problem is that api/main.o is duplicated:
> once because of the %.exe: %.o rule and once
> in the api/main.OBJS.
>
> but all other api/*.o files are not duplicated
> and should be linked (so we link test all
> referenced symbols not just include header test).
>
> i'm considering doing
>
> $(B)/%.exe: $(B)/%.o
> - $(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $< $($*.OBJS) $(LDLIBS)
> $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err
> + $(CC) $(LDFLAGS) $($*.LDFLAGS) -o $@ $(sort $< $($*.OBJS)) $(LDLIBS)
> $($*.LDLIBS) 2>$@.ld.err || echo BUILDERROR $@; cat $@.ld.err
>
> (note: the make sort function removes duplicates)

Didn't know about that! This worked here as a fix, thanks.