SHELL = /bin/sh

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

srcdir = @srcdir@
VPATH = $(srcdir):$(srcdir)/missing

CC = @CC@
YACC = @YACC@
PURIFY =
AUTOCONF = autoconf
@SET_MAKE@

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

CFLAGS = @CFLAGS@ @XCFLAGS@ @ARCH_FLAG@
CPPFLAGS = -I. -I$(srcdir) @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@

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@

#### 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@

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

EXTOBJS	      = 
DLDOBJS	      = $(DMYEXT)
DMYEXT	      = dmyext.@OBJEXT@

MAINOBJ	      = main.@OBJEXT@

OBJS	      = array.@OBJEXT@ \
		bignum.@OBJEXT@ \
		class.@OBJEXT@ \
		compar.@OBJEXT@ \
		dir.@OBJEXT@ \
		dln.@OBJEXT@ \
		enum.@OBJEXT@ \
		error.@OBJEXT@ \
		eval.@OBJEXT@ \
		file.@OBJEXT@ \
		gc.@OBJEXT@ \
		hash.@OBJEXT@ \
		inits.@OBJEXT@ \
		io.@OBJEXT@ \
		marshal.@OBJEXT@ \
		math.@OBJEXT@ \
		numeric.@OBJEXT@ \
		object.@OBJEXT@ \
		pack.@OBJEXT@ \
		parse.@OBJEXT@ \
		process.@OBJEXT@ \
		prec.@OBJEXT@ \
		random.@OBJEXT@ \
		range.@OBJEXT@ \
		re.@OBJEXT@ \
		regex.@OBJEXT@ \
		ruby.@OBJEXT@ \
		signal.@OBJEXT@ \
		sprintf.@OBJEXT@ \
		st.@OBJEXT@ \
		string.@OBJEXT@ \
		struct.@OBJEXT@ \
		time.@OBJEXT@ \
		util.@OBJEXT@ \
		variable.@OBJEXT@ \
		version.@OBJEXT@ \
		$(MISSING)

MANTYPE	      = @MANTYPE@

SCRIPT_ARGS   =	--dest-dir="$(DESTDIR)" \
		--make="$(MAKE)" \
		--mflags="$(MFLAGS)" \
		--make-flags="$(MAKEFLAGS)"

all:		@MAKEFILES@ miniruby$(EXEEXT) rbconfig.rb $(LIBRUBY)
		@$(MINIRUBY) $(srcdir)/ext/extmk.rb --extstatic="$(EXTSTATIC)" $(SCRIPT_ARGS)

miniruby$(EXEEXT):	config.status $(LIBRUBY_A) $(MAINOBJ) $(DMYEXT)
		@rm -f $@
		$(PURIFY) $(CC) $(LDFLAGS) $(MAINLIBS) $(MAINOBJ) $(DMYEXT) $(LIBRUBY_A) $(LIBS) -o $@

