From 0f476b1de3c3e61467cff9536618d120873c47ab Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Fri, 10 May 2019 16:26:18 +0200 Subject: [PATCH] Move native C code into shared library --- lib/Makefile.in | 4 +++- src/Makefile.in | 50 ++++++++++++++++++++++++++++--------------------- src/emacs.c | 2 +- src/main.c | 26 +++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 src/main.c diff --git a/lib/Makefile.in b/lib/Makefile.in index 06d8e56421b..ed3123885d2 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -26,6 +26,8 @@ abs_top_srcdir = @abs_top_srcdir@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +CFLAGS = -fPIC @CFLAGS@ + all: .PHONY: all @@ -50,7 +52,7 @@ am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = -ALL_CFLAGS= \ +ALL_CFLAGS= -fPIC \ $(C_SWITCH_SYSTEM) $(C_SWITCH_MACHINE) $(DEPFLAGS) \ $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS) $(PROFILING_CFLAGS) $(CFLAGS) \ -I. -I../src -I$(srcdir) -I$(srcdir)/../src \ diff --git a/src/Makefile.in b/src/Makefile.in index ab63b926272..423c5a3f929 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -33,7 +33,7 @@ top_srcdir = @top_srcdir@ abs_top_srcdir=@abs_top_srcdir@ VPATH = $(srcdir) CC = @CC@ -CFLAGS = @CFLAGS@ +CFLAGS = @CFLAGS@ -fPIC CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ EXEEXT = @EXEEXT@ @@ -463,7 +463,7 @@ FIRSTFILE_OBJ=@FIRSTFILE_OBJ@ ALLOBJS = $(FIRSTFILE_OBJ) $(VMLIMIT_OBJ) $(obj) $(otherobj) # Must be first, before dep inclusion! -all: emacs$(EXEEXT) $(pdmp) $(OTHER_FILES) +all: $(pdmp) $(OTHER_FILES) .PHONY: all dmpstruct_headers=$(srcdir)/lisp.h $(srcdir)/buffer.h \ @@ -642,25 +642,33 @@ else MAKE_PDUMPER_FINGERPRINT = endif -## We have to create $(etc) here because init_cmdargs tests its -## existence when setting Vinstallation_directory (FIXME?). -## This goes on to affect various things, and the emacs binary fails -## to start if Vinstallation_directory has the wrong value. -temacs$(EXEEXT): $(LIBXMENU) $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(EMACSRES) \ - $(charsets) $(charscript) $(MAKE_PDUMPER_FINGERPRINT) - $(AM_V_CCLD)$(CC) -o $@.tmp \ - $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(LDFLAGS) \ - $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(W32_RES_LINK) $(LIBES) -ifeq ($(HAVE_PDUMPER),yes) - $(AM_V_at)$(MAKE_PDUMPER_FINGERPRINT) $@.tmp -endif - $(AM_V_at)mv $@.tmp $@ - $(MKDIR_P) $(etc) -ifeq ($(DUMPING),unexec) - ifneq ($(PAXCTL_notdumped),) - $(PAXCTL_notdumped) $@ - endif -endif +## FIXME: dumper support totally missing here +libemacs.so: $(LIBXMENU) $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(EMACSRES) \ + $(charsets) $(charscript) $(MAKE_PDUMPER_FINGERPRINT) main.o + $(CC) --shared -o $@ $(ALLOBJS) -Wl,-Bstatic $(LIBEGNU_ARCHIVE) -Wl,-Bdynamic $(LIBES) + +temacs$(EXEEXT): libemacs.so main.o + $(CC) -L. main.o -o $@ $(TEMACS_LDFLAGS) $(LDFLAGS) \ + $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(W32_RES_LINK) $(LIBES) -lemacs -Wl,-rpath -Wl,$(shell pwd) + +# ## We have to create $(etc) here because init_cmdargs tests its +# ## existence when setting Vinstallation_directory (FIXME?). +# ## This goes on to affect various things, and the emacs binary fails +# ## to start if Vinstallation_directory has the wrong value. +# temacs$(EXEEXT): $(LIBXMENU) $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(EMACSRES) \ +# $(charsets) $(charscript) $(MAKE_PDUMPER_FINGERPRINT) +# $(AM_V_CCLD)$(CC) -o $@.tmp \ +# $(ALL_CFLAGS) $(TEMACS_LDFLAGS) $(LDFLAGS) \ +# $(ALLOBJS) $(LIBEGNU_ARCHIVE) $(W32_RES_LINK) $(LIBES) +# ifeq ($(HAVE_PDUMPER),yes) +# $(AM_V_at)$(MAKE_PDUMPER_FINGERPRINT) $@.tmp +# endif +# $(AM_V_at)mv $@.tmp $@ +# $(MKDIR_P) $(etc) +# ifeq ($(DUMPING),unexec) +# ifneq ($(PAXCTL_notdumped),) +# $(PAXCTL_notdumped) $@ +# endif ## The following oldxmenu-related rules are only (possibly) used if ## HAVE_X11 && !USE_GTK, but there is no harm in always defining them. diff --git a/src/emacs.c b/src/emacs.c index c5a760d29f6..81703b4660a 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -924,7 +924,7 @@ load_pdump (int argc, char **argv) #endif /* HAVE_PDUMPER */ int -main (int argc, char **argv) +main1 (int argc, char **argv) { /* Variable near the bottom of the stack, and aligned appropriately for pointers. */ diff --git a/src/main.c b/src/main.c new file mode 100644 index 00000000000..41e35534280 --- /dev/null +++ b/src/main.c @@ -0,0 +1,26 @@ +/* Trampoline for GNU Emacs. + Copyright (C) 2019 Free Software + Foundation, Inc. + +This file is part of GNU Emacs. + +GNU Emacs is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or (at +your option) any later version. + +GNU Emacs is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Emacs. If not, see . */ + +extern int main1 (int argc, char **argv); + +int +main (int argc, char **argv) +{ + return main1(argc, argv); +} -- 2.39.5