#
# Makefile for PWM PRU program
# It is assumed that the PRU compiler environment has been set
#

.PHONY: all clean

all: rcinpru0.stripped rcinpru0.lst

CC=clpru
LD=lnkpru
AR=arpru
OBJDUMP=dispru
STRIP=strippru

# -v3				PRU version 3
# --c99 			C99 support
# --gcc 			Enable GCC extensions
# -O3				Optimization level maximum
# --printf_support=minimal 	Minimal printf
# -ppd				Generate dependencies *.pp
# -ppa				Continue after generating deps
# -DDEBUG			Enable debug
# CFLAGS= -v3 --c99 --gcc -O3 --printf_support=minimal -ppd -ppa -DDEBUG 
CFLAGS= -v3 -s -al -O3 --c99 --gcc --printf_support=minimal --symdebug:none

# -cr 				Link using RAM auto init model (loader assisted)
# -x				Reread libs until no unresolved symbols found
LDFLAGS=-cr --diag_warning=225 -llnk-am33xx.cmd -x

STRIPFLAGS=-p

OBJS1:=rcinpru0.obj

%.obj: %.c
	$(CC) $(CFLAGS) -c $< -ea=.s

%.obj: %.asm
	$(CC) $(CFLAGS) -c $<

rcinpru0: $(OBJS1)
	$(CC) $(CFLAGS) $^ -q -z $(LDFLAGS) -o $@

rcinpru0.stripped: rcinpru0
	$(STRIP) $(STRIPFLAGS) $< -o $@

rcinpru0.lst: rcinpru0
	$(OBJDUMP) -1 $< > $@

clean:
	rm -f \
		rcinpru0 rcinpru0.asm \
		*.obj *.lst *.out *.stripped \
		tags

distclean: clean
	rm -f *.pp

# include any generated deps
-include $(patsubst %.obj,%.pp,$(OBJS))
