# # Makefile for Microchip sdcc project # # override PATH to get our latest sdcc/gputils PATH=$(HOME)/build/sdcc-build/orig/sdcc/bin:$(HOME)/build/gputils/trunk/gputils/gputils:$(HOME)/build/gputils/trunk/gputils/gpasm:$(HOME)/build/gputils/trunk/gputils/gplink:/usr/bin:/bin REL=MCHPFSUSB PARSE=./mplab2sdcc.pl CHIP=18f87j50 # make /usr if you want released tools /home/rick/in/sdcc MY_BASE=$(HOME)/build/sdcc-build/orig/sdcc SDCC_HOME=$(MY_BASE)/device SRCS= system/usb/usbdrv/usbdrv.c system/usb/usbmmap.c main.c system/usb/usb9/usb9.c \ autofiles/usbdsc.c system/usb/usbctrltrf/usbctrltrf.c user/user.c \ system/usb/class/cdc/cdc.c user/temperature.c HDRS= user/user.h autofiles/usbdsc.h autofiles/usbcfg.h system/usb/usb_compile_time_validation.h system/usb/usb.h system/usb/usbdefs/usbdefs_ep0_buff.h system/usb/usbdefs/usbdefs_std_dsc.h system/usb/usbmmap.h system/usb/usb9/usb9.h system/usb/usbdrv/usbdrv.h system/usb/class/cdc/cdc.h system/usb/usbctrltrf/usbctrltrf.h system/typedefs.h system/interrupt/interrupt.h io_cfg.h OBJS = $(SRCS:%.c=%.o) ASMS = $(SRCS:%.c=%.asm) LSTS = $(SRCS:%.c=%.lst) CRT = crt0iz-rloc PROJ=cdcusb CC=$(MY_BASE)/bin/sdcc DIS = gpdasm FSUSB = /opt/emerald/co2/fsusb-0.1.11-2/fsusb CODE_START = 0x0000 MAIN_PROG_START = 8192 # 0x2000 allow enough room for boot code changes! MAIN_PROG_SIZE := $(shell echo 'obase=10; ibase=10; $(MAIN_PROG_START)+12' | bc) # 0x200c put main size here DFU_PROG_END = 0x8000 # depending on chip size # now subtract the size of MAIN_CODE_RECORD from the top of memory DFU_PROG_END_STRUCT=`echo 'obase=10; ibase=16; $(DFU_PROG_END)-6' | bc` OPTS= --vc --denable-peeps --optimize-goto --optimize-cmp --optimize-df --obanksel=9 --opt-code-size --fommit-frame-pointer --ivt-loc=$(CODE_START) --use-crt=$(CRT).o #OPTS= --no-peep --fstack CFLAGS= -I. -I$(SDCC_HOME)/include/pic16 $(OPTS) -mpic16 -pp$(CHIP) LINKER_SCRIPT= sd$(CHIP).lkr LIBS= libsdcc.lib libc18f.lib libio$(CHIP).lib pic$(CHIP).lib .SUFFIXES: .c .asm .o .hex all: $(PROJ).hex $(OBJS): %.o: %.c Makefile .depend $(CC) $(CFLAGS) -c $< -o $@ $(PROJ).hex: $(OBJS) $(LINKER_SCRIPT) $(CC) $(CFLAGS) -L $(SDCC_HOME)/lib/build/pic16 -Wl,"-m -w -s $(LINKER_SCRIPT)" -o $(PROJ) $(OBJS) $(LIBS) disass: $(DIS) -p p$(CHIP) $(PROJ).hex > $(PROJ).lis prog: sudo $(FSUSB) --program $(PROJ).hex #convert mplab to sdcc convert: for file in ${SRCS} ${HDRS} ; do \ cat ../../../$(REL).orig/fw/Cdc/$${file} | $(PARSE) > $${file} ; done sed -e "93,102d;133,168d" ../../../$(REL).orig/fw/Cdc/system/usb/usbmmap.h | $(PARSE) > system/usb/usbmmap.h sed -e "/U S B F I X E D L O C A T I O N/,+107d" ../../../$(REL).orig/fw/Cdc/system/usb/usbmmap.c | $(PARSE) > system/usb/usbmmap.c sed -e "701d;703d;s/clrf POSTINC0,0/*startAdr++ = 0;/" ../../../$(REL).orig/fw/Cdc/system/usb/usbdrv/usbdrv.c | $(PARSE) > system/usb/usbdrv/usbdrv.c sed -e "/D E C L A R A T I O N S/a#ifdef SDCC\n#pragma udata usbram4 bdt_data //See Linker Script,usb4:0x400-0x4FF(256-byte)\n#else\n#pragma udata usbram4=0x400\n#endif\nvolatile far BDTDATA bdt_data; //Buffer Descriptor data\n#ifndef SDCC\n#pragma udata\n#endif" system/usb/usb9/usb9.c > xx mv -f xx system/usb/usb9/usb9.c sed -e "/#if defined(USB_USE_CDC/,+14w /tmp/xx2" system/usb/usbmmap.c > xx sed -e "/#if defined(USB_USE_CDC/,+14d" system/usb/usbmmap.c > xx mv -f xx system/usb/usbmmap.c sed -e "53r /tmp/xx2" system/usb/class/cdc/cdc.c > xx mv -f xx system/usb/class/cdc/cdc.c # also need a different lkr file clean: rm -f $(OBJS) $(ASMS) $(LSTS) core .depend depend $(PROJ).cod $(PROJ).hex $(PROJ).lst $(CRT).o: %.o: %.c Makefile $(CC) $(CFLAGS) -c $< -o $@ depend .depend dep: for file in $(SRCS); do $(CC) $(CFLAGS) -M $$file >> $@; done dummy: # include a dependency file if one exists ifeq (.depend,$(wildcard .depend)) include .depend endif