1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
# Setup for gdmodule 0.50 and later
from distutils.core import setup, Extension
import os, glob, sys, string
# version of this gdmodule package
this_version = "0.56"
# directory existence tester
def dirtest(lst):
rlst = []
for d in lst:
try:
if os.listdir(d):
rlst.append(d)
except:
pass
return rlst
def filetest(path, names):
rlst = []
for d in path:
for i in range(len(names)):
found = glob.glob(os.path.join(d, "lib%s.*" % names[i]))
if found:
rlst.append(names[i])
names[i] = None
names = filter(None, names)
return rlst
def remove(itm, lst):
r = range(len(lst))
r.reverse()
for i in r:
if lst[i] == itm:
del lst[i]
# Add multiarch paths
mult_lib = []
mult_inc = []
try:
cmd = os.popen('dpkg-architecture -qDEB_HOST_MULTIARCH')
multiarch_path_component = cmd.readline().strip()
mult_lib = ['/usr/lib/'+multiarch_path_component]
mult_inc = ['/usr/include/'+multiarch_path_component]
cmd.close()
except:
print "Can not import multiarch name"
# library_dirs option is rather non-portable, but since I am targetting
# Unixoid OS's I will just look for the usual suspects.
libdirs = dirtest([
"/usr/local/lib", "/sw/lib", "/usr/lib",
"/usr/lib/X11", "/usr/X11R6/lib",
"/opt/gnome/lib",
]+mult_lib)
# include_dirs are also non-portable; same trick here.
incdirs = dirtest([
"/usr/local/include", "/sw/include", "/usr/include",
"/usr/include/X11", "/usr/X11R6/include",
"/opt/gnome/include",
]+mult_inc)
# Try to identify our libraries
want_libs = [
"gd",
"jpeg", "png", "gif", "z",
"X11", "Xpm",
"ttf", "freetype",
]
libs = filetest(libdirs, want_libs)
missing = []
for l in want_libs:
if l and l not in libs:
missing.append(l)
if missing:
print "WARNING: Missing", string.join(missing, ", "), "Libraries"
# hand-clean the libs
if "gd" not in libs:
print "Can't find GD library."
sys.exit(0)
if "ttf" in libs and "freetype" in libs:
remove("ttf", libs)
if "Xpm" in libs and "X11" not in libs:
remove("Xpm", libs)
if "png" in libs and "z" not in libs:
remove("png", libs)
if "z" in libs and "png" not in libs:
remove("png", libs)
# build the macro list
macros = []
for l in libs:
macros.append(( "HAVE_LIB%s" % l.upper(), None ))
# OK, now do it!
setup(name="gdmodule", version=this_version,
description="GD Package",
long_description="GD Package",
author="Chris Gonnerman",
author_email="chris.gonnerman@newcenturycomputers.net",
url="http://newcenturycomputers.net/projects/gdmodule.html",
py_modules=["gd"],
ext_modules=[
Extension("_gd", ["_gdmodule.c"],
include_dirs=incdirs, library_dirs=libdirs,
libraries=libs, define_macros=macros)],
)
# end of file... I guess we're done.
|