
OMP?=1
CC = gcc

here  = $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
utestdir = $(here)
root := $(utestdir)/..

srcdir = $(root)/src
libdir = $(root)/lib
bindir = $(root)/bin

OPT = -O3 -ffast-math -g
CPPFLAGS ?= -Wall -Wextra
CFLAGS ?= $(OPT) -Wmissing-prototypes

BART_H := -I$(srcdir)
BART_L := -L$(libdir)

ifeq ($(OMP),1)
CFLAGS += -fopenmp
else
CFLAGS += -Wno-unknown-pragmas
endif

CFLAGS += -std=c99 $(BART_H) $(BART_L)

BART_MODULES = num misc num misc

UTARGETS = test_flpmath


# define space to faciliate running executables
define \n


endef



BART_LIBS = $(patsubst %, $(libdir)/lib%.a, $(BART_MODULES))
BART_LLIBS = $(patsubst %, -l%, $(BART_MODULES))

default: utests .gitignore

$(UTARGETS): % : %.o $(BART_LIBS)
	$(CC) $(CFLAGS) -o $@ $< $(BART_LLIBS) -lm 

%.o: %.c %.h
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<


utests: $(UTARGETS)

run: utests
	$(patsubst %,$(\n)./%,$(UTARGETS))

.gitignore: .gitignore.main Makefile
	@echo '# AUTOGENERATED. DO NOT EDIT. (are you looking for .gitignore.main ?)' > .gitignore
	cat .gitignore.main >> .gitignore
	@echo $(patsubst %, /%, $(UTARGETS)) | tr ' ' '\n' >> .gitignore

all: default run


clean:
	rm -f `find $(utestdir) -name "*.o"`

allclean: clean
	rm -f $(patsubst %, %, $(UTARGETS))

