annotate Mac/Tools/pythonw.c @ 58397:0c8cbdbafaad legacy-trunk

- Issue #7658: Ensure that the new pythonw executable works on OSX 10.4 - Issue #7714: Use ``gcc -dumpversion`` to detect the version of GCC on MacOSX. - Make configure look for util.h as well as libutil.h. The former is the header file that on OSX contains the defition of openpty. (Needed to compile for OSX 10.4 on OSX 10.6) - Use the correct definition of CC to compile the pythonw executable
author Ronald Oussoren <ronaldoussoren@mac.com>
date Sun, 17 Jan 2010 16:25:57 +0000
parents aaeb65bab3c0
children 2990bd3ae883
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
1 /*
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
2 * This wrapper program executes a python executable hidden inside an
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
3 * application bundle inside the Python framework. This is needed to run
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
4 * GUI code: some GUI API's don't work unless the program is inside an
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
5 * application bundle.
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
6 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
7 * This program uses posix_spawn rather than plain execv because we need
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
8 * slightly more control over how the "real" interpreter is executed.
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
9 *
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
10 * On OSX 10.4 (and earlier) this falls back to using exec because the
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
11 * posix_spawnv functions aren't available there.
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
12 */
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
13 #pragma weak_import posix_spawnattr_init
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
14 #pragma weak_import posix_spawnattr_setbinpref_np
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
15 #pragma weak_import posix_spawnattr_setflags
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
16 #pragma weak_import posix_spawn
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
17
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
18 #include <Python.h>
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
19 #include <unistd.h>
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
20 #ifdef HAVE_SPAWN_H
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
21 #include <spawn.h>
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
22 #endif
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
23 #include <stdio.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
24 #include <string.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
25 #include <errno.h>
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
26 #include <err.h>
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
27 #include <dlfcn.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
28 #include <stdlib.h>
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
29
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
30
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
31 extern char** environ;
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
32
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
33 /*
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
34 * Locate the python framework by looking for the
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
35 * library that contains Py_Initialize.
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
36 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
37 * In a regular framework the structure is:
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
38 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
39 * Python.framework/Versions/2.7
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
40 * /Python
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
41 * /Resources/Python.app/Contents/MacOS/Python
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
42 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
43 * In a virtualenv style structure the expected
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
44 * structure is:
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
45 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
46 * ROOT
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
47 * /bin/pythonw
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
48 * /.Python <- the dylib
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
49 * /.Resources/Python.app/Contents/MacOS/Python
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
50 *
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
51 * NOTE: virtualenv's are not an officially supported
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
52 * feature, support for that structure is provided as
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
53 * a convenience.
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
54 */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
55 static char* get_python_path(void)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
56 {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
57 size_t len;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
58 Dl_info info;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
59 char* end;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
60 char* g_path;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
61
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
62 if (dladdr(Py_Initialize, &info) == 0) {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
63 return NULL;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
64 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
65
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
66 len = strlen(info.dli_fname);
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
67
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
68 g_path = malloc(len+60);
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
69 if (g_path == NULL) {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
70 return NULL;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
71 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
72
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
73 strcpy(g_path, info.dli_fname);
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
74 end = g_path + len - 1;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
75 while (end != g_path && *end != '/') {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
76 end --;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
77 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
78 end++;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
79 if (end[1] == '.') {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
80 end++;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
81 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
82 strcpy(end, "Resources/Python.app/Contents/MacOS/Python");
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
83
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
84 return g_path;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
85 }
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
86
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
87 #ifdef HAVE_SPAWN_H
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
88 static void
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
89 setup_spawnattr(posix_spawnattr_t* spawnattr)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
90 {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
91 size_t ocount;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
92 size_t count;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
93 cpu_type_t cpu_types[1];
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
94 short flags = 0;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
95 #ifdef __LP64__
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
96 int ch;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
97 #endif
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
98
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
99 if ((errno = posix_spawnattr_init(spawnattr)) != 0) {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
100 err(2, "posix_spawnattr_int");
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
101 /* NOTREACHTED */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
102 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
103
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
104 count = 1;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
105
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
106 /* Run the real python executable using the same architure as this
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
107 * executable, this allows users to controle the architecture using
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
108 * "arch -ppc python"
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
109 */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
110
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
111 #if defined(__ppc64__)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
112 cpu_types[0] = CPU_TYPE_POWERPC64;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
113
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
114 #elif defined(__x86_64__)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
115 cpu_types[0] = CPU_TYPE_X86_64;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
116
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
117 #elif defined(__ppc__)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
118 cpu_types[0] = CPU_TYPE_POWERPC;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
119 #elif defined(__i386__)
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
120 cpu_types[0] = CPU_TYPE_X86;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
121 #else
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
122 # error "Unknown CPU"
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
123 #endif
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
124
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
125 if (posix_spawnattr_setbinpref_np(spawnattr, count,
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
126 cpu_types, &ocount) == -1) {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
127 err(1, "posix_spawnattr_setbinpref");
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
128 /* NOTREACHTED */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
129 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
130 if (count != ocount) {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
131 fprintf(stderr, "posix_spawnattr_setbinpref failed to copy\n");
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
132 exit(1);
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
133 /* NOTREACHTED */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
134 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
135
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
136
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
137 /*
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
138 * Set flag that causes posix_spawn to behave like execv
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
139 */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
140 flags |= POSIX_SPAWN_SETEXEC;
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
141 if ((errno = posix_spawnattr_setflags(spawnattr, flags)) != 0) {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
142 err(1, "posix_spawnattr_setflags");
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
143 /* NOTREACHTED */
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
144 }
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
145 }
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
146 #endif
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
147
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
148 int
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
149 main(int argc, char **argv) {
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
150 char* exec_path = get_python_path();
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
151
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
152 #ifdef HAVE_SPAWN_H
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
153
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
154 /* We're weak-linking to posix-spawnv to ensure that
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
155 * an executable build on 10.5 can work on 10.4.
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
156 */
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
157 if (posix_spawn != NULL) {
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
158 posix_spawnattr_t spawnattr = NULL;
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
159
57913
aaeb65bab3c0 Issue #6834: replace the implementation for the 'python' and 'pythonw' executables on OSX.
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 38643
diff changeset
160
58397
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
161 setup_spawnattr(&spawnattr);
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
162 posix_spawn(NULL, exec_path, NULL,
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
163 &spawnattr, argv, environ);
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
164 err(1, "posix_spawn: %s", argv[0]);
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
165 }
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
166 #endif
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
167 execve(exec_path, argv, environ);
0c8cbdbafaad - Issue #7658: Ensure that the new pythonw executable works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 57913
diff changeset
168 err(1, "execve: %s", argv[0]);
38176
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
169 /* NOTREACHED */
cdf8f5334426 Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
diff changeset
170 }