#!/bin/sh # NB: Supposed to be POSIX compatible but at least the usage of 'local' is not. # # This file is part of the flashrom project. # # Copyright (C) 2005 coresystems GmbH # Copyright (C) 2009,2010 Carl-Daniel Hailfinger # Copyright (C) 2010 Chromium OS Authors # Copyright (C) 2013-2016 Stefan Tauner # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # EXIT_SUCCESS=0 EXIT_FAILURE=1 # Make sure we don't get translated output export LC_ALL=C # nor local times or dates export TZ=UTC0 # Helper functions # First argument is the path to inspect (usually optional; without # it the whole repository will be considered) git_has_local_changes() { git update-index -q --refresh >/dev/null ! git diff-index --quiet HEAD -- "$1" } git_last_commit() { # git rev-parse --short HEAD would suffice if repository as a whole is of interest (no $1) git log --pretty=format:"%h" -1 -- "$1" } git_is_file_tracked() { git ls-files --error-unmatch -- "$1" >/dev/null 2>&1 } is_file_tracked() { git_is_file_tracked "$1" } # Tries to find a remote source for the changes committed locally. # This includes the URL of the remote repository including the last commit and a suitable branch name. # Takes one optional argument: the path to inspect git_url() { last_commit=$(git_last_commit "$1") # get all remote branches containing the last commit (excluding origin/HEAD) branches=$(git branch -r --contains $last_commit | sed '/\//!d;/.*->.*/d;s/[\t ]*//') if [ -z "$branches" ] ; then echo "No remote branch contains a suitable commit">&2 return fi # find "nearest" branch local mindiff=9000 local target= for branch in $branches ; do curdiff=$(git rev-list --count $last_commit..$branch) if [ $curdiff -ge $mindiff ] ; then continue fi mindiff=$curdiff target=$branch done echo "$(git ls-remote --exit-code --get-url ${target%/*}) ${target#*/}" } # Returns a string indicating where others can get the current source code (excluding uncommitted changes). # Takes one optional argument: the path to inspect scm_url() { local url= if git_is_file_tracked "$1" ; then url="$(git_url "$1")" else return ${EXIT_FAILURE} fi echo "${url}" } # Retrieve timestamp since last modification. If the sources are pristine, # then the timestamp will match that of the SCM's most recent modification # date. timestamp() { local t # date syntaxes are manifold: # gnu date [-d input]... [+FORMAT] # netbsd date [-ajnu] [-d date] [-r seconds] [+format] [[[[[[CC]yy]mm]dd]HH]MM[.SS]] # freebsd date [-jnu] [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...] # dragonflybsd date [-jnu] [-d dst] [-r seconds] [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format] [...] # openbsd date [-aju] [-d dst] [-r seconds] [+format] [[[[[[cc]yy]mm]dd]HH]MM[.SS]] [...] if git_is_file_tracked "$2" ; then # are there local changes? if git_has_local_changes "$2" ; then t=$(date -u "${1}") else # No local changes, get date of the last commit case $(uname) in # Most BSD dates do not support parsing date values from user input with -d but all of # them support parsing epoch seconds with -r. Thanks to git we can easily use that: NetBSD|OpenBSD|DragonFly|FreeBSD) t=$(date -u -r "$(git log --pretty=format:%ct -1 -- $2)" "$1" 2>/dev/null);; *) t=$(date -d "$(git log --pretty=format:%cD -1 -- $2
CMake helpers
-------------

Pybind11 can be used with ``add_subdirectory(extern/pybind11)``, or from an
install with ``find_package(pybind11 CONFIG)``. The interface provided in
either case is functionally identical.

.. cmake-module:: ../../tools/pybind11Config.cmake.in