# $Id: Makefile_obj 11992 2006-01-16 18:59:58Z wsnyder $ -*- Makefile -*-
# DESCRIPTION: SystemPerl: Example makefile
#
# This is executed in the "test_dir", not in this directory
#
# Copyright 2001-2006 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.
#

# Sigh... SystemC should provide a program to determine this
ifeq ($(SYSTEMC_ARCH),)
  SYSTEMC_ARCH = linux
endif
SYSTEMPERL = ..

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

SC_LIBS = -lsystemc
ifneq ($(wildcard $(SYSTEMC)/lib-$(SYSTEMC_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 -Wno-deprecated

ifeq ($(VERILATOR_AUTHOR_SITE),1)	# Local... Else don't burden users
CFLAGS += -Wall -Wno-char-subscripts -Werror -m32
endif

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

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

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

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

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

run:	ex_main
	./ex_main

# Generic wildcard rules

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

