diff --git a/pic/MDR/Makefile b/pic/MDR/Makefile index 8a661d8..7efaa4b 100644 --- a/pic/MDR/Makefile +++ b/pic/MDR/Makefile @@ -1,24 +1,43 @@ -# variables +# hex file to be flashed TARGET = MDR +# pic chip on which to flash the code PIC = 16f1847 +# source code +SRC := $(wildcard *.c) +# compiled code (assembly) +ASM := $(patsubst %.c,%.asm,$(SRC)) +# the object files +OBJ := $(patsubst %.c,%.o,$(SRC)) # software verion used: # pk2cmd: 1.21 # sdcc: 3.4.0 # gputils: 1.3.0 -all: flash +all: compile flash # flash program flash: $(TARGET).hex pk2cmd -PPIC$(PIC) -F$< -M -W -R -# compile program -compile: $(TARGET).hex +# compile stages +assembly: $(ASM) -# compile program C source code (includes a default code) -$(TARGET).hex: $(TARGET).c - sdcc --std-c99 --opt-code-size --use-non-free -mpic14 -p$(PIC) $< +objects: $(OBJ) + +hex: $(TARGET).hex + +compile: hex + +# compile steps +%.asm: %.c + sdcc -S --use-non-free -mpic14 -p$(PIC) -I. -o $@ $< + +%.o: %.asm + gpasm -I . -o $@ -c $< + +$(TARGET).hex: $(OBJ) + gplink -w -r -s /usr/share/gputils/lkr/$(PIC)_g.lkr -I/usr/share/sdcc/lib/pic14 -I/usr/share/sdcc/non-free/lib/pic14 -I. -o $@ libsdcce.lib pic$(PIC).lib $< # remove temporary files clean: - rm -f $(TARGET).hex $(TARGET).lst $(TARGET).asm $(TARGET).adb $(TARGET).o $(TARGET).cod + rm -f $(ASM) $(OBJ) $(TARGET).hex $(patsubst %.c,%.lst,$(SRC)) $(patsubst %.c,%.cod,$(SRC))