File: configure-dev

package info (click to toggle)
gsmartcontrol 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,904 kB
  • sloc: cpp: 66,205; sh: 240; ansic: 125; xml: 33; makefile: 13
file content (160 lines) | stat: -rwxr-xr-x 3,809 bytes parent folder | download
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
###############################################################################
# License: BSD Zero Clause License file
# Copyright:
#   (C) 2012 - 2021 Alexander Shaduri <ashaduri@gmail.com>
###############################################################################

# Configure a build directory for development


function print_usage() {
	echo -e "Usage:"
	echo -e "    ${0} [-t <toolchain_name>] [-c <compiler>] [-b <build_type>]"
	echo -e "    [-s <source_dir>] [-g <generator>] [-o <cmake_options>]"
	echo -e "\nDetails:"
	echo -e "-t <toolchain_name> - toolchain_name can be e.g. \"win32-mingw64\"."
	echo -e "    A toolchain file \"toolchains/<toolchain_name>.cmake\" will be used."
	echo -e "-c <compiler> - compiler is one of:"
	echo -e "    gcc, gcc-<version>, clang, intel."
	echo -e "    The gcc version is the suffix of gcc and g++ executables, e.g. \"4.8\" in"
	echo -e "    \"gcc-4.8\"."
	echo -e "    If unspecified, CC and CXX environment variables are used."
	echo -e "-b <build_type> - build_type is one of:"
	echo -e "    Debug, Release, RelWithDebInfo, MinSizeRel, none. The default is Debug."
	echo -e "-s <source_dir> - source_dir is \"..\" by default."
	echo -e "-g <cmake_generator> - cmake uses \"Unix Makefiles\" by default."
	echo -e "-o <cmake_options> - options to pass directly to cmake."
}

compiler=""
build_type="";
source_dir=".."
toolchain_name=""
generator=""
cmake_options=""

while getopts "t:c:b:s:g:o:h:" opt; do
	case $opt in
		t)
			echo "Requested toolchain: $OPTARG"
			toolchain_name="$OPTARG";
			;;
		c)
			echo "Requested compiler: $OPTARG"
			compiler="$OPTARG";
			;;
		b)
			echo "Requested build type: $OPTARG"
			build_type="$OPTARG";
			;;
		s)
			echo "Requested source directory type: $OPTARG"
			source_dir="$OPTARG";
			;;
		g)
			echo "Requested generator: $OPTARG"
			generator="$OPTARG";
			;;
		o)
			echo "Requested cmake options: $OPTARG"
			cmake_options="$OPTARG";
			;;
		h)
			print_usage;
			exit 1;
			;;
		\?)
			echo "Invalid option: $opt";
			print_usage;
			exit 1;
			;;
	esac
done


if [ "$compiler" != "" ] && [ "$toolchain_name" != "" ]; then
	echo "Error: Conflicting options -c and -t specified."
	exit 1;
fi


cmake_flags="-Wdev";

if [ "$build_type" = "none" ]; then
	build_type="";
fi
if [ "$build_type" != "" ]; then
  cmake_flags="$cmake_flags -DCMAKE_BUILD_TYPE=$build_type";
fi

if [ "$generator" != "" ]; then
	cmake_flags="$cmake_flags -G${generator}";
fi


status=1


# Toolchain mode
if [ "$toolchain_name" != "" ]; then
	cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE='${source_dir}/data/cmake/toolchains/${toolchain_name}.cmake'"

	echo "Running:"
	echo "cmake $cmake_flags $source_dir";

	cmake $cmake_flags $cmake_options $source_dir
	status=$?

else  # Compiler mode
	c_compiler="";
	cxx_compiler="";

	# Detect gcc suffix like "-4.7"
	if [ "${compiler:0:4}" = "gcc-" ]; then
		suffix=${compiler:4};
		c_compiler="gcc-${suffix}";
		cxx_compiler="g++-${suffix}";
		compiler="gcc";
	fi

	case $compiler in
		gcc)
			if [ "$c_compiler" = "" ]; then
				c_compiler="gcc${machine_bits_switch}";
				cxx_compiler="g++${machine_bits_switch}";
			fi
			;;
		intel)
			if [ $machine_bits_precise = "64" ]; then
				c_compiler="icc64";
				cxx_compiler="icpc64";
			else
				c_compiler="icc32";
				cxx_compiler="icpc32";
			fi
			;;
		clang)
			c_compiler="clang${machine_bits_switch}";
			cxx_compiler="clang++${machine_bits_switch}";
			;;
		"")
			c_compiler="$CC"
			cxx_compiler="$CXX"
			;;
		*)
			echo "Unsupported compiler given; use CC and CXX instead."
			exit 1;
			;;
	esac

	echo "Running:"
	echo "CC=\"$c_compiler\" CXX=\"$cxx_compiler\" cmake $cmake_flags $source_dir";

	CC="$c_compiler" CXX="$cxx_compiler" cmake $cmake_flags $cmake_options $source_dir
	status=$?
fi


exit $status