Automate some building of the C library

This commit is contained in:
Paul Jimenez 2018-09-15 17:40:33 -04:00
parent e4b410b70d
commit 60d5222873

View File

@ -15,7 +15,8 @@ EFM32_DEBUGGER= -s 440083537 --device EFM32JG1B200F128GM32
src = $(wildcard pc/*.c) $(wildcard fido2/*.c) $(wildcard crypto/sha256/*.c) crypto/tiny-AES-c/aes.c
obj = $(src:.c=.o) uECC.o
LDFLAGS = -Wl,--gc-sections ./tinycbor/lib/libtinycbor.a
LIBCBOR = tinycbor/lib/libtinycbor.a
LDFLAGS = -Wl,--gc-sections $(LIBCBOR)
CFLAGS = -O2 -fdata-sections -ffunction-sections
INCLUDES = -I./tinycbor/src -I./crypto/sha256 -I./crypto/micro-ecc/ -Icrypto/tiny-AES-c/ -I./fido2/ -I./pc -I./fido2/extensions
@ -24,11 +25,20 @@ CFLAGS += $(INCLUDES)
name = main
.PHONY: all
all: main
cbor:
tinycbor/Makefile crypto/tiny-AES-c/aes.h:
git submodule update --init
.PHONY: cbor
cbor: $(LIBCBOR)
$(LIBCBOR): tinycbor/Makefile
cd tinycbor/ && $(MAKE) clean && $(MAKE) -j8
.PHONY: test
test: testgcm
efm8prog:
@ -51,10 +61,19 @@ efm32bootprog:
cd './targets/efm32boot/GNU ARM v7.2.1 - Debug' && $(MAKE) all
commander flash './efm32boot/GNU ARM v7.2.1 - Debug/efm32boot.hex' $(EFM32_DEBUGGER) --masserase
$(name): $(obj)
crypto/tiny-AES-c/aes.o:
if ! grep "^#define AES256" crypto/tiny-AES-c/aes.h ; then \
echo "Fixing crypto/tiny-AES-c/aes.h" ;\
sed -i 's/^#define AES1\/\/#define AES1; s/^\/*#define AES256/#define AES256/' crypto/tiny-AES-c/aes.h ;\
fi
$(CC) $(CFLAGS) -c -o crypto/tiny-AES-c/aes.o crypto/tiny-AES-c/aes.c
$(name): $(obj) $(LIBCBOR)
$(CC) $(LDFLAGS) -o $@ $(obj) $(LDFLAGS)
testgcm: $(obj)
testgcm: $(obj) $(LIBCBOR)
$(CC) -c main.c $(CFLAGS) -DTEST -o main.o
$(CC) -c crypto/aes_gcm.c $(CFLAGS) -DTEST -o crypto/aes_gcm.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDFLAGS)
@ -64,3 +83,9 @@ uECC.o: ./crypto/micro-ecc/uECC.c
clean:
rm -f *.o main.exe main $(obj)
for f in crypto/tiny-AES-c/Makefile tinycbor/Makefile ; do \
if [ -f "$$f" ]; then \
(cd `dirname $$f` ; git co -- .) ;\
fi ;\
done