]> git.sommitrealweird.co.uk Git - barbilliards.git/blob - src/Makefile
8cc64711cf4cf20a501441fcff30edee6095c413
[barbilliards.git] / src / Makefile
1 ifneq ($(V), 1)
2 MAKEFLAGS += --no-print-dir
3 Q := @
4 endif
5
6 OPT_FLAGS ?= -O2
7
8 CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts\
9         $(OPT_FLAGS) -std=gnu99 -g3 -MD \
10         -I.
11 LDFLAGS += $(OPT_FLAGS)
12
13 SRC =                   \
14         timer.c         \
15         usb_cdcacm.c    \
16
17 CROSS_COMPILE ?= arm-none-eabi-
18 CC = $(CROSS_COMPILE)gcc
19 OBJCOPY = $(CROSS_COMPILE)objcopy
20
21 OPT_FLAGS = -Os
22 CFLAGS += -mcpu=cortex-m3 -mthumb \
23         -DSTM32F1 -DDISCOVERY_STLINK -I../libopencm3/include \
24         -I .
25 LDFLAGS_BOOT := $(LDFLAGS) --specs=nano.specs \
26         -lopencm3_stm32f1 -Wl,--defsym,_stack=0x20005000 \
27         -Wl,-T,bluepill.ld -nostartfiles -lc \
28         -Wl,-Map=mapfile -mthumb -mcpu=cortex-m3 -Wl,-gc-sections \
29         -L../libopencm3/lib
30 LDFLAGS = $(LDFLAGS_BOOT)
31
32 LDFLAGS += --specs=nosys.specs
33
34 all:    timer.bin
35
36 host_clean:
37         -$(Q)$(RM) timer.bin
38
39 OBJ = $(SRC:.c=.o)
40
41 timer.elf: $(OBJ)
42         @echo "  LD      $@"
43         $(Q)$(CC) -o $@ $(OBJ) $(LDFLAGS)
44
45 %.o:    %.c
46         @echo "  CC      $<"
47         $(Q)$(CC) $(CFLAGS) -c $< -o $@
48
49 %.bin:  %.elf
50         @echo "  OBJCOPY $@"
51         $(Q)$(OBJCOPY) -O binary $^ $@
52
53 %.hex:  %
54         @echo "  OBJCOPY $@"
55         $(Q)$(OBJCOPY) -O ihex $^ $@
56
57 .PHONY: clean host_clean FORCE
58
59 clean:  host_clean
60         $(Q)echo "  CLEAN"
61         -$(Q)$(RM) -f *.o *.d *~ *.elf *.bin $(HOSTFILES)
62         -$(Q)$(RM) -f mapfile
63