$(PROGRAM):     $(LIBRUBY) $(MAINOBJ) $(EXTOBJS) $(SETUP) miniruby$(EXEEXT)
		@rm -f $@
		$(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@

# 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):	$(OBJS) $(DMYEXT)
		@rm -f $@
		@AR@ rcu $@ $(OBJS) $(DMYEXT)
		@-@RANLIB@ $@ 2> /dev/null || true

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

ruby.imp:	$(LIBRUBY_A)
		@@NM@ -Pgp $(LIBRUBY_A) | awk 'BEGIN{print "#!"}; $$2~/^[BD]$$/{print $$1}' | sort -u -o $@
# $(MINIRUBY) $< $@

install:	install-nodoc @RDOCTARGET@

install-nodoc:	rbconfig.rb
		$(MINIRUBY) $(srcdir)/instruby.rb $(SCRIPT_ARGS) --mantype="$(MANTYPE)"
		$(MINIRUBY) $(srcdir)/ext/extmk.rb $(SCRIPT_ARGS) install

what-where no-install:	rbconfig.rb
		$(MINIRUBY) $(srcdir)/instruby.rb -n $(SCRIPT_ARGS) --mantype="$(MANTYPE)"
		$(MINIRUBY) $(srcdir)/ext/extmk.rb -n $(SCRIPT_ARGS) install

install-doc:
		@echo Generating RDoc documentation
		$(bindir)/$(PROGRAM) $(srcdir)/bin/rdoc --all --ri-system $(srcdir)

clean-ext:
		@-$(MINIRUBY) $(srcdir)/ext/extmk.rb $(SCRIPT_ARGS) clean 2> /dev/null || true

clean-local:
		@rm -f $(OBJS) $(MAINOBJ) $(LIBRUBY_A) $(LIBRUBY_SO) $(LIBRUBY_ALIASES)
		@rm -f ext/extinit.c ext/extinit.@OBJEXT@ dmyext.@OBJEXT@
		@rm -f $(PROGRAM) miniruby$(EXEEXT)

clean: clean-ext clean-local

distclean-ext:
		@-$(MINIRUBY) $(srcdir)/ext/extmk.rb $(SCRIPT_ARGS) distclean 2> /dev/null || true

distclean-local: clean-local
		@rm -f @MAKEFILES@ config.h rbconfig.rb
		@rm -f ext/config.cache config.cache config.log config.status
		@rm -f *~ core *.core gmon.out y.tab.c y.output ruby.imp

distclean: distclean-ext distclean-local

realclean: 	distclean
		@rm -f parse.c
		@rm -f lex.c

test:		miniruby$(EXEEXT) rbconfig.rb $(PROGRAM) PHONY
		@./miniruby$(EXEEXT) $(srcdir)/rubytest.rb

rbconfig.rb:	miniruby$(EXEEXT) $(srcdir)/mkconfig.rb config.status $(PREP)
		@$(MINIRUBY) $(srcdir)/mkconfig.rb rbconfig.rb

fake.rb:	miniruby$(EXEEXT) 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

.PRECIOUS:	@MAKEFILES@

.PHONY:		test install install-nodoc install-doc

PHONY:

@MAKEFILES@: config.status
		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)

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

lex.c: keywords
	@-rm -f $@
	gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@ || \
	cp "$(srcdir)/$@" .

.y.c:
	$(YACC) $<
	sed '/^#/s|y\.tab\.c|$@|' y.tab.c > $@
	rm -f y.tab.c

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

acosh.@OBJEXT@: $(srcdir)/missing/acosh.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/acosh.c

alloca.@OBJEXT@: $(srcdir)/missing/alloca.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/alloca.c

crypt.@OBJEXT@: $(srcdir)/missing/crypt.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/crypt.c

dup2.@OBJEXT@: $(srcdir)/missing/dup2.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/dup2.c

fileblocks.@OBJEXT@: $(srcdir)/missing/fileblocks.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/fileblocks.c

finite.@OBJEXT@: $(srcdir)/missing/finite.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/finite.c

flock.@OBJEXT@: $(srcdir)/missing/flock.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/flock.c

isinf.@OBJEXT@: $(srcdir)/missing/isinf.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/isinf.c

isnan.@OBJEXT@: $(srcdir)/missing/isnan.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/isnan.c

fnmatch.@OBJEXT@: $(srcdir)/missing/fnmatch.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/fnmatch.c

memcmp.@OBJEXT@: $(srcdir)/missing/memcmp.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/memcmp.c

memmove.@OBJEXT@: $(srcdir)/missing/memmove.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/memmove.c

mkdir.@OBJEXT@: $(srcdir)/missing/mkdir.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/mkdir.c

vsnprintf.@OBJEXT@: $(srcdir)/missing/vsnprintf.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/vsnprintf.c

strcasecmp.@OBJEXT@: $(srcdir)/missing/strcasecmp.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strcasecmp.c

strncasecmp.@OBJEXT@: $(srcdir)/missing/strncasecmp.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strncasecmp.c

strchr.@OBJEXT@: $(srcdir)/missing/strchr.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strchr.c

strerror.@OBJEXT@: $(srcdir)/missing/strerror.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strerror.c

strftime.@OBJEXT@: $(srcdir)/missing/strftime.c
	$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strftime.c

strstr.@OBJEXT@: $(srcdir)/missing/strstr.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strstr.c

strtol.@OBJEXT@: $(srcdir)/missing/strtol.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strtol.c

strtoul.@OBJEXT@: $(srcdir)/missing/strtoul.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strtoul.c

x68.@OBJEXT@: $(srcdir)/missing/x68.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/x68.c

os2.@OBJEXT@: $(srcdir)/missing/os2.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/os2.c

dl_os2.@OBJEXT@: $(srcdir)/missing/dl_os2.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/dl_os2.c

