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

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

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

include $(top_builddir)/Makeconf

SOURCES_C = \
	@LIBOBJS@ \
	apply.c \
	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 \
	g_her_glyph.c \
	g_fontdb.c \
	g_cntrlify.c \
	g_alab_her.c \
	gram.c \
	gram-ex.c \
	graphics.c \
	iosupport.c \
	list.c \
	logic.c \
	main.c \
	match.c \
	memory.c \
	model.c \
	names.c \
	objects.c \
	optim.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 \
	RNG.c \
	regex.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:.c=.d)
OBJECTS = $(SOURCES_C:.c=.o) $(SOURCES_F:.f=.o)
HEADERS = \
	arithmetic.h \
	g_cntrlify.h \
	g_control.h \
	g_extern.h \
	g_her_metr.h \
	g_jis.h \
	names.h \
	regex.h

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = Makefile.in Makefile.win \
	$(HEADERS) \
	$(SOURCES_C) \
	strdup.c \
	$(SOURCES_F) \
	gram.y

RLIBS = ../unix/libunix.a ../appl/libappl.a ../nmath/libmath.a

ALL_LIBS = $(RLIBS) $(LIBS) $(BLAS_LIBS) $(FLIBS) $(R_XTRA_LIBS)

all: Makefile Makedeps R

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

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

R: Makefile
	@$(MAKE) Makedeps
	@$(MAKE) $(top_builddir)/bin/R.bin
	@(cd ../unix && $(MAKE) DLLs)

../include/config.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.bin: $(OBJECTS) $(RLIBS) @EXPORTFILE@
	@$(MKINSTALLDIRS) $(top_builddir)/bin
	$(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(ALL_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))

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 *core Makedeps *.d *.o
distclean: clean
	@-rm -f Makefile
maintainer-clean: distclean
	@echo "This command is intended for maintainers to use; it"
	@echo "deletes files that may need special rules to rebuild"
	@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: