CC = gcc
AS = as
DEBUG = no
SRC = $(wildcard *.c)
CPUSPEED = $(shell ./tools/cpuspeed)
DEFINES = -DCPU_SPEED=$(CPUSPEED)
SRCADD = $(wildcard addition/*.s)
SRCSHT = $(wildcard decalage/*.s)
SRCMUL = $(wildcard multiplication/*.s)
SRCSUB = $(wildcard substract/*.s)
OBJ = $(SRC:.c=.o) $(SRCADD:.s=.o) $(SRCSHT:.s=.o) $(SRCMUL:.s=.o) $(SRCSUB:.s=.o)
EXE = arpcalc

ifeq ($(DEBUG),yes)
	CFLAGS = -Wall -g -lm
else
	CFLAGS =  -Wall -O3  -march=pentium4 -mtune=pentium4 -lm -ffast-math
endif

CFLAGS+= $(DEFINES)
	

all: $(EXE)
.PHONY: all

# Compilation d'objets
%.o: %.c
	$(CC) -c $^ -o $@ $(CFLAGS)
%.o: %.s
	$(AS) $^ -o $@
	

# Compilation de l'exécutable
$(EXE): $(OBJ)
	$(CC) $^ -o $@ $(CFLAGS)


clean: 
	rm $(EXE) *.o
	rm addition/*.o
	rm decalage/*.o
	rm multiplication/*.o
	rm substract/*.o