From 88035b997930bd00c30be7b69de9d855a7f2322e Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 6 Feb 2018 03:19:42 +0000 Subject: [PATCH] mjit headers for universal binary * common.mk (MJIT_HEADER, MJIT_MIN_HEADER): added hook to separate intermediate headers per archs. * defs/gmake.mk: build mjit headers per -arch options, and then merge the headers with `#ifdef`s. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62245 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- Makefile.in | 2 ++ common.mk | 12 +++++++----- defs/gmake.mk | 22 +++++++++++++++++++++- defs/universal.mk | 5 +++++ template/GNUmakefile.in | 1 + win32/Makefile.sub | 2 ++ 6 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 defs/universal.mk diff --git a/Makefile.in b/Makefile.in index 49b0eaef21..ea9b480fa8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -71,6 +71,8 @@ cppflags = @cppflags@ XCFLAGS = @XCFLAGS@ CPPFLAGS = @CPPFLAGS@ $(INCFLAGS) -DMJIT_HEADER_BUILD_DIR=\""$(EXTOUT)/include/$(arch)"\" -DLIBRUBYARG_SHARED=\""$(LIBRUBYARG_SHARED)"\" -DMJIT_HEADER_INSTALL_DIR=\""include/$(RUBY_BASE_NAME)-$(ruby_version)/$(arch)"\" MJIT_HEADER_FLAGS = @MJIT_HEADER_FLAGS@ +MJIT_HEADER_SUFFIX = +MJIT_HEADER_ARCH = LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@ EXTLDFLAGS = @EXTLDFLAGS@ XLDFLAGS = @XLDFLAGS@ $(EXTLDFLAGS) diff --git a/common.mk b/common.mk index 4ed9cde133..0d2e3d9c48 100644 --- a/common.mk +++ b/common.mk @@ -59,6 +59,7 @@ ENC_TRANS_D = $(TIMESTAMPDIR)/.enc-trans.time RDOCOUT = $(EXTOUT)/rdoc HTMLOUT = $(EXTOUT)/html CAPIOUT = doc/capi +MJIT_HEADER = rb_mjit_header.h MJIT_MIN_HEADER = $(EXTOUT)/include/$(arch)/rb_mjit_min_header-$(RUBY_PROGRAM_VERSION).h INITOBJS = dmyext.$(OBJEXT) dmyenc.$(OBJEXT) @@ -195,14 +196,15 @@ main: $(SHOWFLAGS) exts $(ENCSTATIC:static=lib)encs $(MJIT_MIN_HEADER) .PHONY: mjit-headers mjit-headers: $(MJIT_MIN_HEADER) -rb_mjit_header.h: PHONY probes.h +$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).h: PHONY probes.h $(ECHO) building $@ - $(Q) $(CPP) $(MJIT_HEADER_FLAGS) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -DMJIT_HEADER $(srcdir)/vm.c $(CPPOUTFLAG)vm.new - $(Q) $(IFCHANGE) $@ vm.new + $(Q) $(CPP) $(MJIT_HEADER_FLAGS) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -DMJIT_HEADER $(srcdir)/vm.c $(CPPOUTFLAG)$(@F).new + $(Q) $(IFCHANGE) $@ $(@F).new -$(MJIT_MIN_HEADER): rb_mjit_header.h $(srcdir)/tool/transform_mjit_header.rb $(PREP) +$(MJIT_MIN_HEADER:.h=)$(MJIT_HEADER_SUFFIX).h: $(srcdir)/tool/transform_mjit_header.rb $(PREP) +$(MJIT_MIN_HEADER:.h=)$(MJIT_HEADER_SUFFIX).h: $(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).h $(ECHO) building $@ - $(MINIRUBY) $(srcdir)/tool/transform_mjit_header.rb "$(CC) $(ARCH_FLAG)" rb_mjit_header.h $@ + $(MINIRUBY) $(srcdir)/tool/transform_mjit_header.rb "$(CC) $(ARCH_FLAG)" $(MJIT_HEADER:.h=)$(MJIT_HEADER_ARCH).h $@ .PHONY: showflags exts enc trans: $(SHOWFLAGS) diff --git a/defs/gmake.mk b/defs/gmake.mk index 3170b2755a..4c9eb473af 100644 --- a/defs/gmake.mk +++ b/defs/gmake.mk @@ -48,7 +48,7 @@ define archcmd %.i: %.$(1).i endef -$(foreach arch,$(filter -arch=%,$(subst -arch ,-arch=,$(ARCH_FLAG))),\ +$(foreach arch,$(arch_flags),\ $(eval $(call archcmd,$(patsubst -arch=%,%,$(value arch)),$(patsubst -arch=%,-arch %,$(value arch))))) endif @@ -144,3 +144,23 @@ commit: $(if $(filter commit,$(MAKECMDGOALS)),$(filter-out commit,$(MAKECMDGOALS ifeq ($(words $(filter update-gems extract-gems,$(MAKECMDGOALS))),2) extract-gems: update-gems endif + +ifeq ($(filter 0 1,$(words $(arch_flags))),) +$(foreach x,$(patsubst -arch=%,%,$(arch_flags)), \ + $(eval $$(MJIT_HEADER:.h=)-$(value x).h \ + $$(MJIT_MIN_HEADER:.h=)-$(value x).h \ + : ARCH_FLAG := -arch $(value x))) + +mjit_min_headers := $(patsubst -arch=%,$(MJIT_MIN_HEADER:.h=-%.h),$(arch_flags)) +$(MJIT_MIN_HEADER): $(mjit_min_headers) + @ set -e; set $(patsubst -arch=%,%,$(arch_flags)); \ + cd $(@D); h=$(@F:.h=); set -x; \ + cp $$h-$$1.h $$h.h.new; shift; \ + for arch; do \ + mv $$h.h.new $$h.h.tmp; \ + diff -B -D__$${arch}__ $$h.h.tmp $$h-$$arch.h > $$h.h.new || :; \ + done + $(RM) $@.tmp + $(IFCHANGE) $@ $@.new + +endif diff --git a/defs/universal.mk b/defs/universal.mk new file mode 100644 index 0000000000..c34a31b356 --- /dev/null +++ b/defs/universal.mk @@ -0,0 +1,5 @@ +arch_flags := $(filter -arch=%,$(subst -arch ,-arch=,$(ARCH_FLAG))) +ifeq ($(filter 0 1,$(words $(arch_flags))),) +override MJIT_HEADER_SUFFIX = -% +override MJIT_HEADER_ARCH = -$(word 2,$(ARCH_FLAG)) +endif diff --git a/template/GNUmakefile.in b/template/GNUmakefile.in index c904d3474e..f603210bc2 100644 --- a/template/GNUmakefile.in +++ b/template/GNUmakefile.in @@ -1,4 +1,5 @@ include Makefile +include $(srcdir)/defs/universal.mk -include uncommon.mk include $(srcdir)/defs/gmake.mk diff --git a/win32/Makefile.sub b/win32/Makefile.sub index 01802384fe..cb5fb9c7fe 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -287,6 +287,8 @@ LDSHARED_2 = @if exist $(@).manifest @$(RM) $(@:/=\).manifest !endif CPPFLAGS = $(DEFS) $(ARCHDEFS) $(CPPFLAGS) -DMJIT_HEADER_BUILD_DIR=\""$(EXTOUT)/include/$(arch)"\" -DLIBRUBYARG_SHARED=\""$(LIBRUBYARG_SHARED)"\" -DMJIT_HEADER_INSTALL_DIR=\""include/$(RUBY_BASE_NAME)-$(ruby_version)/$(arch)"\" MJIT_HEADER_FLAGS = -P +MJIT_HEADER_SUFFIX = +MJIT_HEADER_ARCH = DLDFLAGS = $(LDFLAGS) -dll SOLIBS =