Commit | Line | Data |
---|---|---|
4cff3ded AW |
1 | #Copyright (C) 2011 by Sagar G V |
2 | # | |
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: | |
9 | # | |
10 | #The above copyright notice and this permission notice shall be included in | |
11 | #all copies or substantial portions of the Software. | |
12 | # | |
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 | |
19 | #THE SOFTWARE. | |
20 | # | |
21 | # Updates: | |
22 | # Arthur Wolf & Adam Green in 2011 - Updated to work with mbed. | |
23 | ############################################################################### | |
24 | # USAGE: | |
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. | |
33 | # Example makefile: | |
34 | # PROJECT=HelloWorld | |
35 | # SRC=. | |
36 | # GCC4MBED_DIR=../.. | |
37 | # LIBS_PREFIX=../agutil/agutil.ar | |
38 | # LIBS_SUFFIX= | |
39 | # | |
40 | # include ../../build/gcc4mbed.mk | |
41 | # | |
42 | ############################################################################### | |
43 | ||
44 | # Default project source to be located in current directory. | |
45 | ifndef SRC | |
4eb9c745 | 46 | SRC=./src |
4cff3ded AW |
47 | endif |
48 | ||
49 | # List of sources to be compiled/assembled | |
068f6a12 AW |
50 | CSRCS = $(wildcard $(SRC)/*.c $(SRC)/*/*.c $(SRC)/*/*/*.c $(SRC)/*/*/*/*.c $(SRC)/*/*/*/*/*.c) |
51 | ASRCS = $(wildcard $(SRC)/*.S $(SRC)/*/*.S $(SRC)/*/*/*.S $(SRC)/*/*/*/*.S $(SRC)/*/*/*/*/*.S) | |
52 | CPPSRCS = $(wildcard $(SRC)/*.cpp $(SRC)/*/*.cpp $(SRC)/*/*/*.cpp $(SRC)/*/*/*/*.cpp $(SRC)/*/*/*/*/*.cpp) | |
4cff3ded AW |
53 | |
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 | |
56 | ||
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 | |
60 | ||
61 | # Location of external library and header dependencies. | |
62 | EXTERNAL_DIR = $(GCC4MBED_DIR)/external | |
63 | ||
068f6a12 AW |
64 | # Include path which points to external library headers and to subdirectories of this project which contain headers. |
65 | SUBDIRS = $(wildcard $(SRC)/* $(SRC)/*/* $(SRC)/*/*/* $(SRC)/*/*/*/* $(SRC)/*/*/*/*/*) | |
66 | PROJINCS = $(sort $(dir $(SUBDIRS))) | |
67 | INCDIRS += $(PROJINCS) $(EXTERNAL_DIR)/mbed $(EXTERNAL_DIR)/mbed/LPC1768 $(EXTERNAL_DIR)/FATFileSystem | |
4cff3ded AW |
68 | |
69 | # DEFINEs to be used when building C/C++ code | |
70 | DEFINES = -DTARGET_LPC1768 | |
71 | ||
72 | # Libraries to be linked into final binary | |
73 | LIBS = $(LIBS_PREFIX) $(EXTERNAL_DIR)/mbed/LPC1768/mbed.ar $(EXTERNAL_DIR)/mbed/LPC1768/capi.ar $(EXTERNAL_DIR)/FATFileSystem/LPC1768/FATFileSystem.ar $(LIBS_SUFFIX) | |
74 | ||
75 | # Optimization level | |
76 | OPTIMIZATION = 2 | |
77 | ||
78 | # Compiler Options | |
79 | 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 | |
80 | GPFLAGS += $(patsubst %,-I%,$(INCDIRS)) | |
81 | GPFLAGS += $(DEFINES) | |
82 | ||
83 | 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 | |
84 | ||
85 | ASFLAGS = $(LISTING) -mcpu=cortex-m3 -mthumb -x assembler-with-cpp | |
86 | ASFLAGS += $(patsubst %,-I%,$(INCDIRS)) | |
87 | ||
88 | # Compiler/Assembler/Linker Paths | |
89 | GPP = arm-none-eabi-g++ | |
90 | AS = arm-none-eabi-gcc | |
91 | LD = arm-none-eabi-g++ | |
92 | OBJCOPY = arm-none-eabi-objcopy | |
93 | OBJDUMP = arm-none-eabi-objdump | |
4cff3ded | 94 | SIZE = arm-none-eabi-size |
068f6a12 AW |
95 | REMOVE = rm |
96 | ||
97 | # Switch to cs-rm on Windows. | |
98 | ifeq "$(MAKE)" "cs-make" | |
99 | REMOVE = cs-rm | |
100 | endif | |
4cff3ded AW |
101 | |
102 | ######################################################################### | |
103 | ||
104 | all:: $(PROJECT).hex $(PROJECT).bin $(PROJECT).disasm | |
105 | ||
106 | $(PROJECT).bin: $(PROJECT).elf | |
107 | $(OBJCOPY) -O binary $(PROJECT).elf $(PROJECT).bin | |
108 | ||
109 | $(PROJECT).hex: $(PROJECT).elf | |
110 | $(OBJCOPY) -R .stack -O ihex $(PROJECT).elf $(PROJECT).hex | |
111 | ||
112 | $(PROJECT).disasm: $(PROJECT).elf | |
113 | $(OBJDUMP) -d $(PROJECT).elf >$(PROJECT).disasm | |
114 | ||
115 | $(PROJECT).elf: $(LSCRIPT) $(OBJECTS) | |
116 | $(LD) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(PROJECT).elf | |
117 | $(SIZE) $(PROJECT).elf | |
118 | ||
4cff3ded | 119 | clean: |
068f6a12 AW |
120 | $(REMOVE) -f $(OBJECTS) |
121 | $(REMOVE) -f $(PROJECT).hex | |
122 | $(REMOVE) -f $(PROJECT).elf | |
123 | $(REMOVE) -f $(PROJECT).map | |
124 | $(REMOVE) -f $(PROJECT).bin | |
125 | $(REMOVE) -f $(PROJECT).disasm | |
126 | ||
127 | ifdef LPC_DEPLOY | |
128 | DEPLOY_COMMAND = $(subst PROJECT,$(PROJECT),$(LPC_DEPLOY)) | |
129 | deploy: | |
130 | $(DEPLOY_COMMAND) | |
131 | endif | |
4cff3ded AW |
132 | |
133 | ######################################################################### | |
134 | # Default rules to compile .c and .cpp file to .o | |
135 | # and assemble .s files to .o | |
136 | ||
137 | .c.o : | |
138 | $(GPP) $(GPFLAGS) -c $< -o $(<:.c=.o) | |
139 | ||
140 | .cpp.o : | |
141 | $(GPP) $(GPFLAGS) -c $< -o $(<:.cpp=.o) | |
142 | ||
143 | .S.o : | |
144 | $(AS) $(ASFLAGS) -c $< -o $(<:.S=.o) | |
145 | ||
146 | ######################################################################### |