SHELL = /bin/sh
NULLCMD = :

#### Start of system configuration section. ####

srcdir = @srcdir@
hdrdir = $(srcdir)/include

CC = @CC@
YACC = bison
PURIFY =
AUTOCONF = autoconf
@SET_MAKE@
MKFILES = @MAKEFILES@
BASERUBY = @BASERUBY@

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libdir = @libdir@
libexecdir = @libexecdir@
datarootdir = @datarootdir@
datadir = @datadir@
arch = @arch@
sitearch = @sitearch@
sitedir = @sitedir@

TESTUI = console
TESTS =
RDOCTARGET = @RDOCTARGET@

EXTOUT = @EXTOUT@
RIDATADIR = $(DESTDIR)$(datadir)/ri/$(MAJOR).$(MINOR)/system
arch_hdrdir = $(EXTOUT)/include/$(arch)
VPATH = $(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir):$(srcdir)/enc:$(srcdir)/missing

empty =
OUTFLAG = @OUTFLAG@$(empty)
COUTFLAG = @COUTFLAG@$(empty)
CFLAGS = @CFLAGS@ @ARCH_FLAG@
XCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir) -I$(srcdir) @XCFLAGS@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@
EXTLDFLAGS = 
XLDFLAGS = @XLDFLAGS@ $(EXTLDFLAGS)
EXTLIBS = 
LIBS = @LIBS@ $(EXTLIBS)
MISSING = @LIBOBJS@ @ALLOCA@
LDSHARED = @LIBRUBY_LDSHARED@
DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(EXTLDFLAGS) @ARCH_FLAG@
SOLIBS = @SOLIBS@
MAINLIBS = @MAINLIBS@
MINIOBJS = @MINIOBJS@ miniprelude.$(OBJEXT)
BUILTIN_ENCOBJS = @BUILTIN_ENCOBJS@

RUBY_INSTALL_NAME=@RUBY_INSTALL_NAME@
RUBY_SO_NAME=@RUBY_SO_NAME@
EXEEXT = @EXEEXT@
PROGRAM=$(RUBY_INSTALL_NAME)$(EXEEXT)
RUBY = $(RUBY_INSTALL_NAME)
MINIRUBY = @MINIRUBY@ $(MINIRUBYOPT)
RUNRUBY = @RUNRUBY@ $(RUNRUBYOPT) --

#### End of system configuration section. ####

MAJOR=	@MAJOR@
MINOR=	@MINOR@
TEENY=	@TEENY@

LIBRUBY_A     = @LIBRUBY_A@
LIBRUBY_SO    = @LIBRUBY_SO@
LIBRUBY_ALIASES= @LIBRUBY_ALIASES@
LIBRUBY	      = @LIBRUBY@
LIBRUBYARG    = @LIBRUBYARG@
LIBRUBYARG_STATIC = @LIBRUBYARG_STATIC@
LIBRUBYARG_SHARED = @LIBRUBYARG_SHARED@

THREAD_MODEL  = @THREAD_MODEL@

PREP          = @PREP@
ARCHFILE      = @ARCHFILE@
SETUP         =
EXTSTATIC     = @EXTSTATIC@

CP            = cp
MV            = mv
RM            = rm -f
NM            = @NM@
AR            = @AR@
ARFLAGS       = rcu
RANLIB        = @RANLIB@
AS            = @AS@
ASFLAGS       = @ASFLAGS@

OBJEXT        = @OBJEXT@
ASMEXT        = S
DLEXT         = @DLEXT@
MANTYPE	      = @MANTYPE@

INSTALLED_LIST= .installed.list
#### End of variables

all:

.DEFAULT: all

# Prevent GNU make v3 from overflowing arg limit on SysV.
.NOEXPORT:

miniruby$(EXEEXT):
		@$(RM) $@
		$(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(MAINOBJ) $(MINIOBJS) $(COMMONOBJS) $(DMYEXT) $(ARCHFILE) $(LIBS) $(OUTFLAG)$@

$(PROGRAM):
		@$(RM) $@
		$(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) $(OUTFLAG)$@

# We must `rm' the library each time this rule is invoked because "updating" a
# MAB library on Apple/NeXT (see --enable-fat-binary in configure) is not
# supported.
$(LIBRUBY_A):
		@$(RM) $@
		$(AR) $(ARFLAGS) $@ $(OBJS) $(DMYEXT)
		@-$(RANLIB) $@ 2> /dev/null || true

$(LIBRUBY_SO):
		@-$(PRE_LIBRUBY_UPDATE)
		$(LDSHARED) $(DLDFLAGS) $(OBJS) $(DLDOBJS) $(SOLIBS) $(OUTFLAG)$@
		@-$(MINIRUBY) -e 'ARGV.each{|link| File.delete link if File.exist? link; \
						  File.symlink "$(LIBRUBY_SO)", link}' \
				$(LIBRUBY_ALIASES) || true

fake.rb:	Makefile
		@echo ' \
		class Object; \
		  CROSS_COMPILING = RUBY_PLATFORM; \
		  remove_const :RUBY_PLATFORM; \
		  remove_const :RUBY_VERSION; \
		  RUBY_PLATFORM = "@arch@"; \
		  RUBY_VERSION = "@MAJOR@.@MINOR@.@TEENY@"; \
		end; \
		if RUBY_PLATFORM =~ /mswin|bccwin|mingw/; \
		  class File; \
		    remove_const :ALT_SEPARATOR; \
		    ALT_SEPARATOR = "\\"; \
		  end; \
		end; \
		' > $@

Makefile:	$(srcdir)/Makefile.in

$(MKFILES): config.status $(srcdir)/common.mk
		MAKE=$(MAKE) $(SHELL) ./config.status
		@{ \
		    echo "all:; -@rm -f conftest.mk"; \
		    echo "conftest.mk: .force; @echo AUTO_REMAKE"; \
		    echo ".force:"; \
		} > conftest.mk || exit 1; \
		$(MAKE) -f conftest.mk | grep '^AUTO_REMAKE$$' >/dev/null 2>&1 || \
		{ echo "Makefile updated, restart."; exit 1; }

config.status:	$(srcdir)/configure
		MINIRUBY="$(MINIRUBY)" $(SHELL) ./config.status --recheck

$(srcdir)/configure: $(srcdir)/configure.in
		cd $(srcdir) && $(AUTOCONF)

# Things which should be considered:
# * with gperf v.s. without gperf
# * ./configure v.s. ../ruby/configure
# * GNU make v.s. HP-UX make	# HP-UX make invokes the action if lex.c and keywords has same mtime.
# * svn checkout generate a file with mtime as current time
# * XFS has a mtime with fractional part
lex.c: keywords
	if cmp -s $(srcdir)/lex.c.src $?; then \
	  cp $(srcdir)/lex.c.blt $@; \
	else \
	  gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@.tmp && \
	  mv $@.tmp $@ && \
	  cp $? $(srcdir)/lex.c.src && \
	  cp $@ $(srcdir)/lex.c.blt; \
	fi

.c.@OBJEXT@:
	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c $<

.s.@OBJEXT@:
	$(AS) $(ASFLAGS) -o $@ $<

.c.S:
	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -S $<

clean-local::
	@$(RM) ext/extinit.c ext/extinit.$(OBJEXT)

distclean-local::
	@$(RM) ext/config.cache $(RBCONFIG)

ext/extinit.$(OBJEXT): ext/extinit.c $(SETUP)
	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c ext/extinit.c
