Skip to content

Commit

Permalink
QoL: Optionally use overloaded env vars per target (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMcCulloch authored Dec 12, 2022
1 parent 20fbead commit 3b963de
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ files and libraries:
* `FFMPEG_INCLUDE_DIR` - path to the FFmpeg header files
* `FFMPEG_LIB_DIR` - path to the FFmpeg libs

If you require building for multiple platforms, you can append `_PLATFORM_TARGET_TRIPLET` to both of the above to create platform specific env. variables, for example:
* `FFMPEG_INCLUDE_DIR_AARCH64_LINUX_ANDROID = ${jniInclude}/arm64-v8a/`
* `FFMPEG_LIB_DIR_AARCH64_LINUX_ANDROID = ${jniLibs}/arm64-v8a/`
* `FFMPEG_INCLUDE_DIR_X86_64_LINUX_ANDROID = ${jniInclude}/x86_64/`
* `FFMPEG_LIB_DIR_X86_64_LINUX_ANDROID = ${jniLibs}/x86_64/`

If you prefer static linking, you can force it using:

* `FFMPEG_STATIC=1`
Expand Down
26 changes: 24 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ fn main() {
}

fn ffmpeg_include_dirs() -> Vec<PathBuf> {
if let Ok(dir) = env::var("FFMPEG_INCLUDE_DIR") {
if let Some(target) = normalized_target() {
if let Ok(dir) = env::var(&format!("FFMPEG_INCLUDE_DIR_{}", target)) {
let dir = PathBuf::from(dir);

if dir.is_dir() {
return vec![dir];
}
}
} else if let Ok(dir) = env::var("FFMPEG_INCLUDE_DIR") {
let dir = PathBuf::from(dir);

if dir.is_dir() {
Expand All @@ -78,7 +86,15 @@ fn ffmpeg_include_dirs() -> Vec<PathBuf> {
}

fn ffmpeg_lib_dirs() -> Vec<PathBuf> {
if let Ok(dir) = env::var("FFMPEG_LIB_DIR") {
if let Some(target) = normalized_target() {
if let Ok(dir) = env::var(&format!("FFMPEG_LIB_DIR_{}", target)) {
let dir = PathBuf::from(dir);

if dir.is_dir() {
return vec![dir];
}
}
} else if let Ok(dir) = env::var("FFMPEG_LIB_DIR") {
let dir = PathBuf::from(dir);

if dir.is_dir() {
Expand All @@ -97,6 +113,12 @@ fn ffmpeg_lib_dirs() -> Vec<PathBuf> {
lib.link_paths
}

fn normalized_target() -> Option<String> {
env::var("TARGET")
.ok()
.map(|t| t.to_uppercase().replace('-', "_"))
}

fn link_static(lib: &str) {
link(lib, "static")
}
Expand Down

0 comments on commit 3b963de

Please sign in to comment.