Skip to content

Commit

Permalink
mjit headers for universal binary
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Feb 6, 2018
1 parent 7112c6a commit 88035b9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion defs/gmake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions defs/universal.mk
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions template/GNUmakefile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include Makefile
include $(srcdir)/defs/universal.mk
-include uncommon.mk
include $(srcdir)/defs/gmake.mk

Expand Down
2 changes: 2 additions & 0 deletions win32/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 88035b9

Please sign in to comment.