Skip to content
supechicken edited this page Jan 20, 2022 · 21 revisions

Creating a package installed from source

  1. Create an empty file in /usr/local/lib/crew/packages/ with a .rb extension. If you want to add a recipe for a package called bc, name the file bc.rb.

  2. Update the content of the file to conform with the following template:

require 'package'

class Bc < Package                 # The first character of the class name must be upper case
  description 'bc is an arbitrary precision numeric processing language.'
  homepage 'http://www.gnu.org/software/bc/'
  version '1.07.1'
  license 'GPL-3' # license of source
  compatibility 'all'
  source_url 'https://ftp.gnu.org/gnu/bc/bc-1.07.1.tar.gz'
  source_sha256 '62adfca89b0a1c0164c2cdca59ca210c1d44c3ffc46daf9931cf4942664cb02a'   # Use the command "sha256sum"

  depends_on 'readline'            # packages required by this package
  depends_on 'flex' => :build      # packages with "=> :build" are only required if you're building from source 
  depends_on 'ed' => :build

  def self.build                   # the steps required to build the package
    system "./configure #{CREW_OPTIONS} --with-readline"
    system "make"
  end

  def self.install                 # the steps required to install the package
    system "make", "DESTDIR=#{CREW_DEST_DIR}", "install"
  end

  def self.check                   # the steps required to check if the package was built ok
    system "make", "check"
  end
end
  1. Use #{CREW_OPTIONS} on ./configure and DESTDIR=#{CREW_DEST_DIR} on install to make sure everything ends up in the correct place.

  2. Try your recipe via crew install <pkgName>, e.g. crew install bc.

  3. Ensure your package was successfully installed. To confirm, execute crew files <pkgName> and make sure there are files listed and they appear to be in the correct location.

  4. Ensure your package can be uninstalled without leaving file residue behind. To confirm, execute crew remove <pkgName> and make sure there are no errors produced by the command.

  5. Upload your package from /usr/local/lib/crew/packages/<pkgName>.rb to your own fork of this repository.

  6. Commit your changes and create a pull request. Please add a short description in the PR to explain the new package and any helpful links for more information.

Testing a pre-compiled binary

To test a pre-compiled binary file of your new package or to an existing one, you must first create a source-only package like above if it does not exist. After that:

  1. Use crew build <pkgName>, e.g. crew build bc.

  2. If you see <pkgname>-<version>-chromeos-<arch>.tpxz is built!, it means everything worked fine and the compressed file has everything you need. It will also create a .sha256 file that has the sha256 of the .tpxz file.

  3. Test your new binary. Add the following in your pkgname.rb file right below the source_url and source_sha256 lines:

  binary_url ({
    <arch>: 'file:///path/to/your/pre-compiled/binary/<pkgname>-<version>-chromeos-<arch>.tar.xz'
  })
  binary_sha256 ({
    <arch>: '<sha256 hash here>'
  })
  1. Make sure to add to the correct architecture. It could be x86_64, i686, armv7l or aarch64 (binary generated in aarch64 can be also used in armv7l since they are all running on 32-bit userspace) (the name will be included in the .tpxz filename). There may be more than one type of pre-compiled binary; each for a different architecture.

  2. Copy <pkgName>.rb to /usr/local/lib/crew/packages/ and then attempt to install.

$ cp <pkgName>.rb /usr/local/lib/crew/packages
$ crew install <pkgName>
  1. Test the installation:
$ crew files <pkgName>
$ <pkgCmd> --version
$ <pkgCmd> --help
$ <pkgCmd> ...

Replace <pkgCmd> with any binary executable(s) installed from the package, if applicable.

PS. Some useful templates for source code build:

  1. Building package from source code using cmake
  def self.build
    FileUtils.mkdir_p 'build'
    Dir.chdir("build") do
      system "cmake -G Ninja #{CREW_CMAKE_OPTIONS} .."
      system 'samu'
    end
  end

  def self.install                 # the steps required to install the package
    Dir.chdir("build") do
      system { 'DESTDIR' => CREW_DEST_DIR }, 'samu', 'install'
    end
  end