jordansissel / xdotool

fake keyboard/mouse input, window management, and more
Other
3.26k stars 319 forks source link

clock_gettime hack no longer required on macOS Sierra #138

Closed mistydemeo closed 8 years ago

mistydemeo commented 8 years ago

9bc31403b95826d9fd8d6540c459ee862b2ac127 added a definition of clock_gettime for OS X. However, OS X 10.12 now includes a native clock_gettime, and so the redefinition causes the build to fail.

Originally reported in Homebrew here: https://github.com/Homebrew/homebrew-x11/issues/219

jordansissel commented 8 years ago

Oh cool, finally clock_gettime!

I'm working on a patch.

jordansissel commented 8 years ago

Ok I've got master building on OSX 10.11 (el capitan?). I had to brew install homebrew/x11/libxkbcommon because at some point in the last few years we needed libxkbcommon.

Can you check master and let me know if make is successful on macOS Sierra? In theory, the new cflags.sh should detect you're on a newer OSX and will skip injecting a custom clock_gettime.

mistydemeo commented 8 years ago

Can confirm - works fine!

jordansissel commented 8 years ago

Woohoo!

I'll work on a new release (it's been a while...) and publish it as soon as I can.

mistydemeo commented 8 years ago

Thanks! A new release would be helpful; the patch didn't apply cleanly to the last release and it'd be more convenient to just have a new release to upgrade to.

jordansissel commented 8 years ago

Release: https://github.com/jordansissel/xdotool/releases/tag/v3.20160804.1

Tarball: https://github.com/jordansissel/xdotool/archive/v3.20160804.1.tar.gz

The test suite passes for me, and some manual testing makes things seem OK on Linux.

mistydemeo commented 8 years ago

Thanks! Have a PR up for the new release at Homebrew: https://github.com/Homebrew/homebrew-x11/pull/223

Couple things I noticed:

jordansissel commented 8 years ago

hmm... I'll spin up my mac and test. I confess I only tested this on Linux (Fedora 23).

jordansissel commented 8 years ago

Oh, right. I didn't have the Makefile detect and set WITHOUT_RPATH_FIX anywhere.

For now, make WITHOUT_RPATH_FIX=1 as you have in your patch makes sense to me.


As for the missing -lX11, I see it OK on my OSX 10.11 laptop. The Makefile hopes to use pkg-config to ask about library needs, but if that fails, it falls back to this:

DEFAULT_LIBS=-L/usr/X11R6/lib -L/usr/local/lib -lX11 -lXtst -lXinerama -lxkbcommon

pkg-config --libs x11 fails for me under OSX saying Package x11 was not found in the pkg-config search path, so when I do make I see the use of DEFAULT_LIBS.

Can you attach the output of make libxdo.dylib ?

