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

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

top_builddir = ../..
subdir = src/main

include $(top_builddir)/Makeconf

SOURCES = \
	arithmetic.c \
	array.c \
	attrib.c \
	bind.c \
	builtin.c \
	character.c \
	coerce.c \
	colors.c \
	complex.c \
	context.c \
	cov.c \
	cum.c \
	debug.c \
	devPS.c \
	devPicTeX.c \
	deparse.c \
	deriv.c \
	devices.c \
	dotcode.c \
	dstruct.c \
	duplicate.c \
	envir.c \
	errors.c \
	eval.c \
	format.c \
	fourier.c \
	gram.c \
	gram-ex.c \
	graphics.c \
	hdf5.c \
	iosupport.c \
	list.c \
	logic.c \
	main.c \
	match.c \
	memory.c \
	model.c \
	names.c \
	objects.c \
	optimize.c \
	options.c \
	par.c \
	paste.c \
	platform.c \
	plot.c \
	plot3d.c \
	plotmath.c \
	print.c \
	printarray.c \
	printvector.c \
	printutils.c \
	random.c \
	relop.c \
	saveload.c \
	scan.c \
	seq.c \
	sort.c \
	source.c \
	split.c \
	subassign.c \
	subscript.c \
	subset.c \
	summary.c \
	unique.c \
	util.c \
	version.c
SOURCES_F = \
	xxxpr.f
DEPENDS = $(SOURCES:.c=.d)
OBJECTS = $(SOURCES:.c=.o) $(SOURCES_F:.f=.o) ../regex/regex.o
ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) -I$(top_srcdir)/src/regex $(CPPFLAGS) $(DEFS) 

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = $(SOURCES) arithmetic.h names.h gram.y

RLIBS = ../unix/libunix.a ../appl/libappl.a ../nmath/libmath.a
RGNOMELIBS = ../gnome/libRgnome.a ../appl/libappl.a ../nmath/libmath.a

ALL_X_LIBS = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
ALL_LIBS = $(RLIBS) $(ALL_X_LIBS) $(FLIBS) $(R_XTRA_LIBS) $(LIBS)
ALL_GNOME_LIBS = $(RGNOMELIBS) $(FLIBS) $(R_XTRA_LIBS) $(LIBS) $(GNOME_LIBDIR) $(GNOMEUI_LIBS) $(LIBGLADE_LIBS)

all: Makefile Makedeps R

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

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

R: Makefile
	@for t in Makedeps $(top_builddir)/bin/R.X11 @RGNOMEBIN@; do \
	  $(MAKE) $${t}; \
	done

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

$(top_builddir)/bin/R.X11: $(OBJECTS) $(RLIBS) @EXPORTFILE@
	@$(MKINSTALLDIRS) $(top_builddir)/bin
	$(LDCMD) $(DLLFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(ALL_LIBS)

$(top_builddir)/bin/R.gnome: $(OBJECTS) $(RGNOMELIBS)
	@$(MKINSTALLDIRS) $(top_builddir)/bin
	$(LDCMD) $(DLLFLAGS) $(LDFLAGS) $(GNOME_LIBDIR) -o $@ $(OBJECTS) $(ALL_GNOME_LIBS)

$(top_builddir)/etc/R.exp: $(OBJECTS) $(RLIBS)
	@$(top_srcdir)/tools/ldAIX4 -o $@ $(OBJECTS) $(RLIBS)

../unix/libunix.a:
	(cd ../unix;  $(MAKE) $(@F))
../appl/libappl.a:
	(cd ../appl;  $(MAKE) $(@F))
../nmath/libmath.a:
	(cd ../nmath; $(MAKE) $(@F))
../regex/regex.o:
	(cd ../regex; $(MAKE) $(@F))

gram.c: $(srcdir)/gram.y
	$(YACC) $(YFLAGS) $(srcdir)/gram.y
	$(top_srcdir)/tools/move-if-change y.tab.c $(@F)

mostlyclean: clean
clean:
	@echo "Cleaning in $(subdir)"
	@-rm -f R.binary R.X11 R.gnome R-Image *core Makedeps *.d *.o
distclean: clean
	@-rm -f Makefile
maintainer-clean: distclean
	@rm -f gram.c

tags: *.h *.c
	ctags *.h *.c
TAGS: *.h *.c
	etags *.h *.c

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

# Unused targets

install install-strip uninstall info dvi check::

## Automagically generated dependencies:

