define cvs_srcs $(addprefix $(1),$(shell cut -d/ -f2 $(1)CVS/Entries | grep -e '\.[chy]$$' | sort)) endef or = $(if $(1),$(1),$(2)) ifeq ($(wildcard CVS/Entries),) SRCS := $(filter-out parse.c,$(wildcard *.[chy] missing/*.[ch] win32/win32.[ch] win32/dir.h)) else SRCS := $(call cvs_srcs) $(call cvs_srcs,missing/) $(call cvs_srcs,win32/) endif ifndef TESTS ifneq ($(wildcard .tests),) TESTS := $(shell cat .tests) endif endif nonexec := print-database := $(foreach mflags,$(filter-out --%,$(filter -%,$(MFLAGS) $(MAKEFLAGS))),\ $(if $(filter $(subst n,,$(mflags)),$(mflags)),,$(eval nonexec := t))\ $(if $(filter $(subst p,,$(mflags)),$(mflags)),,$(eval print-database := t))\ ) MESSAGE = $(if $(nonexec),,@echo ")<=== $(1) $(if $(2),$(2),$@) ===>$(if $(nonexec),,") STARTING = $(call MESSAGE,{{{starting,$(1)) FINISHED = $(call MESSAGE,}}}finished,$(1)) CMDSTARTING = $(if $(filter $@,$(MAKECMDGOALS)),,$(call STARTING,$(1))) CMDFINISHED = $(if $(filter $@,$(MAKECMDGOALS)),$(call FINISHED,$(1))) ifeq ($(print-database),) TOPMAKE = $(MAKE) else TOPMAKE = endif CMDVARS := $(filter-out subdirs=%,$(-*-command-variables-*- :=)) MFLAGS := $(if $(EXTOUT),EXTOUT=$(EXTOUT)) $(if $(RDOCOUT),RDOCOUT=$(RDOCOUT)) makeflags := $(filter-out --%,$(MAKEFLAGS)) make-default = $(MAKE) -C $(1) config-default = cd $(@D); \ sh $(if $(wildcard $@), $(shell sed -n 's/^srcdir=//p' $@),$(PWD))/$(CONFIGURE) \ $(if $(wildcard $@), $(shell sed -n 's/^s,@configure_args@,\(.*\),;t t$$/\1/p' $@)) nmake := $(shell which nmake 2>&1) bcc32 := $(shell which bcc32 2>&1) ifneq ($(nmake),) make-mswin32 = $(if $(nonexec),,@echo $(call make-default,$(1));) cd $(1); unset MAKEFLAGS; \ nmake -l $(makeflags) $(MFLAGS) #make-mswin32 = nmake -C"$(1)" -l $(filter-out --%,$(MAKEFLAGS)) $(MFLAGS) configure-mswin32 = win32/Makefile.sub config-mswin32 = cd $(@D); \ $(if $(wildcard $@), $(shell sed -n 's/^srcdir=//p' $@),$(PWD))/win32/configure.bat endif ifneq ($(bcc32),) make-bccwin32 = $(if $(nonexec),,@echo $(call make-default,$(1));) cd $(1); unset MAKEFLAGS; \ PATH="$(dir $(bcc32)):$$PATH" make $(makeflags) $(MFLAGS) #make-bccwin32 = bmake -C"$(1)" $(filter-out --%,$(MAKEFLAGS)) $(MFLAGS) configure-bccwin32 = bcc32/Makefile.sub config-bccwin32 = cd $(@D); \ $(if $(wildcard $@), $(shell sed -n 's/^srcdir=//p' $@),$(PWD))/bcc32/configure.bat endif common.mk := $(wildcard common.mk) configure-default = Makefile.in $(common.mk) $(subdir)/config.status submake = $(strip $(call $(if $(make-$(target)),make-$(target),make-default),$(@D)) $(CMDVARS)) AUTOCONF = autoconf RM = rm -f CVS = cvs ifndef subdirs subdirs := $(sort $(patsubst %/,%,$(dir $(wildcard */Makefile .[^.]*/Makefile */config.status .[^.]*/config.status)))) endif ostype = $(word 2,$(subst -, ,$1)) target = $(call ostype,$(@D)) CONFIGURE_IN := $(wildcard configure.in) CONFIGURE = $(CONFIGURE_IN:.in=) PARSE_Y := $(wildcard parse.y) LEX_C := $(if $(wildcard keywords),lex.c) RIPPER := $(if $(wildcard ext/ripper/depend),ripper) PREREQ = .force $(CONFIGURE) $(PARSE_Y:.y=.c) $(LEX_C) NATIVEARCH := $(patsubst %/Makefile,%,$(shell grep -l '^PREP *= *miniruby' $(subdirs:=/Makefile) /dev/null)) DEFAULTARCH := $(word 1, $(filter $(ARCH) .$(ARCH),$(NATIVEARCH)) $(NATIVEARCH)) MINIRUBY := $(DEFAULTARCH)/miniruby BISON = bison PWD := $(shell pwd) #subdirs := $(filter-out $(DEFAULTARCH),$(subdirs)) $(DEFAULTARCH) export RUBY := $(if $(patsubst /%,,$(MINIRUBY)),$(PWD)/$(MINIRUBY),$(MINIRUBY)) export RUBYLIB=.:$(EXTOUT):$(PWD)/lib PAGER ?= less ifeq ($(origin MAKEFILE_LIST),undefined) MAKEFILE_LIST := $(wildcard GNUmakefile Makefile makefile $(MAKEFILES)) endif EXTOUT ?= ../.ext RDOCOUT ?= ../.rdoc RBCONFIG ?= ./.rbconfig.time export EXTOUT RDOCOUT RBCONFIG localgoals := $(shell sed -n 's/^\([A-Za-z0-9_][-A-Za-z0-9_./]*\):\([^=].*\|$$\)/\1/p' $(MAKEFILE_LIST)) localgoals := $(filter-out all,$(localgoals)) goals := $(filter-out $(localgoals) $(PREREQ),$(call or,$(MAKECMDGOALS),all)) cmdgoals := $(filter-out $(subdirs:=/%),$(goals)) subdir-goals := $(filter $(subdirs:=/%),$(goals)) .pre-%: $(call STARTING,$*) .post-%: $(call FINISHED,$*) all: $(MINIRUBY): $(PREREQ) $(dir $(MINIRUBY))Makefile .pre-host-miniruby $(submake) $(if $(TOPMAKE),,TOPMAKE=$(MAKE)) $(@F) $(call FINISHED,host-miniruby) #$(filter-out $(MINIRUBY),$(subdir-goals)): prereq # $(submake) $(@F) #$(addprefix %/,$(cmdgoals)): prereq # $(submake) $(filter $(MAKECMDGOALS),$(cmdgoals)) define subdircmd $(if $(configure-$(call ostype,$(1))), $(1)/config.status: $(value configure-$(call ostype,$(1))) $(common.mk) $(1)/Makefile $(1)/Makefile:; , $(1)/Makefile: $$(configure-default) cd $$(@D); sh config.status ) $(1)/config.status: $$(submake) TOPMAKE=$(value TOPMAKE) $$(@F) $(1)/%: .PHONY prereq $$(submake) TOPMAKE=$(value TOPMAKE) $$(@F) endef $(foreach subdir,$(subdirs),$(eval $(call subdircmd,$(subdir)))) phony-filter = up UP tags TAGS prereq-filter = prereq .pre-prereq $(PREREQ) $(RIPPER) config Makefile $(MINIRUBY) $(phony-filter) subdir-filter = $(subdirs:=/%) $(localgoals) $(PREREQ) $(foreach goal,all $(filter-out $(prereq-filter),$(MAKECMDGOALS)),$(eval $(value goal): prereq)) $(foreach goal,all $(filter-out $(phony-filter),$(MAKECMDGOALS)),$(eval $(value goal): .pre-$(value goal))) $(foreach goal,all $(filter-out $(subdir-filter),$(MAKECMDGOALS)),$(eval $(value goal): $$(subdirs:=/$(value goal)))) $(foreach goal,$(filter-out $(phony-filter),$(cmdgoals)),$(eval $(value goal):\; $$(FINISHED))) prereq: .pre-prereq $(PREREQ) $(RIPPER) config Makefile @-sync $(FINISHED) #miniruby:; Makefiles: Makefile Makefile: .pre-Makefile $(subdirs:=/Makefile) .post-Makefile config: .pre-config $(subdirs:=/config.status) .post-config rbconfig: prereq .pre-rbconfig $(subdirs:=/$(RBCONFIG:./%=%)) .post-rbconfig %.c: %.y $(BISON) $(YFLAGS) -o $@ $< $(CMDFINISHED) configure: configure.in +$(AUTOCONF) lex.c: keywords @-$(RM) $@ gperf -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@ ripper: $(MINIRUBY) .PHONY $(CMDSTARTING) $(if $(TOPMAKE),$(MAKE),$(MAKE)) -C ext/ripper -f depend hdrdir=../.. srcdir=. $(FINISHED) prep: up prereq up: $(CVS) -qf up UP: .PHONY $(CVS) -f up | $(PAGER) +/^C tags: TAGS TAGS: $(SRCS) etags $(SRCS) install: install-nodoc install-nodoc: install-local install-ext install-local: prereq pre-install-local install-bin install-lib post-install-local install-bin: $(subdirs:=/install-bin) install-lib: $(DEFAULTARCH)/install-lib install-ext: pre-install-ext $(DEFAULTARCH)/install-ext post-install-ext install-doc: $(DEFAULTARCH)/install-doc install-rdoc: $(DEFAULTARCH)/install-rdoc pre-install-local: $(subdirs:=/pre-install-local) post-install-local: $(subdirs:=/post-install-local) pre-install-ext: $(subdirs:=/pre-install-ext) post-install-ext: $(subdirs:=/post-install-ext) check: .PHONY prereq .pre-check test test-all .post-check test: .PHONY prereq .pre-test $(subdirs:=/test) .post-test; sync test-all: .PHONY prereq .pre-test-all $(subdirs:=/test-all) .post-test-all; sync .PHONY: .force