win32.@OBJEXT@: $(srcdir)/win32/win32.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -I$(srcdir)/win32 -c $(srcdir)/win32/win32.c

# Prevent GNU make v3 from overflowing arg limit on SysV.
.NOEXPORT:
###
array.@OBJEXT@: array.c ruby.h config.h defines.h intern.h missing.h \
  util.h st.h
bignum.@OBJEXT@: bignum.c ruby.h config.h defines.h intern.h missing.h
class.@OBJEXT@: class.c ruby.h config.h defines.h intern.h missing.h \
  rubysig.h node.h st.h
compar.@OBJEXT@: compar.c ruby.h config.h defines.h intern.h missing.h
dir.@OBJEXT@: dir.c ruby.h config.h defines.h intern.h missing.h util.h
dln.@OBJEXT@: dln.c ruby.h config.h defines.h intern.h missing.h dln.h
dmyext.@OBJEXT@: dmyext.c
enum.@OBJEXT@: enum.c ruby.h config.h defines.h intern.h missing.h node.h \
  util.h
error.@OBJEXT@: error.c ruby.h config.h defines.h intern.h missing.h \
  env.h st.h
eval.@OBJEXT@: eval.c ruby.h config.h defines.h intern.h missing.h node.h \
  env.h util.h rubysig.h st.h dln.h
file.@OBJEXT@: file.c ruby.h config.h defines.h intern.h missing.h \
  rubyio.h rubysig.h util.h dln.h
gc.@OBJEXT@: gc.c ruby.h config.h defines.h intern.h missing.h rubysig.h \
  st.h node.h env.h re.h regex.h
hash.@OBJEXT@: hash.c ruby.h config.h defines.h intern.h missing.h st.h \
  util.h rubysig.h
inits.@OBJEXT@: inits.c ruby.h config.h defines.h intern.h missing.h
io.@OBJEXT@: io.c ruby.h config.h defines.h intern.h missing.h rubyio.h \
  rubysig.h env.h util.h
main.@OBJEXT@: main.c ruby.h config.h defines.h intern.h missing.h
marshal.@OBJEXT@: marshal.c ruby.h config.h defines.h intern.h missing.h \
  rubyio.h st.h util.h
math.@OBJEXT@: math.c ruby.h config.h defines.h intern.h missing.h
numeric.@OBJEXT@: numeric.c ruby.h config.h defines.h intern.h missing.h
object.@OBJEXT@: object.c ruby.h config.h defines.h intern.h missing.h \
  st.h util.h
pack.@OBJEXT@: pack.c ruby.h config.h defines.h intern.h missing.h
parse.@OBJEXT@: parse.c ruby.h config.h defines.h intern.h missing.h \
  env.h node.h st.h regex.h util.h lex.c
prec.@OBJEXT@: prec.c ruby.h config.h defines.h intern.h missing.h
process.@OBJEXT@: process.c ruby.h config.h defines.h intern.h missing.h \
  rubysig.h st.h
random.@OBJEXT@: random.c ruby.h config.h defines.h intern.h missing.h
range.@OBJEXT@: range.c ruby.h config.h defines.h intern.h missing.h
re.@OBJEXT@: re.c ruby.h config.h defines.h intern.h missing.h re.h \
  regex.h
regex.@OBJEXT@: regex.c config.h regex.h
ruby.@OBJEXT@: ruby.c ruby.h config.h defines.h intern.h missing.h dln.h \
  node.h util.h
signal.@OBJEXT@: signal.c ruby.h config.h defines.h intern.h missing.h \
  rubysig.h
sprintf.@OBJEXT@: sprintf.c ruby.h config.h defines.h intern.h missing.h
st.@OBJEXT@: st.c config.h st.h
string.@OBJEXT@: string.c ruby.h config.h defines.h intern.h missing.h \
  re.h regex.h
struct.@OBJEXT@: struct.c ruby.h config.h defines.h intern.h missing.h
time.@OBJEXT@: time.c ruby.h config.h defines.h intern.h missing.h
util.@OBJEXT@: util.c ruby.h config.h defines.h intern.h missing.h util.h
variable.@OBJEXT@: variable.c ruby.h config.h defines.h intern.h \
  missing.h env.h node.h st.h util.h
version.@OBJEXT@: version.c ruby.h config.h defines.h intern.h missing.h \
  version.h