mistydemeo commented 8 years ago
$ make libxdo.dylib
sh version.sh --header > xdo_version.h
clang -pipe -O2 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -Wno-missing-field-initializers -g   -DMISSING_CLOCK_GETTIME -std=c99 -I/usr/local/Cellar/libxkbcommon/0.5.0/include -I/opt/X11/include -fPIC -c xdo_search.c
clang -pipe -O2 -pedantic -Wall -W -Wundef -Wendif-labels -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wdisabled-optimization -Wno-missing-field-initializers -g   -DMISSING_CLOCK_GETTIME -std=c99 -I/usr/local/Cellar/libxkbcommon/0.5.0/include -I/opt/X11/include -fPIC -c xdo.c
clang  -dynamiclib -Wl,-install_name,/usr/local/lib/libxdo.3.dylib xdo.o xdo_search.o -o libxdo.dylib -L/usr/local/Cellar/libxkbcommon/0.5.0/lib -L/opt/X11/lib -lXtst -lXinerama -lxkbcommon
Undefined symbols for architecture x86_64:
  "_XAllocClassHint", referenced from:
      _xdo_set_window_class in xdo.o
  "_XAllocWMHints", referenced from:
      _xdo_set_window_urgency in xdo.o
  "_XAllowEvents", referenced from:
      _xdo_select_window_with_click in xdo.o
  "_XChangeKeyboardMapping", referenced from:
      _xdo_send_keysequence_window_list_do in xdo.o
  "_XChangeProperty", referenced from:
      _xdo_set_window_property in xdo.o
  "_XChangeWindowAttributes", referenced from:
      _xdo_set_window_override_redirect in xdo.o
  "_XCloseDisplay", referenced from:
      _xdo_free in xdo.o
  "_XConfigureWindow", referenced from:
      _xdo_move_window in xdo.o
      _xdo_set_window_size in xdo.o
  "_XCreateFontCursor", referenced from:
      _xdo_select_window_with_click in xdo.o
  "_XDefaultRootWindow", referenced from:
      _xdo_get_active_window in xdo.o
      __xdo_ewmh_is_supported in xdo.o
      _xdo_get_number_of_desktops in xdo.o
      _xdo_get_current_desktop in xdo.o
  "_XDestroyWindow", referenced from:
      _xdo_close_window in xdo.o
  "_XDisplayKeycodes", referenced from:
      _xdo_new_with_opened_display in xdo.o
  "_XFlush", referenced from:
      _xdo_map_window in xdo.o
      _xdo_unmap_window in xdo.o
      _xdo_reparent_window in xdo.o
      _xdo_set_window_size in xdo.o
      _xdo_focus_window in xdo.o
      _xdo_raise_window in xdo.o
      _xdo_move_mouse in xdo.o
      ...
  "_XFree", referenced from:
      _xdo_new_with_opened_display in xdo.o
      _xdo_get_window_location in xdo.o
      _xdo_set_window_class in xdo.o
      _xdo_set_window_urgency in xdo.o
      _xdo_find_window_client in xdo.o
      _xdo_send_keysequence_window_list_do in xdo.o
      _xdo_get_viewport_dimensions in xdo.o
      ...
  "_XFreeCursor", referenced from:
      _xdo_select_window_with_click in xdo.o
  "_XFreeModifiermap", referenced from:
      _xdo_new_with_opened_display in xdo.o
      _xdo_send_keysequence_window_list_do in xdo.o
      _xdo_get_active_modifiers in xdo.o
  "_XFreeStringList", referenced from:
      __xdo_match_window_name in xdo_search.o
  "_XGetAtomName", referenced from:
      _xdo_get_desktop_viewport in xdo.o
  "_XGetClassHint", referenced from:
      _xdo_set_window_class in xdo.o
      _check_window_match in xdo_search.o
  "_XGetInputFocus", referenced from:
      _xdo_get_focused_window in xdo.o
  "_XGetKeyboardMapping", referenced from:
      _xdo_new_with_opened_display in xdo.o
      _xdo_send_keysequence_window_list_do in xdo.o
  "_XGetModifierMapping", referenced from:
      _xdo_new_with_opened_display in xdo.o
      _xdo_send_keysequence_window_list_do in xdo.o
      _xdo_get_active_modifiers in xdo.o
  "_XGetWMHints", referenced from:
      _xdo_set_window_urgency in xdo.o
  "_XGetWMName", referenced from:
      __xdo_match_window_name in xdo_search.o
  "_XGetWMNormalHints", referenced from:
      _xdo_translate_window_with_sizehint in xdo.o
  "_XGetWindowAttributes", referenced from:
      _xdo_wait_for_window_map_state in xdo.o
      _xdo_get_window_location in xdo.o
      _xdo_get_window_size in xdo.o
      _xdo_activate_window in xdo.o
      _xdo_set_desktop_for_window in xdo.o
      _xdo_move_mouse_relative_to_window in xdo.o
      _xdo_minimize_window in xdo.o
      ...
  "_XGetWindowProperty", referenced from:
      _xdo_get_window_property_by_atom in xdo.o
  "_XGrabPointer", referenced from:
      _xdo_select_window_with_click in xdo.o
  "_XIconifyWindow", referenced from:
      _xdo_minimize_window in xdo.o
  "_XInternAtom", referenced from:
      _xdo_set_window_property in xdo.o
      _xdo_get_active_window in xdo.o
      _xdo_activate_window in xdo.o
      __xdo_ewmh_is_supported in xdo.o
      _xdo_get_desktop_for_window in xdo.o
      _xdo_set_current_desktop in xdo.o
      _xdo_set_number_of_desktops in xdo.o
      ...
  "_XKeysymToString", referenced from:
      _xdo_enter_text_window in xdo.o
  "_XKillClient", referenced from:
      _xdo_kill_window in xdo.o
  "_XMapWindow", referenced from:
      _xdo_map_window in xdo.o
  "_XOpenDisplay", referenced from:
      _xdo_new in xdo.o
  "_XQueryKeymap", referenced from:
      _xdo_get_active_modifiers in xdo.o
  "_XQueryPointer", referenced from:
      _xdo_get_mouse_location2 in xdo.o
      _xdo_get_input_state in xdo.o
  "_XQueryTree", referenced from:
      _xdo_get_window_location in xdo.o
      _xdo_find_window_client in xdo.o
      _find_matching_windows in xdo_search.o
  "_XRaiseWindow", referenced from:
      _xdo_raise_window in xdo.o
  "_XReparentWindow", referenced from:
      _xdo_reparent_window in xdo.o
  "_XScreenNumberOfScreen", referenced from:
      _xdo_move_mouse_relative_to_window in xdo.o
      _xdo_minimize_window in xdo.o
  "_XSendEvent", referenced from:
      _xdo_activate_window in xdo.o
      _xdo_set_current_desktop in xdo.o
      _xdo_set_number_of_desktops in xdo.o
      _xdo_set_desktop_for_window in xdo.o
      __xdo_mousebutton in xdo.o
      _xdo_send_keysequence_window_list_do in xdo.o
      _xdo_set_desktop_viewport in xdo.o
      ...
  "_XSetClassHint", referenced from:
      _xdo_set_window_class in xdo.o
  "_XSetInputFocus", referenced from:
      _xdo_focus_window in xdo.o
  "_XSetWMHints", referenced from:
      _xdo_set_window_urgency in xdo.o
  "_XStringToKeysym", referenced from:
      __xdo_send_keysequence_window_do in xdo.o
  "_XSync", referenced from:
      _xdo_send_keysequence_window_list_do in xdo.o
      _xdo_clear_active_modifiers in xdo.o
      _xdo_set_active_modifiers in xdo.o
  "_XTranslateCoordinates", referenced from:
      _xdo_get_window_location in xdo.o
      _xdo_move_mouse_relative_to_window in xdo.o
      __xdo_mousebutton in xdo.o
  "_XUngrabPointer", referenced from:
      _xdo_select_window_with_click in xdo.o
  "_XUnmapWindow", referenced from:
      _xdo_unmap_window in xdo.o
  "_XWarpPointer", referenced from:
      _xdo_move_mouse in xdo.o
  "_XWindowEvent", referenced from:
      _xdo_select_window_with_click in xdo.o
  "_XkbFreeClientMap", referenced from:
      _xdo_new_with_opened_display in xdo.o
  "_XkbGetMap", referenced from:
      _xdo_new_with_opened_display in xdo.o
  "_XkbGetState", referenced from:
      _xdo_send_keysequence_window_list_do in xdo.o
  "_XkbKeycodeToKeysym", referenced from:
      _xdo_new_with_opened_display in xdo.o
  "_XkbLockGroup", referenced from:
      _xdo_send_keysequence_window_list_do in xdo.o
  "_Xutf8TextPropertyToTextList", referenced from:
      __xdo_match_window_name in xdo_search.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libxdo.dylib] Error 1
