CC arm-elf-gcc CXX arm-elf-g LD arm-elf-ld OBJCOPY arm-elf-objcopy VPA

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
CC = arm-elf-gcc
CXX = arm-elf-g++
LD = arm-elf-ld
OBJCOPY = arm-elf-objcopy
#VPATH = ../fsm
#-I$(HOME)/ecos/newlib-arm/arm-elf/include -I../fsm -DXXPROTOTYPE_PCB
CPPFLAGS =
# -DHD_TEST
#-DSED_UNICODE
# -DSED_MEMTEST -DPROTOTYPE_PCB
# -DSED_TEST
CFLAGS = -Wall -std=gnu99 -march=armv4t -g3 -mthumb-interwork -I. $(CPPFLAGS)
CXXFLAGS = -Wall -march=armv4t -g3 -I. $(CPPFLAGS)
LDFLAGS = -mthumb -mthumb-interwork
#-L$(HOME)/ecos/newlib-arm/arm-elf/lib/armv4t
#-L$(HOME)/ecos/gnutools/arm-elf/lib/gcc-lib/arm-elf/3.2.1
GCC ?= $(CC)
.PHONY: all debug
all: main.bin
debug: debug.bin
ifeq ($(filter debug debug.elf debug.bin,$(MAKECMDGOALS)),)
CPPFLAGS += -DBOOTLOADER
arm = crt_boot
else
arm = crt_rom
endif
### Source files
arm += timers fsm misc config_hal wchar sound smbus_intr weighs vkpd
thumb = main config ccitt_crc16 bus command hd44780 keyb serial \
version menu smbus log
#argets = crt0 main timers fsm misc wchar config ccitt_crc16 smbus bus \
#command keyb sound serial version hd44780 menu
# include dependencies for each target
include $(thumb:%=%.d)
include $(arm:%=%.d)
### Specific rules
main.elf: $(arm:%=%.o) $(thumb:%=%.o)
$(CXX) $(LDFLAGS) -Tbinboot.ld -nostartfiles -nodefaultlibs \
-lgcc -o$@ $^ -lc -lgcc -lm
debug.elf: $(arm:%=%.o) $(thumb:%=%.o)
$(CXX) $(LDFLAGS) -Trom.ld -nostartfiles -nodefaultlibs \
-lgcc -o$@ $^ -lc -lgcc -lm
.DELETE_ON_ERROR: version.c
version.o: version.c version.h
version.c: version.sh .
sh $< version > $@
# optimization
timers.o: timers.c timers.h custom.h timers_hal.c
$(CC) $(CFLAGS) -O3 -Wa,-alh=$*.lst -c -o $@ $<
# debugging
### Common rules
%.d: %.c
$(GCC) -MM $(CPPFLAGS) $< | \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
%.d: %.cc
$(GCC) -MM $(CPPFLAGS) $< | \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
%.d: %.S
$(GCC) -MM $(CPPFLAGS) $< | \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
# optimize by size
$(thumb:%=%.o):
$(CC) $(CFLAGS) -mthumb -Os -Wa,-alh=$*.lst -c -o $@ $*.c
%.o: %.c
$(CC) $(CFLAGS) -O2 -Wa,-alh=$*.lst -c -o $@ $<
%.o: %.cc
$(CXX) $(CXXFLAGS) -O2 -Wa,-alh=$*.lst -c -o $@ $<
%.o: %.S
$(CC) $(CFLAGS) -c -o $@ $<
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
%.elf: %.o
$(CC) $(LDFLAGS) -nostartfiles -nodefaultlibs -lgcc -o$@ $^ -lc -lgcc -lm
# crti.o crtbegin.o crt0.o $< crtend.o crtn.o
### PHONY target only below
.PHONY: doc
doc:
doxygen doxygen.doc
.PHONY: clean clean-all clean-deps
clean: clean-deps
rm -f *.elf *.o *.lst
clean-deps:
rm -f *.d
clean-all: clean
rm -f *.hex *.bin tags