summaryrefslogtreecommitdiffstats
path: root/docker/build-pb
blob: 62295509f20b28b093e24bff939159c872b11041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash

set -e

name="$(basename $0)"

: ${TOP_DIR:="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"}

source ${TOP_DIR}/docker/builder-include

usage () {
	echo "${name} - Builds the petitboot programs using a pb-builder container." >&2
	echo "Usage: ${name} [flags]" >&2
	echo "Option flags:" >&2
	echo "  -c --check              - Run 'make check'." >&2
	echo "  -d --dry-run            - Do not run docker commands." >&2
	echo "  -h --help               - Show this help and exit." >&2
	echo "  -i --interactive        - Run an interactive pb-builder container." >&2
	echo "  -m --make-command       - Set a specific command to be called for 'make'.">&2
	echo "  -o --configure-opts     - Extra arguments for configure." >&2
	echo "  -t --tag                - Print Docker tag to stdout and exit." >&2
	echo "  -v --verbose            - Verbose execution." >&2
	echo "Environment:" >&2
	echo "  DOCKER_TAG              - Default: '${DOCKER_TAG}'" >&2
	echo "  CFLAGS                  - Default: '${CFLAGS}'" >&2
	echo "  LDFLAGS                 - Default: '${LDFLAGS}'" >&2
	echo "  CC                      - Default: '${CC}'" >&2
	echo "Examples:" >&2
	echo "  ${name} -vc"
	echo "  ${name} -v"
}

short_opts="cdhim:o:tv"
long_opts="check,dry-run,help,interactive,make-command:,configure-opts:,tag,verbose"

opts=$(getopt --options ${short_opts} --long ${long_opts} -n "${name}" -- "$@")

if [ $? != 0 ]; then
	echo "${name}: ERROR: Internal getopt" >&2 
	exit 1
fi

eval set -- "${opts}"

while true ; do
	case "${1}" in
	-c | --check)
		check=1
		shift
		;;
	-d | --dry-run)
		dry_run=1
		shift
		;;
	-h | --help)
		usage=1
		shift
		;;
	-i | --interactive)
		interactive=1
		shift
		;;
	-m | --make-command)
		shift
		makecmd=${1}
		shift
		;;
	-o | --configure-opts)
		shift
		configure_opts=${1}
		shift
		;;
	-t | --tag)
		tag=1
		shift
		;;
	-v | --verbose)
		set -x
		verbose=1
		shift
		;;
	--)
		shift
		break
		;;
	*)
		echo "${name}: ERROR: Internal opts" >&2 
		exit 1
		;;
	esac
done

if [[ -n "${usage}" ]]; then
	usage
	exit 0
fi

if [[ -n "${tag}" ]]; then
	show_tag
	exit 0
fi

docker_base_args="\
	--rm \
	-v /etc/group:/etc/group:ro \
	-v /etc/passwd:/etc/passwd:ro \
	-v ${TOP_DIR}:/opt/pb \
	-w /opt/pb \
"

docker_user_args="-u $(id -u):$(id -g)"

if [[ -n "${interactive}" ]]; then
	cd "${TOP_DIR}"
	docker_args="${docker_base_args} --privileged"
	run_cmd "docker run -it ${docker_args} ${DOCKER_TAG} /bin/bash"
	exit
fi

if [[ -n "${verbose}" ]]; then
	bash_debug="-x"
fi

if [[ -n "${check}" ]]; then
	docker_extra="make check"
else
	docker_extra="true"
fi

if [[ -z "${makecmd}" ]]; then
	makecmd="make"
fi

flags="CFLAGS=${CFLAGS} LDFLAGS=${LDFLAGS} CC=${CC}"

cd "${TOP_DIR}"
docker_args="${docker_base_args} ${docker_user_args}"
run_cmd "docker run ${docker_args} ${DOCKER_TAG} /bin/bash \
	-e ${bash_debug} \
	-c './bootstrap && ${flags} ./configure ${configure_opts[@]} && ${makecmd} && ${docker_extra}'"
OpenPOWER on IntegriCloud