mistydemeo commented 8 years ago

pkg-config --libs x11 fails for me under OSX saying Package x11 was not found in the pkg-config search path, so when I do make I see the use of DEFAULT_LIBS.

Since we specify an X11 dependency, we call pkg-config with PKG_CONFIG_LIBDIR set which causes it to find x11. However, it returns sensible flags:

-L/opt/X11/lib -lX11
mistydemeo commented 8 years ago

Oh, it looks like the flags are LIBXDO_LIBS, which uses pkg-config --libs xtst xinerama xkbcommon and doesn't include pkg-config --libs x11.

jordansissel commented 8 years ago

hmm.. I think I might know what's going on here... speculating.

Can you try this patch?

diff --git a/Makefile b/Makefile
index 85bf0de..cb763db 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ DEFAULT_LIBS=-L/usr/X11R6/lib -L/usr/local/lib -lX11 -lXtst -lXinerama -lxkbcomm
 DEFAULT_INC=-I/usr/X11R6/include -I/usr/local/include

 XDOTOOL_LIBS=$(shell pkg-config --libs x11 2> /dev/null || echo "$(DEFAULT_LIBS)")  $(shell sh platform.sh extralibs)
-LIBXDO_LIBS=$(shell pkg-config --libs xtst xinerama xkbcommon 2> /dev/null || echo "$(DEFAULT_LIBS)")
+LIBXDO_LIBS=$(shell pkg-config --libs x11 xtst xinerama xkbcommon 2> /dev/null || echo "$(DEFAULT_LIBS)")
 INC=$(shell pkg-config --cflags x11 xtst xinerama xkbcommon 2> /dev/null || echo "$(DEFAULT_INC)")
 CFLAGS+=-std=c99 $(INC)
mistydemeo commented 8 years ago

Haha, yep! We both had the same thought. That looks to be it.

jordansissel commented 8 years ago

@mistydemeo yeah I think you are right. On Fedora 23 building libxdo.so looks like this:

cc  -shared -Wl,-soname=libxdo.so.3 xdo.o xdo_search.o -o libxdo.so -lXtst -lXinerama -lxkbcommon

No libX11, but ldd shows it was linked anyway:

% ldd ./libxdo.so | grep X11
        libX11.so.6 => /lib64/libX11.so.6 (0x00007f23a0f7e000)

I think the linker on fedora has some kind of dependency management where I can have libxdo.so depend on libXinerama, and libXinerama itself needs libX11, and ldd is like "ok cool, we have libX11".... the fact that this works seems like a bug. Good catch!

mistydemeo commented 8 years ago

Thanks for the quick merges! I'll apply these patches to the Homebrew formula (unless you're planning a bugfix release).

jordansissel commented 8 years ago

I'll push a new patch release

jordansissel commented 8 years ago

https://github.com/jordansissel/xdotool/releases/download/v3.20160804.2/xdotool-3.20160804.2.tar.gz

jordansissel commented 8 years ago

Tested on Fedora 23 and OSX 10.11. Fingers crossed that we've got it right this time ;)

mistydemeo commented 8 years ago

Hm, cflags.sh seems to be missing from the generated tarball for me.

mistydemeo commented 8 years ago

Oh, rather, the generated tarball has it but the releases tarball you linked doesn't.

jordansissel commented 8 years ago

Hmm, weird that the tarball tests worked. I will fix this tomorrow morning.

On Thursday, August 4, 2016, Misty De Meo notifications@github.com wrote:

Oh, rather, the generated tarball has it but the releases tarball you linked doesn't.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jordansissel/xdotool/issues/138#issuecomment-237763992, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIC6ifNUJ639l3Euge4FkU_c5wj1OZ9ks5qctLIgaJpZM4JaS1G .

jordansissel commented 8 years ago

I fixed the release tests (make test-package-build) and they pass on both OSX 10.11 and Fedora 23 for me.

Maybe the 3rd time will work, haha:

https://github.com/jordansissel/xdotool/releases/download/v3.20160805.1/xdotool-3.20160805.1.tar.gz

mistydemeo commented 8 years ago

Yep, looks fine now!