Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » SDCC
  • » [Sdcc-user] Sdcc makefile for pic14 and pic16 for linux [RSS Feed]

#1 March 24, 2008 10:13:39

T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] Sdcc makefile for pic14 and pic16 for linux


Dear All,

I have created a makefile that can suit my needs.
I would like to ask about your opinions to make it better.

Maybe sombody can find it useful.

It supports:
* sdcc and gputils only under linux
* single file compilation for both asm or C
* multiple file compilation for C or asm or mixed
* creating dependancy for all file in the project
with makedepend and sed
* making a snapshot of your current code project for archival
purposes


Theblond
(Sandor Szoke)

PS.: Soon, I will post example project for use with this makefile###############################################################################
#
# PIC compile makefile for use with SDCC and GPUTILS
# You can find an dummy projects athttp://szokesandor.hu/sdcc#
# C2006.12.02.
# C2008.03.22.
#
# Please send bug reports or comments to the author.
# If you improved this makefile, please send the updates back to the author!
#
# Licensed under the GNU GPL V2 or later
#
#
#----------------------------------------------------------------------------
# Name of the .hex file without extention
#
PRJ = firmware
#
#-----------------------------------------------------------------------------
# Used modules, the first should contain the main() function
# Assembly modules should have extention ".S", because the current clean up!
#
SRCS_C := main.c
SRCS_ASM :=
#
#----------------------------------------------------------------------------
# Type of the used cpu
#
CPU = 18f458
#
#----------------------------------------------------------------------------
# Type of the architecture eg. -mpic14 or -mpic16
#
ARCH = -mpic16
#
#----------------------------------------------------------------------------
# Adjust to sdcc data dir and to gputils dir.
# Normally they are installed into /usr/share
# In my case I have built sdcc under my home.
#
#SDCCDIR = /usr/share/sdcc
SDCCDIR = /home/alex/share/sdcc
GPUTILSDIR = /usr/share/gputils
#
#----------------------------------------------------------------------------
# Adjust according to architecture 14bit (pic) or 16bit (pic16)
#
#INCLUDEDIR = $(SDCCDIR)/include/pic
#LIBDIR = $(SDCCDIR)/lib/pic

INCLUDEDIR = $(SDCCDIR)/include/pic16
LIBDIR = $(SDCCDIR)/lib/pic16
#
#----------------------------------------------------------------------------
# Defining the tools, you may have several version installed
# for different reasons (testing, production, etc.)
#
SDCC = sdcc
GPASM = gpasm
GPDASM = gpdasm
GPLINK = gplink
#
#----------------------------------------------------------------------------
# We should link against these libraries.
# If custom startup code is used crt0i.o should be removed and
# the new crt module should be added to the SRCS_ASM line.
#
LIBS = crt0i.o libsdcc.lib pic$(CPU).lib
#LIBS = libsdcc.lib pic$(CPU).lib
#
#----------------------------------------------------------------------------
# Flags sdcc:
# -c :compile only
# -S :stop after assembly
# -V : show actual command line the compiler executing
# --verbose: Shows the various actions the compiler is performing
#
# Flags for gplink:
# -c :
# -m :
# -w :
# -r :
# -I dir:
# -s file: the linker file
SDCC_FLAGS = -S $(ARCH) -p$(CPU) -c
GPASM_FLAGS =
GPLINK_FLAGS = -c -m -w -r -I $(LIBDIR) -s $(GPUTILSDIR)/lkr/$(CPU).lkr
#
###############################################################################
#
# NO USER SERVICABLE SETTING BELOW THIS LINE!
#
# Changes hereafter can totally break your build process.
# Modify only, if you know what are you doing!
# If you improved this makefile, please send the updates back to the author!
#
DEPDIR = .deps
DEPFILES = $(DEPDIR)/$(*F)
OBJS_C := $(SRCS_C:.c=.o)
OBJS_ASM = $(SRCS_ASM:.asm=.o)
OBJS = $(OBJS_C) $(OBJS_ASM)
#
#----------------------------------------------------------------------------
# Only the generated asm files will be deleted
#
CLEAN_ASMS = $(SRCS_C:.c=.asm)
#
#----------------------------------------------------------------------------
# Current datetime for creating archive
#
DATETIME = $(shell date +%Y_%m_%d_%H%M%S)
#
#----------------------------------------------------------------------------
# Redefine the compiler
#
CC = $(SDCC)
#
#----------------------------------------------------------------------------
# For dependancy, we use makedepend a bit sligthly modified
#
MAKEDEPEND = touch $(DEPFILES).d && makedepend -I$(INCLUDEDIR) -Dpic$(CPU) -f
$(DEPFILES).d $<
#
##############################################################################
# Main target
#
all: $(PRJ).hex
#
##############################################################################
# Linking the modules alltogether
#
$(PRJ).hex: $(OBJS)
$(GPLINK) $(GPLINK_FLAGS) -o $(PRJ).hex $(OBJS) $(LIBS)
$(GPDASM) -p$(CPU) $(PRJ).hex > $(PRJ).dasm
@echo "*** Linking finished."
#
##############################################################################
# Compiling and assembling the modules, with dependencies to its include files
#
# fixme: use only pipe for creating dependancy files
# compile through asm
#
%.o: %.c
@mkdir -p $(DEPDIR)
@$(MAKEDEPEND); \
cp $(DEPFILES).d $(DEPFILES).dep; \
sed -e 's/#.*//' -e 's/^*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(DEPFILES).d >> $(DEPFILES).dep; \
rm -f $(DEPFILES).d $(DEPFILES).d.bak
$(CC) $(SDCC_FLAGS) $<
$(GPASM) $(GPASM_FLAGS) -c $*.asm
##############################################################################
# compiling standalone asm files into object file if needed
#
%.o: %.asm
$(GPASM) $(GPASM_FLAGS) -c $<
#----------------------------------------------------------------------------
# Include generated dependancy to depend on.
#
-include $(SRCS:%.c=$(DEPDIR)/%.dep)
#
#----------------------------------------------------------------------------
# Cleaning the folder, deleting all the files that can be regenerated
#
clean:
-rm -f *.o $(CLEAN_ASMS) *.lst *.p *.d *.cod *.hex *.c~ *.asm~ *.map \
*.cof *.dasm *.dump* $(DEPFILES)*
-rmdir $(DEPDIR)
@echo "*** Project directory cleaned."
#
#----------------------------------------------------------------------------
# Creating a snapshot of the current state of the project,in the upper folder.
# Can be useful for archiving earlier versions of the project.
#
dist:
@pwd=$$(pwd); cd ..; tar cjf $$pwd-$(DATETIME).tar.bz2 $$(basename
$$pwd);\
echo "*** Dist created: $$pwd-$(DATETIME).tar.bz2"
#
.PHONY: all clean dist
#
# end of makefile
###############################################################################-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

  • Root
  • » SDCC
  • » [Sdcc-user] Sdcc makefile for pic14 and pic16 for linux [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support