# $Revision: 1.26 $$Date: 2005-03-14 11:52:33 -0500 (Mon, 14 Mar 2005) $$Author: wsnyder $ -*- Makefile -*-
# DESCRIPTION: SystemPerl: Example makefile for Cadence NC-SystemC
#
# This is executed in the "test_dir", not in this directory
#
# Copyright 2005-2005 by Wilson Snyder.  This program is free software;
# you can redistribute it and/or modify it under the terms of either the GNU
# General Public License or the Perl Artistic License.
#

mydefault: build
build:	preproc ncall


SYSTEMPERL = ..

INCDIR += -I. -I$(SYSTEMPERL)/src -I$(SYSTEMC)/include -I../example

SP_SP = $(wildcard ../example/*.sp)

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

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))

SPPREPROC_FLAGS = -M sp_preproc.d --tree ex.tree --preproc --ncsc

# 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):
	perl ../sp_preproc $(INCDIR) $(SPPREPROC_FLAGS) $(SP_SP)


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

OUR_NCSC_CPP = $(SP_CPP) ExMain.cpp $(SYSTEMPERL)/src/Sp.cpp

# The following are user options, that are documented in the NC-SystemC manual
# Makefile method:
ifeq ($(NCSC_USE_MAKEFILE),)
 # Direct ncsc_run method

 OUR_NCSC_FLAGS += -static -sc_main

 # The below is required to work around a bug in ncsc 05.40-p004
 OUR_NCSC_FLAGS += -noedg

 ncall: ncbuild ncrun

 ncbuild: 
	@echo Ncsc_run Build
	ncsc_run $(OUR_NCSC_FLAGS) $(OUR_NCSC_CPP) $(INCDIR) -use ncsim -stop hdl_elab

# ExMain.cpp shouldn't be required, but bug in ncsc 05.40-p004 requires it
 ncrun: 
	@echo Ncsc_run on pre-elaborated design
	ncsc_run -r worklib.sc_main:sc_module ExMain.cpp

##############################
else
 # NCSC Makefile with separate steps

 SYSTEMC_MAKEFILES = $(NC_ROOT)/tools/systemc/files/make
 SYSTEMC_SOURCES = $(OUR_NCSC_CPP)
 VERILOG_SOURCES = 
 COMPILER = gnu
 USER_IFLAGS = 
 USER_LFLAGS = 
 USER_DFLAGS = -g
 USER_LIBS += 
 USER_SIM_OPTIONS =
 USER_ELAB_OPTIONS = 
 USER_VLOG_OPTIONS =
 USER_CPP_OPTIONS += 
 DEBUG = -g
 CPP_EXT = cpp
 ARCH = lnx86
 DESIGN_TOP = 
 SNAPSHOT_NAME = simx
 export LD_LIBRARY_PATH

 include $(SYSTEMC_MAKEFILES)/Makefile.sc

 ncbuild: static

endif
