Last active
December 2, 2016 10:48
-
-
Save mintisan/05d6a09d4d3b43f64a34ebe47ec2ac2e to your computer and use it in GitHub Desktop.
Mikefile demo for MSP430-GCC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Project Structure | |
# [D]src: all source files here | |
# [D]inc: all headers | |
# [D]obj: objects, binary, out | |
# [F]makefile | |
# [D]: derectory | |
# [F]: file | |
# Note:no need to add include directory in any header or source file | |
vpath %.h inc | |
vpath %.c src | |
vpath %.s src | |
vpath %.o obj | |
NAME = Demo | |
INC = inc | |
SRC = src | |
OBJ = obj | |
OBJECTS = blink.o \ | |
add.o | |
CC = msp430-elf-gcc | |
AS = msp430-elf-as | |
LD = msp430-elf-ld | |
SIZE = msp430-elf-size | |
OBJDUMP = msp430-elf-objdump | |
OBJCOPY = msp430-elf-objcopy | |
# -g for assembler with source code | |
CFLAGS = -I $(INC) -O2 -Wall -g -mcpu=430 | |
LDFLAGS = -L $(INC) | |
.PHONY: all clean | |
all: $(OBJECTS) ${NAME}.elf ${NAME}.bin ${NAME}.hex ${NAME}.lst | |
# .c -> .o | |
$(OBJECTS): %.o: %.c | |
# -c Compile and assemble, but do not link | |
# -o <file> Place the output into <file> | |
# -mcpu={430|430x|430xv2} - select microcontroller architecture | |
# -g --gen-debug generate debugging information | |
# -I DIR add DIR to search list for .include directives | |
$(CC) -c $(CFLAGS) $^ -o $(OBJ)/$@ | |
# just start another make process | |
# to update OBJECTS's vpath[3] | |
${NAME}.elf: ${OBJECTS} | |
$(MAKE) elf | |
# .o -> .elf | |
elf: ${OBJECTS} | |
# -o OBJFILE name the object-file output OBJFILE (default a.out) | |
# -T FILE, --script FILE Read linker script | |
# -L DIRECTORY, --library-path DIRECTORY Add DIRECTORY to library search path | |
$(LD) $(LDFLAGS) $^ -o $(OBJ)/${NAME}.elf | |
# show objects' size | |
# -t --totals Display the total sizes (Berkeley only) | |
# -A|-B --format={sysv|berkeley} Select output style (default is berkeley) | |
$(SIZE) -t -B $^ | |
# .elf -> .hex .bin | |
${NAME}.hex: ${NAME}.elf | |
# -O --output-target <bfdname> Create an output file in format <bfdname> | |
$(OBJCOPY) -O ihex $(OBJ)/$^ $(OBJ)/$@ | |
${NAME}.bin: ${NAME}.elf | |
$(OBJCOPY) -O binary $(OBJ)/$^ $(OBJ)/$@ | |
#.elf -> .lst | |
${NAME}.lst: ${NAME}.elf | |
# -f, --file-headers Display the contents of the overall file header | |
# -S, --source Intermix source code with disassembly | |
# -t, --syms Display the contents of the symbol table(s) | |
$(OBJDUMP) -fSt $(OBJ)/$^ > $(OBJ)/$@ | |
clean: cleanobj cleanbin cleantmp | |
rm -rf $(OBJ)/*.lst | |
cleantmp: | |
rm -rf $(OBJ)/*.i $(OBJ)/*.s | |
cleanobj: | |
rm -rf $(OBJ)/*.o | |
cleanbin: | |
rm -rf $(OBJ)/*.bin $(OBJ)/*.hex $(OBJ)/*.elf | |
# Symbol | |
# $@ all target files | |
# $^ all dependent files | |
# Tutorial | |
# [1]: http://www.cnblogs.com/ggjucheng/archive/2011/12/14/2287738.html | |
# [2]: http://blog.csdn.net/haoel/article/details/2886 | |
# [3]: http://blog.codingnow.com/2009/03/gnu_make_vpath.html | |
# [4]: https://www.gnu.org/software/make/manual/make.html | |
# [5]: http://mrbook.org/blog/tutorials/make/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment