How should I write a Makefile so that I can compile one of a number of
source files, depending on the architecture the code is compiled for.
foo: foo.o bar.o
How should I write a Makefile so that I can compile one of a number of
source files, depending on the architecture the code is compiled for.
Say, I have a source foo.c and several files implementing a function bar(), in C and in assembly language for several architectures, e.g. bar.c, bar-i386.s, bar-amd64.s, and bar-mips.s.
Currently, my Makefile looks similar to this
foo: foo.o bar.o
$(CC) $(LDFLAGS) -o foo foo.o bar.o $(LDLIBS)
ARCH = $(shell uname -m)
This works as long as I compile natively but not for cross-compilation. So my questions is how to write the Makefile so that I can call
make CC=mips-linux-gcc
and have the correct assembly file compiled and linked into the executable.
ifeq ($(ARCH),x86_64)
bar.o: bar-amd64.o
cp $< $@
else ifeq ($(ARCH),i686)
bar.o: bar-i386.o
cp $< $@
else ifeq ($(ARCH),mips)
bar.o: bar-mips.o
cp $< $@
How should I write a Makefile so that I can compile one of a number of...
source files, depending on the architecture the code is compiled for.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 61:25:04 |
Calls: | 6,654 |
Files: | 12,200 |
Messages: | 5,331,525 |