#
# Makefile generated by stmkmk none
# 
# assume environment variable ST_DIR is defined
# or defint it here
# ST_DIR = 
APP = none

# SGC flags:
# assume environment variable SGC_DIR is defined
# or define it here
# SGC_DIR =
# uncomment following two lines if you use SGC (with stgcc).
# SGC_FLAGS = -DWITH_SGC -I$(SGC_DIR)
# SGC_LIB = --xsgc
# uncomment following two lines if you dont use SGC
SGC_FLAGS = 
SGC_LIB = 

# define some useful targets
include $(ST_DIR)/lib/sthreads.mk

# add C flags and C++ flags
# -DST_DBG=0 -DST_ASSERT_ON=0 -DSTACK_INV_CHECK=0 -DST_STAT=0 
# -DST_PROF=0 -DUSE_SMALLOC
CC_CXX_FLAGS = $(SGC_FLAGS) -D$(ST_THREAD_PKG) -Wall -Wno-unused -g
CFLAGS = $(CC_CXX_FLAGS)
CXXFLAGS = $(CC_CXX_FLAGS)

# add basename of object files
# st_nopp was removed
BASES = ma st th st_sync ws st_nocs st_asm prof os st_lock
OBJS = $(addsuffix .o,$(BASES))
ASMS = $(addsuffix .s,$(BASES))
TASMS = $(addsuffix .t,$(BASES))
PPS = $(addsuffix .t.pp,$(BASES))
TAB_CS = $(addsuffix .t.tab.c,$(BASES))
TAB_SS = $(addsuffix .t.tab.s,$(BASES))
TAB_S_PPS = $(addsuffix .t.tab.s.pp,$(BASES))

ifeq ($(SGC_FLAGS),)
	LIBST_A = libst.a
else
	LIBST_A = libst_sgc.a
endif

ifeq ($(ST_CPU_TYPE),mips)
	ST_ASM_OPTS = -mips2
endif
ifeq ($(ST_CPU_TYPE),sparc)
	ST_ASM_OPTS = -Wa,-xarch=v8plus
endif


default : $(ST_DIR)/lib/$(LIBST_A)

all : 
	($(MAKE) no_sgc; $(MAKE) with_sgc)

no_sgc :
	$(MAKE) clean
	$(MAKE) SGC_FLAGS=""

with_sgc :
	$(MAKE) clean
	$(MAKE) SGC_FLAGS="-DWITH_SGC -I$(SGC_DIR)"

$(ST_DIR)/lib/$(LIBST_A) : $(OBJS)
	ar rcv $(LIBST_A) $(OBJS)
	mv $(LIBST_A) $(ST_DIR)/lib

st_nocs.o : st_nocs.c
	$(CC) $(CFLAGS) --no_callee_saves -c st_nocs.c

st_nocs.s : st_nocs.c
	$(CC) $(CFLAGS) --no_callee_saves -S st_nocs.c

st_nocs.t : st_nocs.c
	$(CC) $(CFLAGS) --no_postprocess --no_callee_saves -S st_nocs.c -o st_nocs.t

st_asm.o : st_asm.c
	$(CC) $(CFLAGS) --no_postprocess -S st_asm.c -o st_asm.t
	gawk -f $(ST_DIR)/bin/asmpp.awk TASK=rem_prologue st_asm.t > st_asm.s
	gcc $(ST_ASM_OPTS) -c st_asm.s
	rm -f st_asm.s st_asm.t

st_asm.s : st_asm.c
	$(CC) $(CFLAGS) --no_postprocess -S st_asm.c -o st_asm.t
	gawk -f $(ST_DIR)/bin/asmpp.awk TASK=rem_prologue st_asm.t > st_asm.s
	rm -f st_asm.t

st_asm.t : st_asm.c
	$(CC) $(CFLAGS) --no_postprocess -S st_asm.c -o st_asm.t

clean : 
	rm -f core 
	rm -f $(OBJS) 
	rm -f $(ASMS) 
	rm -f $(TASMS) 
	rm -f $(TAB_CS) 
	rm -f $(TAB_SS) 
	rm -f $(TAB_S_PPS)
	rm -f $(PPS)

all_clean : clean
	rm -f $(APP)
	rm *~
