CC=gcc
TARG=$(subst -, ,$(shell $(CC) -dumpmachine))

# OS specific options

ifneq ($(filter mingw32%,$(TARG)),)
  OS_EXTRA_OBJS = $(EXTRA_OBJS) win32-profil.o
endif
ifneq ($(filter solaris%,$(TARG)),)
  OS_EXTRA_OBJS = prof-freq.o
  OS_CFLAGS = -D_SOLARIS_
  OS_ASFLAGS = -D_SOLARIS_
endif

# CPU specific options

ifneq ($(filter %86 pentium,$(TARG)),)
  CPU = i386
  CPU_EXTRA_OBJS = arch/$(CPU)/mcount.o
endif
ifneq ($(filter sparc,$(TARG)),)
  CPU = sparc
  CPU_CFLAGS = -Wa,-xarch=v8plus
endif
ifneq ($(filter sparc64,$(TARG)),)
  CPU = sparc
  CPU_CFLAGS = -DSPARC64
endif
ifneq ($(filter x86-64 x86_64,$(TARG)),)
  CPU = x86_64
  CPU_EXTRA_OBJS = arch/$(CPU)/mcount.o
endif

OBJS:=gmon.o mcount.o $(OS_EXTRA_OBJS) $(CPU_EXTRA_OBJS)

CFLAGS=-O2 -Wall -I. -Iarch/$(CPU) $(OS_CFLAGS) $(CPU_CFLAGS)
ASFLAGS=-Iarch/$(CPU) $(OS_ASFLAGS)

all: libgnatmon.a

libgnatmon.a: $(OBJS)
	ar rc $@ $(OBJS)

$(OBJS): gmon.h profil.h arch/$(CPU)/atomic.h arch/$(CPU)/mcount.h

clean:
	$(RM) *.o *~ *.a *.dll arch/$(CPU)/*.o
