hluk / CopyQ

Clipboard manager with advanced features
GNU General Public License v3.0
8.69k stars 441 forks source link

Feature request - linuxbrew formula #840

Open black-snow opened 6 years ago

black-snow commented 6 years ago

It'd be awesome if I could install copyq via a simple brew install copyq. Sadly it's only available as a cask and those are macOS only.

hluk commented 6 years ago

Good idea. Unfortunately I have issue when I try to build dependencies with brew so I cannot test this.

Anyway, here is how formula for CopyQ could look like.

(Command make install won't work for OS X where the app is currently built with utils/travis/script-osx.sh.)

class Copyq < Formula
  desc "Clipboard manager with advanced features"
  homepage "https://hluk.github.io/CopyQ/"
  url "https://github.com/hluk/CopyQ/archive/v3.1.2.tar.gz"
  sha256 "7f351ecbf906b385ebb64397eaecd344042131d41f9453e764bc15171f778647"
  head "https://github.com/hluk/CopyQ.git"

  option "with-tests", "Build with tests"

  needs :cxx11

  depends_on "cmake" => :build
  depends_on "qt"

  def install
    # For Mountain Lion
    ENV.libcxx

    args = std_cmake_args
    args << "-DWITH_TESTS=" + (build.with?("tests") ? "1" : "0")

    system "cmake", *args
    system "make", "install"
  end

  test do
    system "#{bin}/copyq", "--version"
    system "#{bin}/copyq", "--help"
    system "#{bin}/copyq", "--info"
  end
end
black-snow commented 6 years ago

@hluk Thanks for the quick reply! Could you share your issues?

I'll get back to this in January, I think. As CopyQ is X-platform there should be formulas for both, mac and linux - or one that fits both. It's already available in choco.

For reference: https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md https://apple.stackexchange.com/questions/97065/how-do-i-write-a-homebrew-recipe

hluk commented 6 years ago

This is the issue:

> brew install copyq
==> Installing dependencies for copyq: systemd, flex, cunit, pixman, cairo, linuxbrew/xorg/libdrm, linuxbrew/xorg/libsha1, libmpc, isl, gcc, binutils, libedit, llvm, libelf, linuxbrew/xorg/libomxil-bellagio, linuxbrew/xorg/wayland, linuxbrew/xorg/wayland-protocols, valgrind, linuxbrew/xorg/libva, linuxbrew/xorg/libvdpau, linuxbrew/xorg/mesa, qt
==> Installing copyq dependency: systemd
==> Downloading https://github.com/systemd/systemd/archive/v234.tar.gz
Already downloaded: /home/lukas/.cache/Homebrew/systemd-234.tar.gz
==> ./autogen.sh
==> ./configure --disable-acl --disable-silent-rules --prefix=/home/lukas/.linuxbrew/Cellar/systemd/234_1 --localstatedir=/home/lukas/.linuxbrew/var --sysconfdir=/home/lukas/.linuxbrew/Cellar/systemd/234_1/etc --with-rootprefix=/home/lukas/.linuxbrew/Cellar/systemd/234_1 --
Last 15 lines from /home/lukas/.cache/Homebrew/Logs/systemd/02.configure:
checking if gcc-7 supports -c -o file.o... yes
checking if gcc-7 supports -c -o file.o... (cached) yes
checking whether the gcc-7 linker (/home/lukas/.linuxbrew/Library/Homebrew/shims/linux/super/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for intltool-merge... yes
checking whether NLS is requested... yes
Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/^(.*)\${ <-- HERE ?([A-Z_]+)}?(.*)$/ at /home/lukas/.linuxbrew/opt/intltool/bin/intltool-update line 1066.
checking for intltool >= 0.40.0...  found
configure: error: Your intltool is too old.  You need intltool 0.40.0 or later.
READ THIS: https://github.com/Linuxbrew/brew/blob/master/docs/Troubleshooting.md#troubleshooting
Please do not report this issue to Homebrew/brew or Homebrew/core, which support macOS only.
These open issues may also help:
systemd failed on ArchLinux https://github.com/Linuxbrew/homebrew-core/issues/5132

The first problem looks like incompatible version of Perl is used.

Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/^(.*)\${ <-- HERE ?([A-Z_]+)}?(.*)$/ at /home/lukas/.linuxbrew/opt/intltool/bin/intltool-update line 1066.
> which perl
/home/lukas/.linuxbrew/bin/perl
> perl -v
This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-thread-multi
Copyright 1987-2017, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
hluk commented 6 years ago

Solved the issue with systemd brew build. Workaround is to patch intltool-update.

Unfortunately there is another issue.

==> Installing copyq dependency: flex
==> Downloading https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
Already downloaded: /home/lukas/.cache/Homebrew/flex-2.6.4.tar.gz
==> ./configure --disable-silent-rules --enable-shared --prefix=/home/lukas/.linuxbrew/Cellar/flex/2.6.4
==> make install
Last 15 lines from /home/lukas/.cache/Homebrew/Logs/flex/02.make:
gcc-7 -DHAVE_CONFIG_H -I.  -DLOCALEDIR=\"/home/lukas/.linuxbrew/Cellar/flex/2.6.4/share/locale\"   -g -O2 -c -o stage1flex-yylex.o `test -f 'yylex.c' || echo './'`yylex.c
/bin/sh ../libtool  --tag=CC   --mode=link gcc-7  -g -O2 -version-info 2:0:0  -o libfl.la -rpath /home/lukas/.linuxbrew/Cellar/flex/2.6.4/lib libmain.lo libyywrap.lo  -lm
libtool: link: gcc-7 -shared  -fPIC -DPIC  .libs/libmain.o .libs/libyywrap.o   -lm  -g -O2   -Wl,-soname -Wl,libfl.so.2 -o .libs/libfl.so.2.0.0
libtool: link: (cd ".libs" && rm -f "libfl.so.2" && ln -s "libfl.so.2.0.0" "libfl.so.2")
libtool: link: (cd ".libs" && rm -f "libfl.so" && ln -s "libfl.so.2.0.0" "libfl.so")
libtool: link: ar cru .libs/libfl.a  libmain.o libyywrap.o
ar: `u' modifier ignored since `D' is the default (see `U')
libtool: link: ranlib .libs/libfl.a
/bin/sh ../libtool  --tag=CC   --mode=link gcc-7  -g -O2   -o stage1flex stage1flex-scan.o stage1flex-buf.o stage1flex-ccl.o stage1flex-dfa.o stage1flex-ecs.o stage1flex-filter.o stage1flex-gen.o stage1flex-main.o stage1flex-misc.o stage1flex-nfa.o stage1flex-options.o stage1flex-parse.o stage1flex-regex.o stage1flex-scanflags.o stage1flex-scanopt.o stage1flex-skel.o stage1flex-sym.o stage1flex-tables.o stage1flex-tables_shared.o stage1flex-tblcmp.o stage1flex-yylex.o    -lm
libtool: link: ( cd ".libs" && rm -f "libfl.la" && ln -s "../libfl.la" "libfl.la" )
libtool: link: gcc-7 -g -O2 -o stage1flex stage1flex-scan.o stage1flex-buf.o stage1flex-ccl.o stage1flex-dfa.o stage1flex-ecs.o stage1flex-filter.o stage1flex-gen.o stage1flex-main.o stage1flex-misc.o stage1flex-nfa.o stage1flex-options.o stage1flex-parse.o stage1flex-regex.o stage1flex-scanflags.o stage1flex-scanopt.o stage1flex-skel.o stage1flex-sym.o stage1flex-tables.o stage1flex-tables_shared.o stage1flex-tblcmp.o stage1flex-yylex.o  -lm
./stage1flex   -o stage1scan.c ./scan.l
make[1]: *** [Makefile:1696: stage1scan.c] Segmentation fault (core dumped)
make[1]: Leaving directory '/tmp/flex-20171217-32638-1bh1650/flex-2.6.4/src'
make: *** [Makefile:533: install-recursive] Error 1

Looks like it could be related to https://github.com/westes/flex/issues/219 but using patch from https://github.com/westes/flex/pull/221 doesn't fix the problem.

black-snow commented 6 years ago

You're on macOS, right? A plain brew install flex should fail, too then, right? I wonder why we need flex at all - couldn't find it in the code. Is it a nested dependency?

hluk commented 6 years ago

You're on macOS, right?

No, I'm using linuxbrew on Arch Linux. It's rather issue https://github.com/westes/flex/issues/265 that matches my problem exactly.

A plain brew install flex should fail, too then, right?

Yes, executing brew install flex fails with the error.

I wonder why we need flex at all - couldn't find it in the code. Is it a nested dependency?

Yes, it's not directly required by CopyQ.

hluk commented 6 years ago

Adding _GNU_SOURCE definition for CFLAGS fixes the issue. It should be fixed in next version of flex.

diff --git a/Formula/flex.rb b/Formula/flex.rb
index 9f783bcd6e..7c3c525927 100644
--- a/Formula/flex.rb
+++ b/Formula/flex.rb
@@ -42,7 +42,8 @@ class Flex < Formula
     system "./configure", "--disable-dependency-tracking",
                           "--disable-silent-rules",
                           "--enable-shared",
-                          "--prefix=#{prefix}"
+                          "--prefix=#{prefix}",
+                          "CFLAGS=-D_GNU_SOURCE"
     system "make", "install"
     bin.install_symlink "flex" => "lex" unless OS.mac?
   end
black-snow commented 6 years ago

Nice, was that the last issue you had? Anything to help with?

hluk commented 6 years ago

Unfortunately, there are other issues. The last encountered is:

==> Installing copyq dependency: linuxbrew/xorg/mesa
==> Downloading https://mesa.freedesktop.org/archive/mesa-17.2.3.tar.xz
######################################################################## 100.0%
==> Downloading https://gist.githubusercontent.com/rwhogg/088a3e771be0f0556d2286c034544d18/raw/efd587120964745a61a2571a431ffc38341dc37c/mesa-patch-from-linux-from-scratch.patch
######################################################################## 100.0%
==> Patching
==> Applying mesa-patch-from-linux-from-scratch.patch
patching file xdemos/glinfo_common.c
patching file xdemos/glinfo_common.h
patching file xdemos/glxgears.1
patching file xdemos/glxgears.c
patching file xdemos/glxinfo.1
patching file xdemos/glxinfo.c
patching file xdemos/Makefile
==> Downloading https://files.pythonhosted.org/packages/56/4b/cb75836863a6382199aefb3d3809937e21fa4cb0db15a4f4ba0ecc2e7e8e/Mako-1.0.6.tar.gz
######################################################################## 100.0%
==> python -c import setuptools... --no-user-cfg install --prefix=/home/lukas/.linuxbrew/Cellar/mesa/17.2.3/libexec/vendor --single-version-externally-managed --record=installed.txt
==> ./autogen.sh CFLAGS=-Os -w -pipe -march=native CXXFLAGS=-Os -w -pipe -march=native --disable-silent-rules --disable-dependency-tracking --prefix=/home/lukas/.linuxbrew/Cellar/mesa/17.2.3 --sysconfdir=/home/lukas/.linuxbrew/etc --localstatedir=/home/lukas/.linuxbrew/var 
==> make
Last 15 lines from /home/lukas/.cache/Homebrew/Logs/mesa/03.make:
rasterizer/core/.libs/libswrAVX2_la-threads.o:(.data.rel.ro._ZTINSt6thread11_State_implINS_8_InvokerISt5tupleIJPFjPvEP11THREAD_DATAEEEEEE[_ZTINSt6thread11_State_implINS_8_InvokerISt5tupleIJPFjPvEP11THREAD_DATAEEEEEE]+0x10): undefined reference to `typeinfo for std::thread::_State'
collect2: error: ld returned 1 exit status
make[5]: *** [Makefile:1910: libswrAVX2.la] Error 1
...

Didn't have time to dig deeper, but Mesa and Qt should be the last dependencies to build.