# Generic Makefile
# requires make >= 3.82
.RECIPEPREFIX = -
#--------------------------------

REPS=10
SIZE=8

#--------

CC=gcc
CFLAGS=-Wall -g -std=c11
S=as
SFLAGS=-g -als

#--------

%: %.c
-       $(CC) -o $@  $(CFLAGS)  $^

%.o: %.s
-       $(S)  $(SFLAGS)  -o $@  $<  >$*.lst

%.o: %.c
-       $(CC) -o $@  $(CFLAGS) -c  $^

#--------

sort-book-c: sort-main.o sort-book-c.o swap-book-c.o
-   $(CC) $(CFLAGS) -o $@  $^

test-c: sort-book-c
-   for i in `seq $(REPS)`; do ./$< $(SIZE) > /dev/null ; done

#----

sort-book-s: sort-main.o sort-book-s.o swap-book-s.o
-   $(CC) $(CFLAGS) -o $@  $^

test-s: sort-book-s
-   for i in `seq $(REPS)`; do ./$< $(SIZE) > /dev/null ; done

#----

sort-book-s2: sort-main.o sort-book-s2.o swap-book-s.o
-   $(CC) $(CFLAGS) -o $@  $^

test-s2: sort-book-s2
-   for i in `seq $(REPS)`; do ./$< $(SIZE) > /dev/null ; done

#----

sort-book-cs: sort-main.o sort-book-c.o swap-book-s.o
-   $(CC) $(CFLAGS) -o $@  $^

test-cs: sort-book-cs
-   for i in `seq $(REPS)`; do ./$< $(SIZE) > /dev/null ; done

#----

sort-recursive: sort-main.o sort-recursive.o
-   $(CC) $(CFLAGS) -o $@  $^

test-r: sort-recursive
-   for i in `seq $(REPS)`; do ./$< $(SIZE) > /dev/null ; done

#--------

clean:
-       find . -executable -type f -ls -ok rm {} \;
-       rm -f *.o *.lst *~ a.out

dummy:
-       ls -l
-       echo "That's all, folks!"

#--------