ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CMSDIST/python.spec
Revision: 1.92
Committed: Mon Aug 20 13:31:52 2012 UTC (12 years, 8 months ago) by dsr
Branch: MAIN
Changes since 1.91: +50 -14 lines
Log Message:
restore HEAD

File Contents

# Content
1 ### RPM external python 2.7.3
2 ## INITENV +PATH PATH %i/bin
3 ## INITENV +PATH LD_LIBRARY_PATH %i/lib
4 ## INITENV SETV PYTHON_LIB_SITE_PACKAGES lib/python%{python_major_version}/site-packages
5 ## INITENV SETV PYTHONHASHSEED random
6 # OS X patches and build fudging stolen from fink
7 %{expand:%%define python_major_version %(echo %realversion | cut -d. -f1,2)}
8 %define online %(case %cmsplatf in (*onl_*_*) echo true;; (*) echo false;; esac)
9
10 Requires: expat bz2lib db4 gdbm
11
12 %if "%online" != "true"
13 Requires: zlib openssl sqlite
14 %endif
15
16 # FIXME: readline, crypt
17 # FIXME: gmp, panel, tk/tcl, x11
18
19 Source0: http://www.python.org/ftp/%n/%realversion/Python-%realversion.tgz
20 Patch1: python-fix-macosx-relocation
21 Patch2: python-2.7.3-fix-pyport
22
23 %prep
24 %setup -n Python-%realversion
25 find . -type f | while read f; do
26 if head -n1 $f | grep -q /usr/local; then
27 perl -p -i -e "s|#!.*/usr/local/bin/python|#!/usr/bin/env python|" $f
28 else :; fi
29 done
30 %patch1 -p0
31
32 %ifos darwin
33 %patch2 -p1
34 %endif
35
36 %build
37 # Python is awkward about passing other include or library directories
38 # to it. Basically there is no way to pass anything from configure to
39 # make, or down to python itself. To get python detect the extensions
40 # we want to enable, we simply have to link the contents into python's
41 # own include/lib directories. Ugh.
42 #
43 # NB: It would sort-of make sense to link more stuff from /sw on OS X,
44 # but we simply cannot link the whole world. If you need something,
45 # see above for the commented-out list of packages that could be
46 # linked specifically, or could be built by ourselves, depending on
47 # whether we like to pick up system libraries or want total control.
48 #mkdir -p %i/include %i/lib
49 mkdir -p %i/include %i/lib %i/bin
50
51 %if "%online" != "true"
52 %define extradirs $ZLIB_ROOT $OPENSSL_ROOT $SQLITE_ROOT
53 %else
54 %define extradirs %{nil}
55 %endif
56
57 dirs="$EXPAT_ROOT $BZ2LIB_ROOT $NCURSES_ROOT $DB4_ROOT $GDBM_ROOT %{extradirs}"
58
59 # We need to export it because setup.py now uses it to determine the actual
60 # location of DB4, this was needed to avoid having it picked up from the system.
61 export DB4_ROOT
62
63 # Python's configure parses LDFLAGS and CPPFLAGS to look for aditional library and include directories
64 echo $dirs
65 LDFLAGS=""
66 CPPFLAGS=""
67 for d in $dirs; do
68 LDFLAGS="$LDFLAGS -L $d/lib"
69 CPPFLAGS="$CPPFLAGS -I $d/include"
70 done
71 export LDFLAGS
72 export CPPFLAGS
73
74 additionalConfigureOptions=""
75 case %cmsplatf in
76 osx105* )
77 additionalConfigureOptions="--disable-readline"
78 ;;
79 esac
80
81 # Bugfix for dbm package. Use ndbm.h header and gdbm compatibility layer.
82 sed -ibak "s/ndbm_libs = \[\]/ndbm_libs = ['gdbm', 'gdbm_compat']/" setup.py
83
84 ./configure --prefix=%i $additionalConfigureOptions --enable-shared
85
86 # Modify pyconfig.h to match macros from GLIBC features.h on Linux machines.
87 # _POSIX_C_SOURCE and _XOPEN_SOURCE macros are not identical anymore
88 # starting GLIBC 2.10.1. Python.h is not included before standard headers
89 # in CMSSW and pyconfig.h is not smart enough to detect already defined
90 # macros on Linux. The following problem does not exists on BSD machines as
91 # cdefs.h does not define these macros.
92 case %cmsplatf in
93 slc6*)
94 rm -f cms_configtest.cpp
95 cat <<CMS_EOF > cms_configtest.cpp
96 #include <features.h>
97
98 int main() {
99 return 0;
100 }
101 CMS_EOF
102
103 FEATURES=$(g++ -dM -E -DGNU_GCC=1 -D_GNU_SOURCE=1 -D_DARWIN_SOURCE=1 cms_configtest.cpp \
104 | grep -E '_POSIX_C_SOURCE |_XOPEN_SOURCE ')
105 rm -f cms_configtest.cpp a.out
106
107 POSIX_C_SOURCE=$(echo "${FEATURES}" | grep _POSIX_C_SOURCE | cut -d ' ' -f 3)
108 XOPEN_SOURCE=$(echo "${FEATURES}" | grep _XOPEN_SOURCE | cut -d ' ' -f 3)
109
110 sed -ibak "s/\(#define _POSIX_C_SOURCE \)\(.*\)/\1${POSIX_C_SOURCE}/g" pyconfig.h
111 sed -ibak "s/\(#define _XOPEN_SOURCE \)\(.*\)/\1${XOPEN_SOURCE}/g" pyconfig.h
112 ;;
113 esac
114
115 # The following is a kludge around the fact that the /usr/lib/libreadline.so
116 # symlink (for 32-bit lib) is missing on the 64bit machines
117 case %cmsplatf in
118 slc4_ia32* )
119 mkdir -p %{i}/lib
120 ln -s /usr/lib/libreadline.so.4.3 %{i}/lib/libreadline.so
121 ;;
122 esac
123
124 make %makeprocesses
125
126 %install
127 # We need to export it because setup.py now uses it to determine the actual
128 # location of DB4, this was needed to avoid having it picked up from the system.
129 export DB4_ROOT
130 make install
131 %define pythonv %(echo %realversion | cut -d. -f 1,2)
132
133 case %cmsplatf in
134 osx*)
135 make install prefix=%i
136 (cd Misc; /bin/rm -rf RPM)
137 mkdir -p %i/share/doc/%n
138 cp -R Demo Doc %i/share/doc/%n
139 cp -R Misc Tools %i/lib/python%{pythonv}
140 gcc -dynamiclib -all_load -single_module \
141 -framework System -framework CoreServices -framework Foundation \
142 %i/lib/python%{pythonv}/config/libpython%{pythonv}.a \
143 -undefined dynamic_lookup \
144 -o %i/lib/python%{pythonv}/config/libpython%{pythonv}.dylib \
145 -install_name %i/lib/python%{pythonv}/config/libpython%{pythonv}.dylib \
146 -current_version %{pythonv} -compatibility_version %{pythonv} -ldl
147 (cd %i/lib/python%{pythonv}/config
148 perl -p -i -e 's|-fno-common||g' Makefile)
149
150 find %i/lib/python%{pythonv}/config -name 'libpython*' -exec mv -f {} %i/lib \;
151 ;;
152 esac
153
154 perl -p -i -e "s|^#!.*python|#!/usr/bin/env python|" %{i}/bin/idle \
155 %{i}/bin/pydoc \
156 %{i}/bin/python-config \
157 %{i}/bin/2to3 \
158 %{i}/bin/python2.7-config \
159 %{i}/bin/smtpd.py
160
161 find %{i}/lib -maxdepth 1 -mindepth 1 ! -name '*python*' -exec rm {} \;
162 find %{i}/include -maxdepth 1 -mindepth 1 ! -name '*python*' -exec rm {} \;
163
164 # remove executable permission anything which is *.py script,
165 # is executable, but does not start with she-bang so not valid
166 # executable; this avoids problems with rpm 4.8+ find-requires
167 find %i -name '*.py' -perm +0111 | while read f; do
168 if head -n1 $f | grep -q '"'; then chmod -x $f; else :; fi
169 done
170
171 # remove tkinter that brings dependency on libtk:
172 find %{i}/lib -type f -name "_tkinter.so" -exec rm {} \;
173
174 # Remove documentation, examples and test files.
175 %define drop_files { %i/share %{i}/lib/python%{pythonv}/test \
176 %{i}/lib/python%{pythonv}/distutils/tests \
177 %{i}/lib/python%{pythonv}/json/tests \
178 %{i}/lib/python%{pythonv}/ctypes/test \
179 %{i}/lib/python%{pythonv}/sqlite3/test \
180 %{i}/lib/python%{pythonv}/bsddb/test \
181 %{i}/lib/python%{pythonv}/email/test \
182 %{i}/lib/python%{pythonv}/lib2to3/tests }
183
184 # Remove .pyo files
185 find %i -name '*.pyo' -exec rm {} \;
186
187 # Generate dependencies-setup.{sh,csh} so init.{sh,csh} picks full environment.
188 mkdir -p %i/etc/profile.d
189 : > %i/etc/profile.d/dependencies-setup.sh
190 : > %i/etc/profile.d/dependencies-setup.csh
191 for tool in $(echo %{requiredtools} | sed -e's|\s+| |;s|^\s+||'); do
192 root=$(echo $tool | tr a-z- A-Z_)_ROOT; eval r=\$$root
193 if [ X"$r" != X ] && [ -r "$r/etc/profile.d/init.sh" ]; then
194 echo "test X\$$root != X || . $r/etc/profile.d/init.sh" >> %i/etc/profile.d/dependencies-setup.sh
195 echo "test X\$$root != X || source $r/etc/profile.d/init.csh" >> %i/etc/profile.d/dependencies-setup.csh
196 fi
197 done
198
199 %post
200 %{relocateConfig}lib/python2.7/config/Makefile
201 %{relocateConfig}etc/profile.d/dependencies-setup.*sh