# Rules to construct .ss's from component files.

##############################################################################
#
# .h -> .ss conversion rules
#

# Clear ALLSSFILES
ALLSSFILES =

ifneq (,$(HFILES))
HSSFILES := $(HFILES:%.h=%.ss)
$(HSSFILES) : %.ss : %.h
	$(SALIVATE) $(SALIVATE-FLAGS) $< > $@
ALLSSFILES := $(ALLSSFILES) $(HSSFILES)
endif

ifneq (,$(HHFILES))
HHSSFILES := $(HHFILES:%.hh=%.ss)
$(HHSSFILES) : %.ss : %.hh
	@ cat $< > $(sstotmp)
	@ for i in ${HHDIRS} ; do if test -r $$i/$(sstoh) ; then \
          cat $$i/$(sstoh) >> $(sstotmp) ; fi ; done
	$(SALIVATE) $(SALIVATE-FLAGS) $(sstotmp) > $@
	@ rm -f $(sstotmp)
ALLSSFILES := $(ALLSSFILES) $(HHSSFILES)
endif

TOTALSSFILES := $(ALLSSFILES) $(OTHERSSFILES)

LIBTARGET := $(addprefix lib,$(addsuffix .so,$(basename $(TARGET))))

ifneq (,$(TOTALSSFILES))
$(TARGET): $(TOTALSSFILES)
	@ echo -n "**** Creating Meta-ss file "$(TARGET)" ... "
	@ echo '(load-shared-object "'$(LIBTARGET)'")' > $@
ifeq (,$(STRAIGHTINCLUDE))
	@ echo '(define dl-handle (dlopen "'$(LIBTARGET)'" 2))' >> $@
	@ for i in ${TOTALSSFILES} ; do echo '  ('load-once '"'$$i'")' >> $@ ; done
else
	@ for i in ${TOTALSSFILES} ; do echo '  ('load-once '"'$$i'")' >> $@ ; done
endif
	@ echo "done"
endif

ifneq (,$(ALLSSFILES))
clean::
	rm -f $(TARGET) $(ALLSSFILES)
endif

cleanall: clean
	rm -f $(TARGET)

list:
	@ echo $(TARGET)
