# Makefile for .a archive libraries

# We *do* need -prelink when making an archive of C++ code.  To
# facilitate this, we use the C++ compiler to build the archive.  This
# is only necessary, of course, on SGI.

ALLOFILES := $(ALLOFILES) $(OFILES)


ifeq (,$(USE_DEFERRED))
  DEFERRED_TARGET :=
endif

ifneq (,$(DEFERRED_TARGET))

  # If the makefile requests a "deferred target", it means that we'll
  # just write out a mini-makefile that defines the .o files that go
  # into the target, rather than actually building the target now.
  # Another Makefile later will presumably do the actual building.

  DEFERRED_MAKEFILE := Deferred.$(DEFERRED_TARGET).$(BASETARGET)
  THISDIR := $(notdir $(shell pwd))

$(TARGET) : $(DEFERRED_MAKEFILE)
$(DEFERRED_MAKEFILE):
	rm -f $@
	echo ALLOFILES += $(patsubst ./%,../../$(THISDIR)/%,$(ALLOFILES)) > $@

else # DEFERRED_TARGET

  ifneq (,$(strip $(ALLOFILES)))
  $(TARGET): $(OFILES)   # *not* ALLOFILES
    ifeq (SGI,$(PENV))
	$(C++) -ar -o $@ $(ALLOFILES) 
    else
	$(AR) $(ARFLAGS) $@ $(ALLOFILES) 
    endif
  endif

endif # DEFERRED_TARGET

clean::
	@rm -f a.out.$(TARGET)

cleanall: clean
	rm -rf ii_files
	rm -f $(TARGET)

list:
	@echo $(TARGET)
