build: Allow to override build date with SOURCE_DATE_EPOCH
[vpp.git] / src / scripts / generate_version_h
1 #!/bin/bash
2 : ${VPP_BUILD_USER:=$(whoami)}
3 : ${VPP_BUILD_HOST:=$(hostname)}
4 DATE_FMT="+%Y-%m-%dT%H:%M:%S"
5 SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
6 VPP_BUILD_DATE=$(date -u -d "@$SOURCE_DATE_EPOCH" "$DATE_FMT" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "$DATE_FMT" 2>/dev/null || date -u "$DATE_FMT")
7
8 cat > ${1} << __EOF__
9 /*
10  * Copyright (c) 2018 Cisco and/or its affiliates.
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at:
14  *
15  *     http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23
24 #ifndef included_vpp_app_version_h
25 #define included_vpp_app_version_h
26
27 #define VPP_BUILD_DATE "$VPP_BUILD_DATE"
28 #define VPP_BUILD_USER "$VPP_BUILD_USER"
29 #define VPP_BUILD_HOST "$VPP_BUILD_HOST"
30 #define VPP_BUILD_TOPDIR "$(git rev-parse --show-toplevel 2> /dev/null)"
31 #define VPP_BUILD_VER "$(scripts/version)"
32 #endif
33 __EOF__