aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Third2021-06-16 21:28:10 +0100
committerAlan Third2021-06-26 10:34:59 +0100
commit5dd2d50f3d5e65b85c87da86e2e8a6d087fe5767 (patch)
treef8add442c328e37e5b8519415ed60d0c54523e65 /src
parent4d63a033a726a8da33bda8d18a503e88bfb794fb (diff)
downloademacs-5dd2d50f3d5e65b85c87da86e2e8a6d087fe5767.tar.gz
emacs-5dd2d50f3d5e65b85c87da86e2e8a6d087fe5767.zip
Fix NS native compilation builds
* Makefile.in (ns_applibexecdir): (ns_applibdir): (ns_appdir): New variables. (.PHONY): Include new rule. (epaths-force-ns-self-contained): Remove the app bundle directory from all paths. * configure.ac (NS_SELF_CONTAINED): Set the default site-lisp directory instead of hard-coding it in the ObjC code, and use the new epaths generating make rule. * src/callproc.c (init_callproc_1): (init_callproc): Remove all the NS specific code as the special cases are now handled by decode_env_path. * src/emacs.c (load_pdump): (decode_env_path): Use ns_relocate to find the correct directory after relocation. * src/lread.c (load_path_default): Remove all the NS specific code as the special cases are now handled by decode_env_path. * src/nsterm.h: Update function definitions. * src/nsterm.m (ns_etc_directory): (ns_exec_path): (ns_load_path): Remove functions that are no longer needed. (ns_relocate): New function to calculate paths within the NS app bundle. * nextstep/Makefile.in (ns_applibexecdir): New variable, and update anything relying on the libexec location.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in2
-rw-r--r--src/callproc.c36
-rw-r--r--src/emacs.c16
-rw-r--r--src/lread.c7
-rw-r--r--src/nsterm.h4
-rw-r--r--src/nsterm.m125
6 files changed, 43 insertions, 147 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index 79cddb35b55..22c7aeed5c6 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -55,7 +55,7 @@ lwlibdir = ../lwlib
55# Configuration files for .o files to depend on. 55# Configuration files for .o files to depend on.
56config_h = config.h $(srcdir)/conf_post.h 56config_h = config.h $(srcdir)/conf_post.h
57 57
58## ns-app if HAVE_NS, else empty. 58## ns-app if NS self contained app, else empty.
59OTHER_FILES = @OTHER_FILES@ 59OTHER_FILES = @OTHER_FILES@
60 60
61## Flags to pass for profiling builds 61## Flags to pass for profiling builds
diff --git a/src/callproc.c b/src/callproc.c
index e44e243680d..aabc39313b8 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1661,32 +1661,15 @@ make_environment_block (Lisp_Object current_dir)
1661void 1661void
1662init_callproc_1 (void) 1662init_callproc_1 (void)
1663{ 1663{
1664#ifdef HAVE_NS 1664 Vdata_directory = decode_env_path ("EMACSDATA", PATH_DATA, 0);
1665 const char *etc_dir = ns_etc_directory ();
1666 const char *path_exec = ns_exec_path ();
1667#endif
1668
1669 Vdata_directory = decode_env_path ("EMACSDATA",
1670#ifdef HAVE_NS
1671 etc_dir ? etc_dir :
1672#endif
1673 PATH_DATA, 0);
1674 Vdata_directory = Ffile_name_as_directory (Fcar (Vdata_directory)); 1665 Vdata_directory = Ffile_name_as_directory (Fcar (Vdata_directory));
1675 1666
1676 Vdoc_directory = decode_env_path ("EMACSDOC", 1667 Vdoc_directory = decode_env_path ("EMACSDOC", PATH_DOC, 0);
1677#ifdef HAVE_NS
1678 etc_dir ? etc_dir :
1679#endif
1680 PATH_DOC, 0);
1681 Vdoc_directory = Ffile_name_as_directory (Fcar (Vdoc_directory)); 1668 Vdoc_directory = Ffile_name_as_directory (Fcar (Vdoc_directory));
1682 1669
1683 /* Check the EMACSPATH environment variable, defaulting to the 1670 /* Check the EMACSPATH environment variable, defaulting to the
1684 PATH_EXEC path from epaths.h. */ 1671 PATH_EXEC path from epaths.h. */
1685 Vexec_path = decode_env_path ("EMACSPATH", 1672 Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC, 0);
1686#ifdef HAVE_NS
1687 path_exec ? path_exec :
1688#endif
1689 PATH_EXEC, 0);
1690 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path)); 1673 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
1691 /* FIXME? For ns, path_exec should go at the front? */ 1674 /* FIXME? For ns, path_exec should go at the front? */
1692 Vexec_path = nconc2 (decode_env_path ("PATH", "", 0), Vexec_path); 1675 Vexec_path = nconc2 (decode_env_path ("PATH", "", 0), Vexec_path);
@@ -1701,10 +1684,6 @@ init_callproc (void)
1701 1684
1702 char *sh; 1685 char *sh;
1703 Lisp_Object tempdir; 1686 Lisp_Object tempdir;
1704#ifdef HAVE_NS
1705 if (data_dir == 0)
1706 data_dir = ns_etc_directory () != 0;
1707#endif
1708 1687
1709 if (!NILP (Vinstallation_directory)) 1688 if (!NILP (Vinstallation_directory))
1710 { 1689 {
@@ -1716,15 +1695,8 @@ init_callproc (void)
1716 /* MSDOS uses wrapped binaries, so don't do this. */ 1695 /* MSDOS uses wrapped binaries, so don't do this. */
1717 if (NILP (Fmember (tem, Vexec_path))) 1696 if (NILP (Fmember (tem, Vexec_path)))
1718 { 1697 {
1719#ifdef HAVE_NS
1720 const char *path_exec = ns_exec_path ();
1721#endif
1722 /* Running uninstalled, so default to tem rather than PATH_EXEC. */ 1698 /* Running uninstalled, so default to tem rather than PATH_EXEC. */
1723 Vexec_path = decode_env_path ("EMACSPATH", 1699 Vexec_path = decode_env_path ("EMACSPATH", SSDATA (tem), 0);
1724#ifdef HAVE_NS
1725 path_exec ? path_exec :
1726#endif
1727 SSDATA (tem), 0);
1728 Vexec_path = nconc2 (decode_env_path ("PATH", "", 0), Vexec_path); 1700 Vexec_path = nconc2 (decode_env_path ("PATH", "", 0), Vexec_path);
1729 } 1701 }
1730 1702
diff --git a/src/emacs.c b/src/emacs.c
index 60a57a693ce..b7982ece646 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -835,7 +835,13 @@ load_pdump (int argc, char **argv)
835 NULL 835 NULL
836#endif 836#endif
837 ; 837 ;
838 const char *argv0_base = "emacs"; 838 const char *argv0_base =
839#ifdef NS_SELF_CONTAINED
840 "Emacs"
841#else
842 "emacs"
843#endif
844 ;
839 845
840 /* TODO: maybe more thoroughly scrub process environment in order to 846 /* TODO: maybe more thoroughly scrub process environment in order to
841 make this use case (loading a dump file in an unexeced emacs) 847 make this use case (loading a dump file in an unexeced emacs)
@@ -912,6 +918,8 @@ load_pdump (int argc, char **argv)
912 /* On MS-Windows, PATH_EXEC normally starts with a literal 918 /* On MS-Windows, PATH_EXEC normally starts with a literal
913 "%emacs_dir%", so it will never work without some tweaking. */ 919 "%emacs_dir%", so it will never work without some tweaking. */
914 path_exec = w32_relocate (path_exec); 920 path_exec = w32_relocate (path_exec);
921#elif defined (HAVE_NS)
922 path_exec = ns_relocate (path_exec);
915#endif 923#endif
916 924
917 /* Look for "emacs.pdmp" in PATH_EXEC. We hardcode "emacs" in 925 /* Look for "emacs.pdmp" in PATH_EXEC. We hardcode "emacs" in
@@ -929,6 +937,7 @@ load_pdump (int argc, char **argv)
929 } 937 }
930 sprintf (dump_file, "%s%c%s%s", 938 sprintf (dump_file, "%s%c%s%s",
931 path_exec, DIRECTORY_SEP, argv0_base, suffix); 939 path_exec, DIRECTORY_SEP, argv0_base, suffix);
940#if !defined (NS_SELF_CONTAINED)
932 /* Assume the Emacs binary lives in a sibling directory as set up by 941 /* Assume the Emacs binary lives in a sibling directory as set up by
933 the default installation configuration. */ 942 the default installation configuration. */
934 const char *go_up = "../../../../bin/"; 943 const char *go_up = "../../../../bin/";
@@ -943,6 +952,7 @@ load_pdump (int argc, char **argv)
943 sprintf (emacs_executable, "%s%c%s%s%s", 952 sprintf (emacs_executable, "%s%c%s%s%s",
944 path_exec, DIRECTORY_SEP, go_up, argv0_base, 953 path_exec, DIRECTORY_SEP, go_up, argv0_base,
945 strip_suffix ? strip_suffix : ""); 954 strip_suffix ? strip_suffix : "");
955#endif
946 result = pdumper_load (dump_file, emacs_executable); 956 result = pdumper_load (dump_file, emacs_executable);
947 957
948 if (result == PDUMPER_LOAD_FILE_NOT_FOUND) 958 if (result == PDUMPER_LOAD_FILE_NOT_FOUND)
@@ -2960,7 +2970,11 @@ decode_env_path (const char *evarname, const char *defalt, bool empty)
2960 path = 0; 2970 path = 0;
2961 if (!path) 2971 if (!path)
2962 { 2972 {
2973#ifdef NS_SELF_CONTAINED
2974 path = ns_relocate (defalt);
2975#else
2963 path = defalt; 2976 path = defalt;
2977#endif
2964#ifdef WINDOWSNT 2978#ifdef WINDOWSNT
2965 defaulted = 1; 2979 defaulted = 1;
2966#endif 2980#endif
diff --git a/src/lread.c b/src/lread.c
index 0b33fd0f254..4617ffd6265 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -4769,14 +4769,9 @@ load_path_default (void)
4769 return decode_env_path (0, PATH_DUMPLOADSEARCH, 0); 4769 return decode_env_path (0, PATH_DUMPLOADSEARCH, 0);
4770 4770
4771 Lisp_Object lpath = Qnil; 4771 Lisp_Object lpath = Qnil;
4772 const char *normal = PATH_LOADSEARCH;
4773 const char *loadpath = NULL; 4772 const char *loadpath = NULL;
4774 4773
4775#ifdef HAVE_NS 4774 lpath = decode_env_path (0, PATH_LOADSEARCH, 0);
4776 loadpath = ns_load_path ();
4777#endif
4778
4779 lpath = decode_env_path (0, loadpath ? loadpath : normal, 0);
4780 4775
4781 if (!NILP (Vinstallation_directory)) 4776 if (!NILP (Vinstallation_directory))
4782 { 4777 {
diff --git a/src/nsterm.h b/src/nsterm.h
index f64354b8a7b..b29e76cc63f 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -1190,9 +1190,7 @@ extern void ns_run_ascript (void);
1190#define NSAPP_DATA2_RUNFILEDIALOG 11 1190#define NSAPP_DATA2_RUNFILEDIALOG 11
1191extern void ns_run_file_dialog (void); 1191extern void ns_run_file_dialog (void);
1192 1192
1193extern const char *ns_etc_directory (void); 1193extern const char *ns_relocate (const char *epath);
1194extern const char *ns_exec_path (void);
1195extern const char *ns_load_path (void);
1196extern void syms_of_nsterm (void); 1194extern void syms_of_nsterm (void);
1197extern void syms_of_nsfns (void); 1195extern void syms_of_nsfns (void);
1198extern void syms_of_nsmenu (void); 1196extern void syms_of_nsmenu (void);
diff --git a/src/nsterm.m b/src/nsterm.m
index e81a4cbc0dc..8497138039c 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -499,118 +499,35 @@ append2 (Lisp_Object list, Lisp_Object item)
499 499
500 500
501const char * 501const char *
502ns_etc_directory (void) 502ns_relocate (const char *epath)
503/* If running as a self-contained app bundle, return as a string the 503/* If we're running in a self-contained app bundle some hard-coded
504 filename of the etc directory, if present; else nil. */ 504 paths are relative to the root of the bundle, so work out the full
505{ 505 path.
506 NSBundle *bundle = [NSBundle mainBundle];
507 NSString *resourceDir = [bundle resourcePath];
508 NSString *resourcePath;
509 NSFileManager *fileManager = [NSFileManager defaultManager];
510 BOOL isDir;
511 506
512 resourcePath = [resourceDir stringByAppendingPathComponent: @"etc"]; 507 FIXME: I think this should be able to handle cases where multiple
513 if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir]) 508 directories are separated by colons. */
514 {
515 if (isDir) return [resourcePath UTF8String];
516 }
517 return NULL;
518}
519
520
521const char *
522ns_exec_path (void)
523/* If running as a self-contained app bundle, return as a path string
524 the filenames of the libexec and bin directories, ie libexec:bin.
525 Otherwise, return nil.
526 Normally, Emacs does not add its own bin/ directory to the PATH.
527 However, a self-contained NS build has a different layout, with
528 bin/ and libexec/ subdirectories in the directory that contains
529 Emacs.app itself.
530 We put libexec first, because init_callproc_1 uses the first
531 element to initialize exec-directory. An alternative would be
532 for init_callproc to check for invocation-directory/libexec.
533*/
534{ 509{
510#ifdef NS_SELF_CONTAINED
535 NSBundle *bundle = [NSBundle mainBundle]; 511 NSBundle *bundle = [NSBundle mainBundle];
536 NSString *resourceDir = [bundle resourcePath]; 512 NSString *root = [bundle bundlePath];
537 NSString *binDir = [bundle bundlePath]; 513 NSString *original = [NSString stringWithUTF8String:epath];
538 NSString *resourcePath, *resourcePaths; 514 NSString *fixedPath = [NSString pathWithComponents:@[root, original]];
539 NSRange range;
540 NSString *pathSeparator = [NSString stringWithFormat: @"%c", SEPCHAR];
541 NSFileManager *fileManager = [NSFileManager defaultManager]; 515 NSFileManager *fileManager = [NSFileManager defaultManager];
542 NSArray *paths;
543 NSEnumerator *pathEnum;
544 BOOL isDir;
545 516
546 range = [resourceDir rangeOfString: @"Contents"]; 517 if (![original isAbsolutePath]
547 if (range.location != NSNotFound) 518 && [fileManager fileExistsAtPath:fixedPath isDirectory:NULL])
548 { 519 return [fixedPath UTF8String];
549 binDir = [binDir stringByAppendingPathComponent: @"Contents"];
550#ifdef NS_IMPL_COCOA
551 binDir = [binDir stringByAppendingPathComponent: @"MacOS"];
552#endif
553 }
554 520
555 paths = [binDir stringsByAppendingPaths: 521 /* If we reach here either the path is absolute and therefore we
556 [NSArray arrayWithObjects: @"libexec", @"bin", nil]]; 522 don't need to complete it, or we're unable to relocate the
557 pathEnum = [paths objectEnumerator]; 523 file/directory. If it's the latter it may be because the user is
558 resourcePaths = @""; 524 trying to use a bundled app as though it's a Unix style install
525 and we have no way to guess what was intended, so return the
526 original string unaltered. */
559 527
560 while ((resourcePath = [pathEnum nextObject])) 528#endif
561 {
562 if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir])
563 if (isDir)
564 {
565 if ([resourcePaths length] > 0)
566 resourcePaths
567 = [resourcePaths stringByAppendingString: pathSeparator];
568 resourcePaths
569 = [resourcePaths stringByAppendingString: resourcePath];
570 }
571 }
572 if ([resourcePaths length] > 0) return [resourcePaths UTF8String];
573
574 return NULL;
575}
576
577
578const char *
579ns_load_path (void)
580/* If running as a self-contained app bundle, return as a path string
581 the filenames of the site-lisp and lisp directories.
582 Ie, site-lisp:lisp. Otherwise, return nil. */
583{
584 NSBundle *bundle = [NSBundle mainBundle];
585 NSString *resourceDir = [bundle resourcePath];
586 NSString *resourcePath, *resourcePaths;
587 NSString *pathSeparator = [NSString stringWithFormat: @"%c", SEPCHAR];
588 NSFileManager *fileManager = [NSFileManager defaultManager];
589 BOOL isDir;
590 NSArray *paths = [resourceDir stringsByAppendingPaths:
591 [NSArray arrayWithObjects:
592 @"site-lisp", @"lisp", nil]];
593 NSEnumerator *pathEnum = [paths objectEnumerator];
594 resourcePaths = @"";
595
596 /* Hack to skip site-lisp. */
597 if (no_site_lisp) resourcePath = [pathEnum nextObject];
598
599 while ((resourcePath = [pathEnum nextObject]))
600 {
601 if ([fileManager fileExistsAtPath: resourcePath isDirectory: &isDir])
602 if (isDir)
603 {
604 if ([resourcePaths length] > 0)
605 resourcePaths
606 = [resourcePaths stringByAppendingString: pathSeparator];
607 resourcePaths
608 = [resourcePaths stringByAppendingString: resourcePath];
609 }
610 }
611 if ([resourcePaths length] > 0) return [resourcePaths UTF8String];
612 529
613 return NULL; 530 return epath;
614} 531}
615 532
616 533