# $Revision: #18 $$Date: 2003/03/28 $$Author: wsnyder $ -*- Makefile -*-
# DESCRIPTION: SystemPerl: Example makefile
#
# This is executed in the "test_dir", not in this directory
#

# Sigh... SystemC should provide a program to determine this
TARGET_ARCH = linux
SYSTEMPERL = ..

CC = g++
INCDIR += -I. -I$(SYSTEMPERL)/src -I$(SYSTEMC)/include -I../example
LIBDIR += -L. -L$(SYSTEMPERL)/src -L$(SYSTEMC)/lib-$(TARGET_ARCH)
VPATH += ../example $(SYSTEMPERL)/src
MAKEFILES += ../example/Makefile_obj

SC_LIBS = -lsystemc
ifneq ($(wildcard $(SYSTEMC)/lib-$(TARGET_ARCH)/*numeric_bit*),)
  # Systemc 1.2.1beta
  SC_LIBS   += -lnumeric_bit -lqt
endif

LIBS   =  $(SC_LIBS) -lm $(EXTRA_LIBS)

SP_SP = $(wildcard ../example/*.sp)
# /*AUTOTRACE*/ Looks for this
CFLAGS += -DWAVES

# List Objects in bottom-up order, that way lower modules get errors first
OBJS = $(SP_OBJS) ExMain.o Sp.cpp

default: build

######################################################################

SP_SP_BASE := $(basename $(notdir $(SP_SP)))
SP_H   := $(addsuffix .h,$(SP_SP_BASE))
SP_CPP := $(addsuffix .cpp,$(SP_SP_BASE))
SP_OBJS   := $(addsuffix .o,$(SP_SP_BASE))

build:	preproc ex_main

# Setup as a "always" rule; we don't check for enough sp_preproc dependencies
# In a user example where you weren't editing sp_preproc, you could have:
#preproc $(SP_CPP) $(SP_H): $(SP_SP)
preproc $(SP_CPP) $(SP_H):
	../sp_preproc $(INCDIR) -M sp_preproc.d --tree ex.tree --preproc $(SP_SP)

ex_main:	$(OBJS)
	$(CC) $(CFLAGS) $(INCDIR) $(LIBDIR) -o $@ $^ $(LIBS) 2>&1 | c++filt

.cpp.o:
	$(CC) $(CFLAGS) $(INCDIR) -c $<

run:	ex_main
	./ex_main
