/ setup.py
setup.py
1 #!/usr/bin/env python 2 # This is a component of AXIS, a front-end for emc 3 # Copyright 2004, 2005, 2006 Jeff Epler <jepler@unpythonic.net> 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 2 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 import sys, os 20 sys.path.insert(0, "lib") 21 sys.path.insert(0, "setup") 22 23 if sys.hexversion < 0x2040000: 24 raise SystemExit, "Python 2.4 is required for AXIS" 25 26 from glob import glob 27 from distutils import sysconfig 28 from distutils.core import setup, Extension 29 from togl_setup import get_togl_flags 30 from emc_setup import * 31 import distutils.command.install 32 from monkeypatch import * 33 34 name="axis" 35 version="1.4a0" 36 DOCDIR="share/doc/%s-%s" % (name, version) 37 SHAREDIR="share/%s" % (name) 38 LOCALEDIR="share/locale" 39 40 emcroot = os.getenv("EMCROOT", None) or find_emc_root() 41 if emcroot is None: 42 print """\ 43 setup.py failed to locate the root directory of your emc installation. 44 Determine the location of your emc installation and re-run setup.py with a 45 commandline like this: 46 $ env EMCROOT=/usr/local/emc python setup.py install 47 48 See the README file for more information.""" 49 raise SystemExit, 1 50 emcroot = os.path.abspath(emcroot) 51 52 emc2_marker = os.path.join(emcroot, "include", "config.h") 53 emc2_marker2 = os.path.join(emcroot, "include", "emc2", "config.h") 54 is_emc2 = os.path.exists(emc2_marker) or os.path.exists(emc2_marker2) 55 bdi4_marker = os.path.join(emcroot, "src/include", "config.h") 56 is_bdi4 = os.path.exists(bdi4_marker) 57 58 minigl = Extension("minigl", 59 ["extensions/minigl.c"], 60 libraries = ["GL", "GLU"], 61 library_dirs = ["/usr/X11R6/lib"]) 62 hal = None 63 64 if is_emc2: 65 run_installed = (os.environ.has_key("EMC_RUN_INSTALLED") \ 66 or os.path.exists(emc2_marker2)) 67 if run_installed: 68 print "(run installed)" 69 include_dirs = [os.path.join(emcroot, "include", "emc2")] 70 library_dirs = [os.path.join(emcroot, "lib")] 71 else: 72 distutils.command.install.INSTALL_SCHEMES['unix_prefix']['scripts'] = \ 73 "%s/bin" % (emcroot) 74 distutils.command.install.INSTALL_SCHEMES['unix_prefix']['platlib'] = \ 75 "%s/lib/python" % (emcroot) 76 distutils.command.install.INSTALL_SCHEMES['unix_prefix']['data'] = \ 77 "%s" % (emcroot) 78 include_dirs = [os.path.join(emcroot, "include")] 79 library_dirs = [os.path.join(emcroot, "lib")] 80 extra_link_args = ['-Wl,-rpath,%s' % library_dirs[0]] 81 82 print "Building AXIS", version, "for EMC2 in", emcroot 83 gcode = Extension("gcode", [ 84 "extensions/gcodemodule.cc" 85 ], 86 define_macros = [('AXIS_USE_EMC2', 1), ('NEW_INTERPRETER', 1)], 87 include_dirs=include_dirs, 88 library_dirs=library_dirs, 89 extra_link_args = extra_link_args, 90 libraries = ['rs274', 'nml', 'm', 'stdc++', 'GL'], 91 ) 92 93 emc = Extension("emc", ["extensions/emcmodule.cc"], 94 define_macros=[('DEFAULT_NMLFILE', 95 '"%s/configs/sim/emc.nml"' % emcroot), 96 ('AXIS_USE_EMC2', 1)], 97 libraries = ["emc", "nml", "m", "stdc++", "GL"], 98 include_dirs=include_dirs, 99 library_dirs=library_dirs, 100 extra_link_args = extra_link_args, 101 ) 102 103 if os.path.exists(os.path.join(emcroot, "lib", "libemchal.so")): 104 hal = Extension("hal", ["extensions/halmodule.cc"], 105 libraries = ["emchal"], 106 include_dirs=include_dirs, 107 library_dirs=library_dirs, 108 extra_link_args = extra_link_args, 109 ) 110 111 os.environ['USE_SYSTEM_BWIDGET']="yes" 112 113 elif is_bdi4: 114 distutils.command.install.INSTALL_SCHEMES['unix_prefix']['scripts'] = \ 115 "%s/plat/linux_rtai/bin" % (emcroot) 116 print "Building AXIS", version, "for BDI-4 in", emcroot 117 118 119 gcode = Extension("gcode", [ 120 "extensions/gcodemodule.cc" 121 ], 122 define_macros = [('AXIS_USE_BDI4', 1), ('NEW_INTERPRETER', 1)], 123 include_dirs=[ 124 os.path.join(emcroot, "src/include"), 125 ], 126 library_dirs = [ 127 os.path.join(emcroot, "plat/linux_rtai/lib") 128 ], 129 libraries = ['nml', 'm', 'stdc++'], 130 extra_link_args = [ 131 '-Wl,-rpath,%s' % os.path.join(emcroot, "plat/linux_rtai/lib"), 132 os.path.join(emcroot, "src", ".tmp", "rs274.o"), 133 '-lnml', '-lm', '-lstdc++' 134 ] 135 ) 136 137 emc = Extension("emc", ["extensions/emcmodule.cc"], 138 define_macros=[('DEFAULT_NMLFILE', 139 '"%s/emc.nml"' % emcroot), 140 ('AXIS_USE_BDI4', 1)], 141 include_dirs=[ 142 os.path.join(emcroot, "src/include") 143 ], 144 library_dirs = [ 145 os.path.join(emcroot, "plat/linux_rtai/lib") 146 ], 147 libraries = ["emc", "nml", "m", "stdc++", "GL"] 148 ) 149 150 else: 151 emcplat = os.getenv("PLAT", find_emc_plat(emcroot)) 152 if emcplat is None: 153 print """\ 154 setup.py failed to locate the (non-realtime) platform of your emc 155 installation. Determine the platform name and re-run setup.py with a 156 commandline like this: 157 $ env PLAT=nonrealtime python setup.py install 158 159 If you had to specify EMCROOT, the commandline would look like 160 $ env EMCROOT=/usr/local/emc PLAT=nonrealtime python setup.py install 161 162 See the README file for more information.""" 163 raise SystemExit, 1 164 distutils.command.install.INSTALL_SCHEMES['unix_prefix']['scripts'] = \ 165 "%s/emc/plat/%s/bin" % (emcroot, emcplat) 166 print "Building AXIS", version, "for EMC in", emcroot 167 print "Non-realtime PLAT", emcplat 168 169 gcode = Extension("gcode", [ 170 "extensions/gcodemodule.cc" 171 ], 172 define_macros = [('NEW_INTERPRETER', 1)], 173 include_dirs=[ 174 os.path.join(emcroot, "emc", "plat", emcplat, "include", 175 "rs274ngc_new"), 176 os.path.join(emcroot, "emc", "plat", emcplat, "include"), 177 os.path.join(emcroot, "rcslib", "plat", emcplat, "include") 178 ], 179 library_dirs = [ 180 os.path.join(emcroot, "emc", "plat", emcplat, "lib"), 181 os.path.join(emcroot, "rcslib", "plat", emcplat, "lib") 182 ], 183 libraries = ['rcs', 'm', 'stdc++'], 184 extra_link_args = [ 185 '-Wl,-rpath,%s' % 186 os.path.join(emcroot, "rcslib", "plat", emcplat, "lib"), 187 os.path.join(emcroot, "emc", "plat", emcplat, "lib", "rs274abc.o"), 188 ] 189 ) 190 191 emc = Extension("emc", ["extensions/emcmodule.cc"], 192 define_macros=[('DEFAULT_NMLFILE', '"%s/emc/emc.nml"' % emcroot)], 193 include_dirs=[ 194 os.path.join(emcroot, "emc", "plat", emcplat, "include"), 195 os.path.join(emcroot, "rcslib", "plat", emcplat, "include") 196 ], 197 library_dirs = [ 198 os.path.join(emcroot, "emc", "plat", emcplat, "lib"), 199 os.path.join(emcroot, "rcslib", "plat", emcplat, "lib") 200 ], 201 libraries = ["emc", "rcs", "m", "stdc++", "GL"], 202 extra_link_args = ['-Wl,-rpath,%s' % 203 os.path.join(emcroot, "rcslib", "plat", emcplat, "lib")] 204 ) 205 206 flags = get_togl_flags() 207 togl = Extension("_togl", ["extensions/_toglmodule.c"], **flags) 208 seticon = Extension("_tk_seticon", ["extensions/seticon.c"], **flags) 209 210 ext_modules = [emc, togl, gcode, minigl, seticon] 211 if hal: 212 ext_modules.append(hal) 213 214 def lang(f): 215 import os 216 return os.path.splitext(os.path.basename(f))[0] 217 i18n = [(os.path.join(LOCALEDIR,lang(f),"LC_MESSAGES"), [(f, "axis.mo")]) 218 for f in glob("i18n/??.mo") + glob("i18n/??_??.mo")] 219 220 setup(name=name, version=version, 221 description="AXIS front-end for emc", 222 author="Jeff Epler", author_email="jepler@unpythonic.net", 223 package_dir={'': 'lib', 'rs274' : 'rs274'}, 224 packages=['', 'rs274'], 225 scripts={WINDOWED('axis'): 'scripts/axis.py', 226 TERMINAL('axis-remote'): 'scripts/axis-remote.py', 227 TERMINAL('emctop'): 'scripts/emctop.py', 228 TERMINAL('hal_manualtoolchange'): 'scripts/hal_manualtoolchange.py', 229 TERMINAL('mdi'): 'scripts/mdi.py'}, 230 cmdclass = { 'build_scripts': build_scripts, 'install_data': install_data}, 231 data_files = [(os.path.join(SHAREDIR, "tcl"), glob("tcl/*.tcl")), 232 (os.path.join(SHAREDIR, "tcl"), glob("thirdparty/*.tcl")), 233 (os.path.join(SHAREDIR, "images"), glob("images/*.gif")), 234 (os.path.join(SHAREDIR, "images"), glob("images/*.xbm")), 235 (os.path.join(SHAREDIR, "images"), ["images/axis.ngc"]), 236 (DOCDIR, ["COPYING", "README", "BUGS", 237 "doc/axis_light_background", 238 "thirdparty/LICENSE-Togl"])] + i18n, 239 ext_modules = ext_modules, 240 url="http://axis.unpythonic.net/", 241 license="GPL", 242 ) 243 244 # vim:ts=8:sts=4:et: