################################################################################
# microbenchmark-instructions                                                  #
# (C) Jean-Pierre Lozi, 2013                                                   #
################################################################################

SHELL=/bin/bash
PROJECT=instruction-microbenchmarks


ifeq ($(shell uname),SunOS)
CFLAGS=-O3 -pthread -I$(HOME)/usr/include/
LDFLAGS=-lpthread $(HOME)/usr/lib/libpapi.so
else
CFLAGS=-O3 -pthread
LDFLAGS=-lpthread -lpapi -lnuma
endif


Echo=@echo -e "[$(PROJECT)]"

ifndef VERBOSE
  Verb := @
endif


ifeq ($(shell uname),SunOS)
all: cas store cas_gethrtime store_gethrtime
else
all: cas store
endif


cas: cas.o
	$(Echo) Building \'$@\'
	$(Verb) gcc -o $@ cas.o $(LDFLAGS)

cas.o: cas_vs_store.c
	$(Echo) Compiling $<
	$(Verb) gcc -DWITH_CAS -c $(CFLAGS) "$<" -o "$@"

cas_gethrtime: cas_gethrtime.o
	$(Echo) Building \'$@\'
	$(Verb) gcc -o $@ cas_gethrtime.o $(LDFLAGS)

cas_gethrtime.o: cas_vs_store.c
	$(Echo) Compiling $<
	$(Verb) gcc -DWITH_CAS -DWITH_GETHRTIME -c $(CFLAGS) "$<" -o "$@"

store: store.o
	$(Echo) Building \'$@\'
	$(Verb) gcc -o $@ store.o $(LDFLAGS)

store.o: cas_vs_store.c
	$(Echo) Compiling $<
	$(Verb) gcc -DWITH_STORE -c $(CFLAGS) "$<" -o "$@"

store_gethrtime: store_gethrtime.o
	$(Echo) Building \'$@\'
	$(Verb) gcc -o $@ store_gethrtime.o $(LDFLAGS)

store_gethrtime.o: cas_vs_store.c
	$(Echo) Compiling $<
	$(Verb) gcc -DWITH_STORE -DWITH_GETHRTIME -c $(CFLAGS) "$<" -o "$@"


clean:
	rm -rf *.o cas store cas_gethrtime store_gethrtime

