Created
March 17, 2014 17:00
-
-
Save henry0312/9603498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'formula' | |
class X264DownloadStrategy < CurlDownloadStrategy | |
def tarball_path | |
Pathname.new("#{HOMEBREW_CACHE}/#{name}-#{resource.version}#{ext}") | |
end | |
def ext | |
'.tar.gz' | |
end | |
end | |
class GitVersion | |
def initialize(downloader) | |
@downloader = downloader | |
end | |
def get_revision | |
`cd #{git_cache} && git rev-list origin/master | sort | wc -l | awk '{print $1}'`.strip | |
end | |
def get_head_hash | |
`cd #{git_cache} && git rev-list origin/master | head -1 | cut -c 1-7`.strip | |
end | |
private | |
def git_cache | |
@downloader.cached_location | |
end | |
end | |
class X264 < Formula | |
homepage 'http://www.videolan.org/developers/x264.html' | |
url 'http://git.videolan.org/?p=x264.git;a=snapshot;h=aff928d2a2f601072cebecfd1ac5ff768880cf88;sf=tgz', :using => X264DownloadStrategy | |
sha1 '51ce24e35d67360e721538541e9e8a1a6961779d' | |
version 'r2397' | |
head 'http://git.videolan.org/git/x264.git' | |
devel do | |
url 'http://git.videolan.org/?p=x264.git;a=snapshot;h=d6b4e63d2ed8d444b77c11b36c1d646ee5549276;sf=tgz', :using => X264DownloadStrategy | |
sha1 '733997577215ec233b2ca9382bbd679f9c668d2a' | |
version 'r2409' | |
end | |
depends_on 'yasm' => :build | |
option "enable-shared", "build shared library" | |
option "enable-static", "build static library" | |
option "disable-opencl", "disable OpenCL features" | |
option "disable-gpl", "disable GPL-only features" | |
option "disable-thread", "disable multithreaded encoding" | |
option "disable-interlaced", "disable interlaced encoding support" | |
option "bit-depth=10", "set output bit depth 10" | |
option "enable-debug", "add -g" | |
option "enable-gprof", "add -pg" | |
option "enable-strip", "add -s" | |
option "enable-pic", "build position-independent code" | |
option "disable-avs", "disable avisynth support" | |
option "disable-swscale", "disable swscale support" | |
option "disable-lavf", "disable libavformat support" | |
option "disable-ffms", "disable ffmpegsource support" | |
option "disable-gpac", "disable gpac support" | |
option "disable-lsmash", "disable lsmash support" | |
def install | |
args = ["--prefix=#{prefix}"] | |
args << "--enable-shared" if build.include? "enable-shared" | |
args << "--enable-static" if build.include? "enable-static" | |
args << "--disable-opencl" if build.include? "disable-opencl" | |
args << "--disable-gpl" if build.include? "disable-gpl" | |
args << "--disable-thread" if build.include? "disable-thread" | |
args << "--bit-depth=10" if build.include? "bit-depth=10" | |
args << "--enable-debug" if build.include? "enable-debug" | |
args << "--enable-gprof" if build.include? "enable-gprof" | |
args << "--enable-strip" if build.include? "enable-strip" | |
args << "--enable-pic" if build.include? "enable-pic" | |
args << "--disable-avs" if build.include? "disable-avs" | |
args << "--disable-swscale" if build.include? "disable-swscale" | |
args << "--disable-lavf" if build.include? "disable-lavf" | |
args << "--disable-ffms" if build.include? "disable-ffms" | |
args << "--disable-gpac" if build.include? "disable-gpac" | |
args << "--disable-lsmash" if build.include? "disable-lsmash" | |
system "./configure", *args | |
if build.head? | |
git = GitVersion.new(@active_spec.downloader) | |
_version = "r" + git.get_revision | |
_hash = git.get_head_hash | |
else | |
_version = version.to_s | |
_hash = url.slice(/h=(\w+);/, 1).slice(0..6) | |
end | |
inreplace 'x264_config.h' do |s| | |
s.gsub! "X264_VERSION \"\"", "X264_VERSION \" #{_version} #{_hash}\"" | |
s.gsub! ".x", ".#{_version[1..-1]} #{_hash}" | |
end | |
File.open('x264_config.h', 'a') do |file| | |
file << "#define X264_REV #{_version[1..-1]}\n" | |
file << "#define X264_REV_DIFF 0\n" | |
end | |
system "make install" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment