# # Sample Makefile for C30 based projects # Version 0.1 # # (C) 2010 Matt Jervis # http://www.electricrock.co.nz/blog # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # # Use at your own risk and make sure you backup important files first!!!! # # The name of the file you want to output TARGET=targetname.hex # Part number PART=30f4013 # Uncomment the appropriate family PARTFAMILY=dsPIC30F #PARTFAMILY=dsPIC33F #PARTFAMILY=pic24H #PARTFAMILY=pic24L GCC=pic30-coff-gcc AS=pic30-coff-as LD=pic30-coff-ld # The path where you installed C30 (e.g. /opt/c30) C30PATH=/usr/local # This assumes all sources are in the current directory # Add paths to other directories if necessary, or manually specify sources SRCS=$(wildcard *.c) \ # $(wildcard src/*.c) \ # $(wildcard src/dir1/*.c) # Add more include paths as required by your project INCLUDEPATH=.\ # ./include # CFLAGS - these are just ones I was mucking around with. # If you want to on-chip debug then you probably want -O0 (I think) CFLAGS=-g -O2 # Comment out the second lib here if you don't need the periphal libraries LIBS= -lpic30 \ -lp$(subst f,F,$(PART)) # # # The rest shouldn't need editing # # ---------------------------------------------------------------------------- # LIBPATH=-L$(C30PATH)/share/pic30-nonfree/lib \ -L$(C30PATH)/share/pic30-nonfree/lib/$(PARTFAMILY) LINKERSCRIPT=$(C30PATH)/share/pic30-nonfree/support/$(PARTFAMILY)/gld/p$(PART).gld OBJS=$(patsubst %.c, %.o, $(SRCS)) LSTS=$(patsubst %.c, %.lst, $(SRCS)) ASMS=$(patsubst %.c, %.s, $(SRCS)) HEADERS=$(wildcard *.h) .PHONY: target target: $(TARGET) .PHONY: assembly assembly: $(ASMS) .PHONY: objects objects: $(OBJS) .PHONY: all all: target assembly objects .PHONY: clean clean: -rm $(OBJS) -rm $(TARGET) -rm $(LSTS) -rm $(ASMS) %.s: %.c $(HEADERS) $(GCC) -S -mcpu=$(PART) $(CFLAGS) -o $@ $< %.o: %.c $(HEADERS) $(GCC) -c -mcpu=$(PART) $(CFLAGS) -o $@ $< $(TARGET): $(OBJS) $(LD) $(LIBPATH) $(LIBS) -T$(LINKERSCRIPT) -o $@ $^