Skip to content

Commit

Permalink
make: improve cross compilation support
Browse files Browse the repository at this point in the history
resolves #14.

Signed-off-by: Vanya A. Sergeev <v@sergeev.io>
  • Loading branch information
jhlimatplk authored and vsergeev committed Oct 1, 2019
1 parent 085752d commit 742d983
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ clean:
###########################################################################

tests/%: tests/%.c $(LIB)
$(CC) $(CFLAGS) $(LDFLAGS) $< $(LIB) -o $@ -lpthread
$(CROSS)$(CC) $(CFLAGS) $(LDFLAGS) $< $(LIB) -o $@ -lpthread

###########################################################################

Expand All @@ -42,8 +42,8 @@ $(OBJDIR):
mkdir $(OBJDIR)

$(LIB): $(OBJECTS)
ar rcs $(LIB) $(OBJECTS)
$(CROSS)$(AR) rcs $(LIB) $(OBJECTS)

$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@
$(CROSS)$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,18 @@ $

### Cross-compilation

Set the `CC` environment variable with the cross-compiler when calling make:
Set the `CROSS` and `CC` environment variables with the cross-compiler prefix and compiler, respectively, when calling make:

``` console
$ CC=arm-linux-gcc make clean all tests
$ CROSS=arm-linux- CC=gcc make clean all tests
rm -rf periphery.a obj tests/test_serial tests/test_i2c tests/test_mmio tests/test_spi tests/test_gpio
mkdir obj
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC -c src/gpio.c -o obj/gpio.o
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC -c src/spi.c -o obj/spi.o
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC -c src/i2c.c -o obj/i2c.o
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC -c src/mmio.c -o obj/mmio.o
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC -c src/serial.c -o obj/serial.o
ar rcs periphery.a obj/gpio.o obj/spi.o obj/i2c.o obj/mmio.o obj/serial.o
arm-linux-ar rcs periphery.a obj/gpio.o obj/spi.o obj/i2c.o obj/mmio.o obj/serial.o
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC tests/test_serial.c periphery.a -o tests/test_serial
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC tests/test_i2c.c periphery.a -o tests/test_i2c
arm-linux-gcc -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast -fPIC tests/test_mmio.c periphery.a -o tests/test_mmio
Expand Down

0 comments on commit 742d983

Please sign in to comment.