-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
160 lines (102 loc) · 3.64 KB
/
Makefile
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#******************************************************************************
# Copyright (C) 2022 by Abdulrahman Aboghanima
#
# Redistribution and use in source and binary forms, with or without
# Modification, are permitted as long as there is no misuse of this
# software.
# Abdulrahman Aboghanima is not liable for any misuse of this Material
#
#******************************************************************************
include sources.mk
#The Compiler Used
CC := avr-gcc
#Target MCU
MCU := atmega32
#CPU Clock Frequency
F_CPU := 8000000ul
#Linker
LD := avr-ld
OBJCOPY := avr-objcopy
CFLAGS := -std=c99 -Wall -Wextra -g -Os -fdata-sections -ffunction-sections -fshort-enums -mmcu=$(MCU) -DF_CPU=$(F_CPU)
CPPFLAGS := $(INCLUDES:%=-I%)
LDFLAGS := -Xlinker --gc-sections -Xlinker --relax -Wl,-u,vfprintf -lprintf_flt -lm #-Xlinker --strip-all
module_name :=
EXEC := $(EXEC)
#RULES
#######################################################################################################
#`make build-all` for building all the executable files
.PHONY: build-all
build-all:
$(foreach HEX_FILE, $(HEX_FILES), make build EXEC=$(HEX_FILE:%.hex=%);)
#`make build` for build only
.PHONY: build
build: $(EXEC).elf $(EXEC).lss $(EXEC).hex
#`make compile-all` for compiling all source files
.PHONY: compile-all
compile-all: $(ALLOBJS)
#`make preprocess-all` for preprocessing all source files
.PHONY: preprocess-all
preprocess-all: $(PREPROCESSED)
#`make assemble-all` for generating an assembly file for all source files
.PHONY: assemble-all
assemble-all: $(ASSEMBLIES)
#`make flash` to flash the hex file to the micro-controller
.PHONY: flash
flash: $(EXEC).hex
@echo Flashing to the $(MCU)..
avrdude -p $(MCU) -c usbasp -U flash:w:$<:i -F -P usb
#`make EXECUTABLENAME.lss` for generating Extended listing
%.lss: %.elf
@echo Invoking: Avr Extended listing
avr-objdump -S -h $< > $@
#`make EXECUTABLENAME.elf` for generating the elf file
%.elf: $(OBJS) %.o
@echo Building Target: $@
$(CC) $(CFLAGS) $(LDFLAGS) -Xlinker [email protected] $^ -o $@
@avr-size -C $@
#`make x.o` generate an object file, x.o from source file, x.c,.
bin/%.o:%.c
@mkdir -p $(INCLUDES:%=bin/%)
@echo Compiling ---------------------------------------- $@
@$(CC) -c $(CFLAGS) $(CPPFLAGS) -MMD -MP -MT$@ [email protected] $< -o $@
#`make x.asm` generate an assembly file, x.asm from source file, x.c,.
bin/%.asm:%.c
@mkdir -p $(INCLUDES:%=bin/%)
$(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o $@
#`make x.i` generate a preprocessed file, x.i from source file, x.c,.
bin/%.i:%.c
@mkdir -p $(INCLUDES:%=bin/%)
$(CC) -E $(CFLAFS) $(CPPFLAGS) $< -o $@
#`make x.hex` generate an object file, x.hex from elf file, x.elf,.
%.hex:%.elf
@echo Genrating hex file --------------------------------- $@
@$(OBJCOPY) -j .text -j .data -O ihex $< $@
#`make docs` for generating documentation
.PHONY: docs
docs:
@echo Generating Documentations
@doxygen &> /dev/null
.PHONY: module
module:
@test $(module_name) || \
(echo "Enter the path followed by the module name. i.e MCAL/moduleX"; exit 1)
@mkdir -p $(shell dirname ${module_name})
@touch $(module_name)_config.h \
$(module_name)_interface.h \
$(module_name)_program.c \
$(module_name)_register.h \
$(module_name)_private.h
.PHONY: test
test:
@echo The Sources are : $(SOURCES)
@echo
@echo The Includes are : $(INCLUDES)
@echo
@echo The objects are : $(OBJS)
@echo Test files are : $(TESTSOBJS)
@echo Hex files are : $(HEX_FILES)
.PHONY: clean
clean:
@rm -rf $(OBJS) $(PREPROCESSED) $(ASSEMBLIES) $(DEPENDENCIES) $(TESTSOBJS) \
*.out *.map *.elf *.map *.hex *.s *.i *.d *.lss *.o *.obj bin
@echo CLEANED!