#Copyright (C) 2011 by Sagar G V # #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal #in the Software without restriction, including without limitation the rights #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #copies of the Software, and to permit persons to whom the Software is #furnished to do so, subject to the following conditions: # #The above copyright notice and this permission notice shall be included in #all copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #THE SOFTWARE. # # Updates: # Arthur Wolf & Adam Green in 2011 - Updated to work with mbed. ############################################################################### # USAGE: # Variables that must be defined in including makefile. # PROJECT: Name to be given to the output binary for this project. # SRC: The root directory for the sources of your project. # GCC4MED_DIR: The root directory for where the gcc4mbed sources are located # in your project. This should point to the parent directory # of the build directory which contains this gcc4mbed.mk file. # LIBS_PREFIX: List of library/object files to prepend to mbed.ar capi.ar libs. # LIBS_SUFFIX: List of library/object files to append to mbed.ar capi.ar libs. # Example makefile: # PROJECT=HelloWorld # SRC=. # GCC4MBED_DIR=../.. # LIBS_PREFIX=../agutil/agutil.ar # LIBS_SUFFIX= # # include ../../build/gcc4mbed.mk # ############################################################################### # Default project source to be located in current directory. ifndef SRC SRC=./src endif # List of sources to be compiled/assembled CSRCS = $(wildcard $(SRC)/*.c) $(wildcard $(SRC)/*/*.c) $(wildcard $(SRC)/*/*/*.c) $(wildcard $(SRC)/*/*/*/*.c) ASRCS = $(wildcard $(SRC)/*.S) $(wildcard $(SRC)/*/*.S) $(wildcard $(SRC)/*/*/*.S) $(wildcard $(SRC)/*/*/*/*.S) CPPSRCS = $(wildcard $(SRC)/*.cpp) $(wildcard $(SRC)/*/*.cpp) $(wildcard $(SRC)/*/*/*.cpp) $(wildcard $(SRC)/*/*/*/*.cpp) # Add in the gcc4mbed shim sources that allow mbed code build under GCC CSRCS += $(GCC4MBED_DIR)/src/gcc4mbed.c $(GCC4MBED_DIR)/src/syscalls.c # List of the objects files to be compiled/assembled OBJECTS= $(CSRCS:.c=.o) $(ASRCS:.S=.o) $(CPPSRCS:.cpp=.o) LSCRIPT=$(GCC4MBED_DIR)/build/mbed.ld # Location of external library and header dependencies. EXTERNAL_DIR = $(GCC4MBED_DIR)/external # Include path INCDIRS += $(EXTERNAL_DIR)/mbed $(EXTERNAL_DIR)/mbed/LPC1768 $(EXTERNAL_DIR)/FATFileSystem $(SRC) # DEFINEs to be used when building C/C++ code DEFINES = -DTARGET_LPC1768 # Libraries to be linked into final binary LIBS = $(LIBS_PREFIX) $(EXTERNAL_DIR)/mbed/LPC1768/mbed.ar $(EXTERNAL_DIR)/mbed/LPC1768/capi.ar $(EXTERNAL_DIR)/FATFileSystem/LPC1768/FATFileSystem.ar $(LIBS_SUFFIX) # Optimization level OPTIMIZATION = 2 # Compiler Options 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 GPFLAGS += $(patsubst %,-I%,$(INCDIRS)) GPFLAGS += $(DEFINES) 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 ASFLAGS = $(LISTING) -mcpu=cortex-m3 -mthumb -x assembler-with-cpp ASFLAGS += $(patsubst %,-I%,$(INCDIRS)) # Compiler/Assembler/Linker Paths GPP = arm-none-eabi-g++ AS = arm-none-eabi-gcc LD = arm-none-eabi-g++ OBJCOPY = arm-none-eabi-objcopy OBJDUMP = arm-none-eabi-objdump REMOVE = rm -f SIZE = arm-none-eabi-size ######################################################################### all:: $(PROJECT).hex $(PROJECT).bin $(PROJECT).disasm $(PROJECT).bin: $(PROJECT).elf $(OBJCOPY) -O binary $(PROJECT).elf $(PROJECT).bin $(PROJECT).hex: $(PROJECT).elf $(OBJCOPY) -R .stack -O ihex $(PROJECT).elf $(PROJECT).hex $(PROJECT).disasm: $(PROJECT).elf $(OBJDUMP) -d $(PROJECT).elf >$(PROJECT).disasm $(PROJECT).elf: $(LSCRIPT) $(OBJECTS) $(LD) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(PROJECT).elf $(SIZE) $(PROJECT).elf stats: $(PROJECT).elf $(SIZE) $(PROJECT).elf clean: $(REMOVE) $(OBJECTS) $(REMOVE) $(PROJECT).hex $(REMOVE) $(PROJECT).elf $(REMOVE) $(PROJECT).map $(REMOVE) $(PROJECT).bin $(REMOVE) $(PROJECT).disasm ######################################################################### # Default rules to compile .c and .cpp file to .o # and assemble .s files to .o .c.o : $(GPP) $(GPFLAGS) -c $< -o $(<:.c=.o) .cpp.o : $(GPP) $(GPFLAGS) -c $< -o $(<:.cpp=.o) .S.o : $(AS) $(ASFLAGS) -c $< -o $(<:.S=.o) #########################################################################