#
# ${R_HOME}/src/unix/Makefile

VPATH = @srcdir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@

top_builddir = ../..
subdir = src/unix

include $(top_builddir)/Makeconf

ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) $(CPPFLAGS) $(DEFS)

SOURCES = devices.c dynload.c edit.c stubs.c system.c sys-unix.c \
          sys-common.c sys-std.c
DEPENDS = $(SOURCES:.c=.d)
OBJECTS = $(SOURCES:.c=.o)
HEADERS = Runix.h devUI.h

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = \
	Makefile.in PSPAPER $(SOURCES) $(HEADERS) \
	hpdlfcn.c system.txt

SUBDIRS = X11 gnome

LIB = libunix.a

all: Makefile Makedeps R

Makefile: $(srcdir)/Makefile.in \
  $(top_builddir)/config.status \
  ../include/Rversion.h \
  ../include/FFDecl.h \
  ../include/FFTab.h \
  $(SOURCES)
	@cd $(top_builddir) && \
	  CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= \
	  $(SHELL) ./config.status

Makedeps: Makefile $(DEPENDS)
	@cat $(DEPENDS) >> Makefile
	@touch $@

R: Makefile
	@$(MAKE) Makedeps
	@$(MAKE) $(LIB)

DLLs:
	@for g in $(R_GUIS) ""; do \
	  if test -n "$${g}"; then \
	    (cd $${g} && $(MAKE) R) || exit 1; \
	  fi; \
	done

../include/Rversion.h:
	(cd ../include; $(MAKE) $(@F))
../include/FFDecl.h ../include/FFTab.h: $(top_srcdir)/src/appl/ROUTINES
	(cd ../include; $(top_srcdir)/tools/GETSYMBOLS)

$(LIB): $(OBJECTS)
	$(AR) cr $(LIB) $(OBJECTS)
	$(RANLIB) $(LIB)

mostlyclean: clean
clean:
	@echo "cleaning in $(subdir)"
	@for g in $(R_GUIS) ""; do \
	  if test -n "$${g}"; then \
	    (cd $${g} && $(MAKE) $@); \
	  fi; \
	done
	@-rm -f Makedeps *.d *.o *.a
distclean: clean
	@for g in $(R_GUIS) ""; do \
	  if test -n "$${g}"; then \
	    (cd $${g} && $(MAKE) $@); \
	  fi; \
	done
	@for d in $(SUBDIRS); do \
	  rm -f $${d}/Makefile; \
	done
	@-rm -f Makefile
maintainer-clean: distclean

distdir: $(DISTFILES)
	@for f in $(DISTFILES); do \
	  test -f $(distdir)/$${f} \
	    || ln $(srcdir)/$${f} $(distdir)/$${f} 2>/dev/null \
	    || cp -p $(srcdir)/$${f} $(distdir)/$${f}; \
	done
	@for d in $(SUBDIRS); do \
	  test -d $(distdir)/$${d} \
	    || mkdir $(distdir)/$${d} \
	    || exit 1; \
	  chmod 755 $(distdir)/$${d}; \
	  (cd $${d} && $(MAKE) distdir) \
	    || exit 1; \
	done

## Automagically generated dependencies: