This repository has been archived by the owner on Oct 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile_linux
111 lines (93 loc) · 2.69 KB
/
Makefile_linux
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
#Makefile for STM8 Examples with SDCC compiler
#Author: Saeid Yazdani
#Website: WWW.EMBEDONIX.COM
#Copyright 2016
#LICENSE: GNU-LGPL
.PHONY: all clean
#Compiler
CC = sdcc
OBJCOPY = stm8-objcopy
SIZE = stm8-size
#Platform
PLATFORM = stm8
#Product name
PNAME = main
#Directory for helpers
IDIR = StdPeriphLib/inc
SDIR = StdPeriphLib/src
# In case you ever want a different name for the main source file
MAINSRC = $(PNAME).c
ELF_SECTIONS_TO_REMOVE = -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame
# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
$(SDIR)/stm8s_iwdg.c \
$(SDIR)/stm8s_clk.c \
$(SDIR)/stm8s_gpio.c \
$(SDIR)/stm8s_adc1.c \
$(SDIR)/stm8s_tim1.c \
$(SDIR)/stm8s_tim3.c \
$(SDIR)/stm8s_uart2.c \
$(SDIR)/stm8s_flash.c \
gpio.c \
ht162.c \
adc.c \
timers.c \
lcd.c \
uart.c \
eeprom.c \
button.c \
utils.c \
HEADERS = gpio.h main.h adc.h timers.h lcd.h uart.h eeprom.h ht162.h button.h pins.h config.h utils.h
# The list of .rel files can be derived from the list of their source files
RELS = $(EXTRASRCS:.c=.rel)
INCLUDES = -I$(IDIR) -I.
CFLAGS = -m$(PLATFORM) -Ddouble=float --std-c99 --nolospre
ELF_FLAGS = --out-fmt-elf --debug
LIBS =
# This just provides the conventional target name "all"; it is optional
# Note: I assume you set PNAME via some means not exhibited in your original file
all: $(PNAME)
# How to build the overall program
$(PNAME): $(MAINSRC) $(RELS)
$(CC) $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) $(MAINSRC) $(RELS)
$(SIZE) $(PNAME).elf -A
$(OBJCOPY) -O binary $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).bin
$(OBJCOPY) -O ihex $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).hex
# How to build any .rel file from its corresponding .c file
# GNU would have you use a pattern rule for this, but that's GNU-specific
%.rel: %.c $(HEADERS)
$(CC) -c $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) -o$< $<
# Suffixes appearing in suffix rules we care about.
# Necessary because .rel is not one of the standard suffixes.
.SUFFIXES: .c .rel
hex:
$(OBJCOPY) -O ihex $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).ihx
flash:
stm8flash -cstlinkv2 -pstm8s105?4 -w$(PNAME).bin
clean:
@echo "Cleaning files..."
@rm -rf $(SDIR)/*.asm
@rm -rf $(SDIR)/*.rel
@rm -rf $(SDIR)/*.lk
@rm -rf $(SDIR)/*.lst
@rm -rf $(SDIR)/*.rst
@rm -rf $(SDIR)/*.sym
@rm -rf $(SDIR)/*.cdb
@rm -rf $(SDIR)/*.map
@rm -rf $(SDIR)/*.elf
@rm -rf $(SDIR)/*.bin
@rm -rf $(SDIR)/*.adb
@rm -rf *.asm
@rm -rf *.rel
@rm -rf *.lk
@rm -rf *.lst
@rm -rf *.rst
@rm -rf *.sym
@rm -rf *.cdb
@rm -rf *.map
@rm -rf *.adb
@rm -rf *.elf
@rm -rf main.bin
@rm -rf *.ihx
@rm -rf *.hex
@echo "Done."