1 #Copyright (C) 2011 by Sagar G V
3 #Permission is hereby granted, free of charge, to any person obtaining a copy
4 #of this software and associated documentation files (the "Software"), to deal
5 #in the Software without restriction, including without limitation the rights
6 #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 #copies of the Software, and to permit persons to whom the Software is
8 #furnished to do so, subject to the following conditions:
10 #The above copyright notice and this permission notice shall be included in
11 #all copies or substantial portions of the Software.
13 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # Arthur Wolf & Adam Green in 2011 - Updated to work with mbed.
23 ###############################################################################
25 # Variables that must be defined in including makefile.
26 # PROJECT: Name to be given to the output binary for this project.
27 # SRC: The root directory for the sources of your project.
28 # GCC4MED_DIR: The root directory for where the gcc4mbed sources are located
29 # in your project. This should point to the parent directory
30 # of the build directory which contains this gcc4mbed.mk file.
31 # LIBS_PREFIX: List of library/object files to prepend to mbed.ar capi.ar libs.
32 # LIBS_SUFFIX: List of library/object files to append to mbed.ar capi.ar libs.
37 # LIBS_PREFIX=../agutil/agutil.ar
40 # include ../../build/gcc4mbed.mk
42 ###############################################################################
44 # Default project source to be located in current directory.
49 # List of sources to be compiled/assembled
50 CSRCS
= $(wildcard $(SRC
)/*.c
) $(wildcard $(SRC
)/*/*.c
) $(wildcard $(SRC
)/*/*/*.c
) $(wildcard $(SRC
)/*/*/*/*.c
)
51 ASRCS
= $(wildcard $(SRC
)/*.S
) $(wildcard $(SRC
)/*/*.S
) $(wildcard $(SRC
)/*/*/*.S
) $(wildcard $(SRC
)/*/*/*/*.S
)
52 CPPSRCS
= $(wildcard $(SRC
)/*.
cpp) $(wildcard $(SRC
)/*/*.
cpp) $(wildcard $(SRC
)/*/*/*.
cpp) $(wildcard $(SRC
)/*/*/*/*.
cpp)
54 # Add in the gcc4mbed shim sources that allow mbed code build under GCC
55 CSRCS
+= $(GCC4MBED_DIR
)/src
/gcc4mbed.c
$(GCC4MBED_DIR
)/src
/syscalls.c
57 # List of the objects files to be compiled/assembled
58 OBJECTS
= $(CSRCS
:.c
=.o
) $(ASRCS
:.S
=.o
) $(CPPSRCS
:.
cpp=.o
)
59 LSCRIPT
=$(GCC4MBED_DIR
)/build
/mbed.
ld
61 # Location of external library and header dependencies.
62 EXTERNAL_DIR
= $(GCC4MBED_DIR
)/external
65 INCDIRS
+= $(EXTERNAL_DIR
)/mbed
$(EXTERNAL_DIR
)/mbed
/LPC1768
$(EXTERNAL_DIR
)/FATFileSystem
$(SRC
)
67 # DEFINEs to be used when building C/C++ code
68 DEFINES
= -DTARGET_LPC1768
70 # Libraries to be linked into final binary
71 LIBS
= $(LIBS_PREFIX
) $(EXTERNAL_DIR
)/mbed
/LPC1768
/mbed.
ar $(EXTERNAL_DIR
)/mbed
/LPC1768
/capi.
ar $(EXTERNAL_DIR
)/FATFileSystem
/LPC1768
/FATFileSystem.
ar $(LIBS_SUFFIX
)
77 GPFLAGS
= -O
$(OPTIMIZATION
) -gdwarf-2
-mcpu
=cortex-m3
-mthumb
-mthumb-interwork
-fshort-wchar
-ffunction-sections
-fdata-sections
-fpromote-loop-indices
-Wall
-Wextra
-Wimplicit
-Wcast-align
-Wpointer-arith
-Wredundant-decls
-Wshadow
-Wcast-qual
-Wcast-align
-fno-exceptions
78 GPFLAGS
+= $(patsubst %,-I
%,$(INCDIRS
))
81 LDFLAGS
= -mcpu
=cortex-m3
-mthumb
-O
$(OPTIMIZATION
) -Wl
,-Map
=$(PROJECT
).map
,--cref
,--gc-sections
,--no-wchar-size-warning
-T
$(LSCRIPT
) -L
$(EXTERNAL_DIR
)/gcc
/LPC1768
83 ASFLAGS
= $(LISTING
) -mcpu
=cortex-m3
-mthumb
-x assembler-with-cpp
84 ASFLAGS
+= $(patsubst %,-I
%,$(INCDIRS
))
86 # Compiler/Assembler/Linker Paths
87 GPP
= arm-none-eabi-g
++
88 AS
= arm-none-eabi-gcc
89 LD
= arm-none-eabi-g
++
90 OBJCOPY
= arm-none-eabi-objcopy
91 OBJDUMP
= arm-none-eabi-objdump
93 SIZE
= arm-none-eabi-size
95 #########################################################################
97 all:: $(PROJECT
).hex
$(PROJECT
).bin
$(PROJECT
).disasm
99 $(PROJECT
).bin
: $(PROJECT
).elf
100 $(OBJCOPY
) -O binary
$(PROJECT
).elf
$(PROJECT
).bin
102 $(PROJECT
).hex
: $(PROJECT
).elf
103 $(OBJCOPY
) -R .stack
-O ihex
$(PROJECT
).elf
$(PROJECT
).hex
105 $(PROJECT
).disasm
: $(PROJECT
).elf
106 $(OBJDUMP
) -d
$(PROJECT
).elf
>$(PROJECT
).disasm
108 $(PROJECT
).elf
: $(LSCRIPT
) $(OBJECTS
)
109 $(LD
) $(LDFLAGS
) $(OBJECTS
) $(LIBS
) -o
$(PROJECT
).elf
110 $(SIZE
) $(PROJECT
).elf
112 stats
: $(PROJECT
).elf
113 $(SIZE
) $(PROJECT
).elf
117 $(REMOVE
) $(PROJECT
).hex
118 $(REMOVE
) $(PROJECT
).elf
119 $(REMOVE
) $(PROJECT
).map
120 $(REMOVE
) $(PROJECT
).bin
121 $(REMOVE
) $(PROJECT
).disasm
123 #########################################################################
124 # Default rules to compile .c and .cpp file to .o
125 # and assemble .s files to .o
128 $(GPP
) $(GPFLAGS
) -c
$< -o
$(<:.c
=.o
)
131 $(GPP
) $(GPFLAGS
) -c
$< -o
$(<:.
cpp=.o
)
134 $(AS
) $(ASFLAGS
) -c
$< -o
$(<:.S
=.o
)
136 #########################################################################