# $Id: Makefile,v 1.12 2003/02/16 21:56:35 mikpe Exp $

SHELL=/bin/sh
CC=gcc
CFLAGS=-O2 -fomit-frame-pointer -Wall
INCLDIR=../linux/include
CPPFLAGS=-I$(INCLDIR)
AR=ar
ARFLAGS=ruv
RANLIB=ranlib
EVENT_SET_OBJS=event_set.o event_set_amd.o event_set_centaur.o\
	event_set_p4.o event_set_p5.o event_set_p6.o
OBJS=global.o misc.o virtual.o $(EVENT_SET_OBJS)

# Prevent 16-byte stack alignment crap in gcc-2.95.
CFLAGS += $(shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -x c /dev/null > /dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi)

# this code does not need -fno-strict-aliasing

default:	libperfctr.a event_codes.h

libperfctr.a:	$(OBJS)
	$(AR) $(ARFLAGS) libperfctr.a $(OBJS)
	$(RANLIB) libperfctr.a

libperfctr.so:	$(OBJS)
	$(CC) -shared $(OBJS) -o $@

$(OBJS):	libperfctr.h $(INCLDIR)/linux/perfctr.h $(INCLDIR)/asm/perfctr.h
$(EVENT_SET_OBJS):	event_set.h

$(INCLDIR)/asm/perfctr.h:
	cd ..; make configure

event_codes.h:	gen-event-codes
	./gen-event-codes > $@

gen-event-codes:	gen-event-codes.c $(EVENT_SET_OBJS)
	$(LINK.c) $^ -o $@

distclean realclean:	clean

clean:
	rm -f libperfctr.a libperfctr.so $(OBJS) gen-event-codes event_codes.h
