code: def copy_and_patch_libzmq(ZMQ, libzmq):
      
  
      if sys.platform.startswith('win'):
          return
  
      # copy libzmq into zmq for bdist
      local = localpath('zmq',libzmq)
      if not ZMQ and not os.path.exists(local):
          fatal("Please specify zmq prefix via `setup.py configure --zmq=/path/to/zmq` "
                "or copy libzmq into zmq/ manually prior to running bdist.")
  
      try:
          # resolve real file through symlinks
          lib = os.path.realpath(pjoin(ZMQ, 'lib', libzmq))
          print ("copying %s -> %s"%(lib, local))
          shutil.copy(lib, local)
      except Exception:
          if not os.path.exists(local):
              fatal("Could not copy libzmq into zmq/, which is necessary for bdist. "
                    "Please specify zmq prefix via `setup.py configure --zmq=/path/to/zmq` "
                    "or copy libzmq into zmq/ manually.")
      
      if sys.platform == 'darwin':
          # chmod u+w on the lib,
          # which can be user-read-only for some reason
          mode = os.stat(local).st_mode
          os.chmod(local, mode | stat.S_IWUSR)
  
          # patch install_name on darwin, instead of using rpath
          cmd = ['install_name_tool', '-id', '@loader_path/../%s' % libzmq, local]
  
          try:
              p = Popen(cmd, stdout=PIPE, stderr=PIPE)
          except OSError:
              fatal("install_name_tool not found, cannot patch libzmq for bundling.")
  
          out, err = p.communicate()
  
          if p.returncode:
              fatal("Could not patch bundled libzmq install_name: %s"%err, p.returncode)
docs: copy libzmq into source dir, and patch it if necessary.
      
      This command is necessary prior to running a bdist on Linux or OS X.