Ralf Wildenhues wrote:
Hello,
* tns1 wrote on Thu, Sep 04, 2008 at 10:12:27PM CEST:
I have source tree with many folders containing many .o files each. I
wish to partially link the contents of each folder so I have one
combined .o file (library?) for each folder. These combined (object
files?, libraries?) will go thru a final link step at a later stage in
the build.
The combined .o files are just objects again, not libraries.
Is there anything special about how this partial linking or can I just
do something like:
$(OBJS)=a.o b.o c.o
mylink.b : $(OBJS)
ld -o mylink.b $(OBJS)
BTW, why mylink.b and not mylink.o? I think some vendor ld's may warn
about this, or fail to do the right thing. Also, for partial linking
you would need to pass -r to ld.
For each sub-folder I ended up with a makefile like:
OBJS=a.o b.o c.o
NEWOBJ=newobjA.lk
FLAGS=-fsigned-char -O0 -mthumb -mthumb-interwork
all: $(OBJS) $(NEWOBJ)
$(OBJS): %o : %c
arm-elf-gcc $(FLAGS) -I ./../includes -c -o $@ $<
$(NEWOBJ) : $(OBJS)
arm-elf-ld -r -o ./../$@ $(OBJS)
clean:
rm *.o
Does building in this multi-tiered fashion result in a larger final
image, or can the final link still remove redundancies?
You did not state what the final link will create.
The final link is a program image. For this main folder link I am using
something like this, although I don't have a clean link yet because my
script is not complete:
MOREOBJS=newobjA.lk newobjB.lk newobjC.lk
myarm.img : $(MOREOBJS)
arm-elf-ld -o $@ -T armlink.ld -Map myarm.map $(MOREOBJS) $(OBJS)
clean:
rm *.img
FWIW, depending on whether you can assume GNU ld, GNU make, or whether
you would be willing to use libtool, some optimizations and/or
simplifications may be applied to your general setup.
(I can expand but then please specify on which.)
This is a cross platform port, and the two-tier link is legacy from the
old tools. My main concern is that I have all the basic steps and I am
not missing something crucial (such as -r and -fsigned-char).