forked from memtt/malt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·781 lines (710 loc) · 21.9 KB
/
configure
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
#!/bin/sh
###########################################################
# PROJECT : MALT (MALoc Tracker)
# VERSION : 1.2.4
# DATE : 10/2024
# LICENSE : Apache 2.0
# FILE : configure
#----------------------------------------------------------
# AUTHOR : Sébastien Valat (ECR) - 2014
# AUTHOR : Sébastien Valat - 2018 - 2024
# AUTHOR : Sébastien Valat (INRIA) - 2024
#------------------------- ORIGIN -------------------------
# PROJECT : numaprof
# VERSION : 1.1.2
# DATE : 01/2022
# AUTHOR : Valat Sébastien (CERN) - 2017 - 2018
# LICENSE : Apache 2.0
# URL : https://memtt.github.io/numaprof/
###########################################################
###########################################################
# This script provide a simple wrapper to cmake to fix
# the missing --help equivalent to autotools. And it
# may be more intuitive for users to use the well
# known ./configure & make & make install procedure.
###########################################################
#help debug
#set -e
#set -x
###########################################################
#where to load optinos
CFG_OPTIONS_FILE='options'
#script setup
CFG_PROJECT_NAME="`basename $PWD`"
CFG_DEFAULT_BUILD_TYPE='Release'
CFG_DEFAULT_PREFIX='/usr/local'
#compiler default flags
CFG_EXTRA_CC=''
CFG_EXTRA_CXX=''
CFG_EXTRA_FC=''
CFG_EXTRA_CFLAGS="${CFLAGS}"
CFG_EXTRA_CXXFLAGS="${CXXFLAGS}"
CFG_EXTRA_LDFLAGS="${LDFLAGS}"
CFG_EXTRA_FFLAGS="${FFLAGS}"
# State variables
CFG_CMAKE_COMMAND='cmake'
#help formatting
CFG_HELP_OPT_LENGTH=23
#to be redifined by user if needed
CFG_CUSTOM_HELP=''
#colors
CFG_ENABLE_COLOR="false"
CFG_COLOR_RED="\e[31m"
CFG_COLOR_YELLOW="\e[33m"
CFG_COLOR_CYAN="\e[36m"
CFG_COLOR_RESET="\e[0m"
###########################################################
CFG_TMP='/tmp'
CFG_FEATURES_HELP_FILE="`mktemp ${CFG_TMP}/configure_help_enable_disable.XXXXXXXXXX`"
CFG_WITH_HELP_FILE="`mktemp ${CFG_TMP}/configure_help_with_without.XXXXXXXXXX`"
CFG_CASE_PARSE_OPT_FILE="`mktemp ${CFG_TMP}/configure_case_parse_opt.XXXXXXXXXX`"
CFG_CMAKE_OPTS_FILE="`mktemp ${CFG_TMP}/configure_cmake_opts.XXXXXXXXXX`"
###########################################################
#Find default source dir
CFG_SOURCE_DIR="`dirname \"$0\"`"
###########################################################
#function defining all the options available to configure the project
cfg_setup_options()
{
#add standard one
#debug
cfg_add_enable_option --name='debug' \
--on-enable='-DCMAKE_BUILD_TYPE=Debug' \
--on-disable='-DCMAKE_BUILD_TYPE=Release' \
--doc='Enable debugging support (-DCMAKE_BUILD_TYPE=Debug).'
#debug
cfg_add_enable_option --name='release-debug' \
--on-enable='-DCMAKE_BUILD_TYPE=RelWithDebug' \
--on-disable='-DCMAKE_BUILD_TYPE=Release' \
--doc='Enable debugging support (-DCMAKE_BUILD_TYPE=RelWithDebug).'
#ninja
cfg_add_enable_option --name='ninja' \
--on-enable='-GNinja' \
--doc='Enable usage of Ninja with cmake instead of Make.' \
--only=enable
#load user one
. "${CFG_SOURCE_DIR}/${CFG_OPTIONS_FILE}"
}
###########################################################
#Set project name for help string
# - $1 : project name
cfg_set_projet()
{
CFG_PROJECT_NAME="${1}"
}
###########################################################
cfg_exit()
{
#cat "${CFG_CASE_PARSE_OPT_FILE}"
#cat "${CFG_CMAKE_OPTS_FILE}"
rm -f "${CFG_WITH_HELP_FILE}"
rm -f "${CFG_FEATURES_HELP_FILE}"
rm -f "${CFG_CASE_PARSE_OPT_FILE}"
rm -f "${CFG_CMAKE_OPTS_FILE}"
exit $1
}
###########################################################
cfg_hint()
{
for tmp in "$@"
do
echo "${CFG_COLOR_CYAN}${tmp}${CFG_COLOR_RESET}" 1>&2
done
}
###########################################################
cfg_error()
{
for tmp in "$@"
do
echo "${CFG_COLOR_RED}${tmp}${CFG_COLOR_RESET}" 1>&2
done
}
###########################################################
cfg_fail()
{
for tmp in "$@"
do
echo "${CFG_COLOR_RED}${tmp}${CFG_COLOR_RESET}" 1>&2
done
cfg_exit 1
}
###########################################################
# add value to variable with space as separator
# - $1 : variable name
# - $2 : value to add
cfg_add_to_var()
{
#vars
var="${1}"
value="${2}"
eval "cur=\"\$${var}\""
#concat
if test -z "${cur}"; then
final="${value}"
else
final="${cur} ${value}"
fi
#export
eval "${var}=\"${final}\""
}
###########################################################
#check /tmp
cfg_check_tmp()
{
if ! test -d "${CFG_TMP}"; then
CFG_TMP="./"
fi
}
###########################################################
#Check if colors could be enabled if not piped
cfg_auto_enable_color()
{
#check
if [ -t 1 ]; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
CFG_ENABLE_COLOR='true'
fi
fi
#do
if test "${CFG_ENABLE_COLOR}" = "false"; then
CFG_COLOR_RESET=""
CFG_COLOR_RED=""
CFG_COLOR_YELLOW=""
CFG_COLOR_CYAN=""
fi
}
###########################################################
# Add an --enable-*|--disable-* option to the list of available options.
# The command take a command line like parameters to setup the option :
#
# Params:
# --name={NAME} Provide option name (will be added to --enable-{NAME} and --disable-{NAME})
# --doc={DOC} Provide documentation string for --help
# --on-enable={OPT} Add a cmake option to the option list when --enable-{NAME} is triggered
# --on-disable={OPT} Add a cmake option to the option list when --enable-{NAME} is triggered
# --on={-DVAR=${ON}} Setup the given cmake variable to ON/OFF depending on the enable/disable.
# --on-enable-inherit={} List of inherited configure option to trigger when used.
# --on-disable-inherit={} List of inherited configure option to trigger when used.
# --invert-help In help message, do it for disable instead of enable.
# --only={enable|disable} Provide only one of the two command.
# --custom Call a custom user sh function to handle.
#
# In commands you can use variables :
# ${ON} Will be 'ON' on enable and 'OFF' on disable
# ${OFF} Will be 'OFF' on enable and 'ON' on disable
# ${ENABLE} Will be 'ENABLE' on enable and 'DISABLE' on disable
# ${DISABLE} Will be 'DISABLE' on enable and 'ENABLE' on disable
# ${WITH} Will be 'WITH' on enabled and 'WITHOUT' on disable
# ${WITHOUT} Will be 'WITHOUT' on enabled and 'WITH' on disable
cfg_add_enable_option()
{
#vars
opt_help_mode='enable'
opt_mode='both'
opt_enable=''
opt_disable=''
#scan options
for opt in "$@"
do
#extract
v=`echo $opt | cut -f 2- -d =`
#case
case $opt in
--name=*)
opt_name="${v}"
;;
--doc=*)
opt_doc="${v}"
;;
--custom=*)
on_enable="${v}"
on_disable="${v}"
;;
--on-enable=*)
opt_enable="cfg_push_cmake_opt \"${v}\""
;;
--on-disable=*)
opt_disable="cfg_push_cmake_opt \"${v}\""
;;
--on=*)
opt_enable="cfg_push_cmake_opt \"${v}\""
opt_disable="cfg_push_cmake_opt \"${v}\""
;;
--on-enable-inherit=*)
opt_enable="cfg_parse_global_args ${v}"
;;
--on-disable-inherit=*)
opt_disable="cfg_parse_global_args ${v}"
;;
--invert-help)
opt_help_mode='disable'
;;
--only=enable|--only=disable)
opt_help_mode="${v}"
opt_mode="${v}"
;;
*)
cfg_fail "Invalid internal option to build enable option ${opt} while calling cfg_add_enable_option()"
;;
esac
done
#generate doc
printf " --%-${CFG_HELP_OPT_LENGTH}s %s\n" "${opt_help_mode}-${opt_name}" "${opt_doc}" >> ${CFG_FEATURES_HELP_FILE}
#generate enable action
if test ! -z "${opt_enable}"; then
if test "${opt_mode}" = "both" || test "${opt_mode}" = "enable"; then
echo " --enable-${opt_name})" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ${opt_enable}" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ;;" >> ${CFG_CASE_PARSE_OPT_FILE}
fi
fi
#generate disable action
if test ! -z "${opt_disable}"; then
if test "${opt_mode}" = "both" || test "${opt_mode}" = "disable"; then
echo " --disable-${opt_name})" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ${opt_disable}" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ;;" >> ${CFG_CASE_PARSE_OPT_FILE}
fi
fi
}
###########################################################
# Add an --with-*|--without-* option to the list of available options.
# The command take a command line like parameters to setup the option :
#
# Params:
# --name={NAME} Provide option name (will be added to --with-{NAME} and --without-{NAME})
# --doc={DOC} Provide documentation string for --help
# --on-with={OPT} Add a cmake option to the option list when --with-{NAME} is triggered
# --on-without={OPT} Add a cmake option to the option list when --without-{NAME} is triggered
# --on={-DVAR=${ON}} Setup the given cmake variable to ON/OFF depending on the with/without
# --on-with-inherit={} List of inherited configure option to trigger when used
# --on-without-inherit={} List of inherited configure option to trigger when used
# --invert-help In help message, do it for disable instead of enable
# --only={with|without} Provide only one of the two command
# --var={var} Cmake variable to setup
# --custom Call a custom user sh function to handle
# --type={value} In help which type of value we wait on with mode
# --enum={a|b|cz} List authozied values
# --allow-no-value Will consider call with ${val}='ON' if with-X is provided without value.
#
# In commands you can use variables :
# ${ON} Will be 'ON' on enable and 'OFF' on disable
# ${OFF} Will be 'OFF' on enable and 'ON' on disable
# ${ENABLE} Will be 'ENABLE' on enable and 'DISABLE' on disable
# ${DISABLE} Will be 'DISABLE' on enable and 'ENABLE' on disable
# ${WITH} Will be 'WITH' on enabled and 'WITHOUT' on disable
# ${WITHOUT} Will be 'WITHOUT' on enabled and 'WITH' on disable
cfg_add_with_option()
{
#vars
opt_help_mode='with'
opt_mode='both'
opt_with=''
opt_without=''
opt_type='path'
opt_enum=''
opt_no_value='false'
#scan options
for opt in "$@"
do
#extract
v=`echo $opt | cut -f 2- -d =`
#case
case $opt in
--name=*)
opt_name="${v}"
;;
--doc=*)
opt_doc="${v}"
;;
--var=*)
opt_with="cfg_push_cmake_opt \"-D${v}=\${val}\""
opt_without="cfg_push_cmake_opt -D${v}=OFF"
;;
--custom=*)
on_with="${v}"
on_without="${v}"
;;
--on-with=*)
opt_with="cfg_push_cmake_opt \"${v}\""
;;
--on-without=*)
opt_without="cfg_push_cmake_opt \"${v}\""
;;
--on=*)
opt_with="cfg_push_cmake_opt \"${v}\""
opt_without="cfg_push_cmake_opt \"${v}\""
;;
--on-with-inherit=*)
opt_with="cfg_parse_global_args ${v}"
;;
--on-without-inherit=*)
opt_without="cfg_parse_global_args ${v}"
;;
--invert-help)
opt_help_mode='without'
;;
--only=with|--only=without)
opt_help_mode="${v}"
opt_mode="${v}"
;;
--type=*)
opt_type="${v}"
;;
--enum=*)
opt_enum="${v}"
;;
--allow-no-value)
opt_no_value='true'
;;
*)
cfg_fail "Invalid internal option to build with/without option ${opt} while calling cfg_add_with_option()"
;;
esac
done
#generate doc
printf " --%-${CFG_HELP_OPT_LENGTH}s %s\n" "${opt_help_mode}-${opt_name}={${opt_type}}" "${opt_doc}" >> ${CFG_WITH_HELP_FILE}
#generate with action
if test ! -z "${opt_with}"; then
if test "${opt_mode}" = "both" || test "${opt_mode}" = "with"; then
#no value case
if test "${opt_no_value}" = 'true'; then
echo " --with-${opt_name})" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " val='ON'" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ${opt_with}" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ;;" >> ${CFG_CASE_PARSE_OPT_FILE}
fi
#value case
if test -z "${opt_enum}"; then
#std case
echo " --with-${opt_name}=*)" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ${opt_with}" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ;;" >> ${CFG_CASE_PARSE_OPT_FILE}
else
#make selection for each value of enum
for entry in `echo ${opt_enum} | sed -e 's/[|]/ /g'`; do
echo " --with-${opt_name}=${entry})" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ${opt_with}" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ;;" >> ${CFG_CASE_PARSE_OPT_FILE}
done
fi
fi
fi
#generate without action
if test ! -z "${opt_without}"; then
if test "${opt_mode}" = "both" || test "${opt_mode}" = "without"; then
echo " --without-${opt_name})" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ${opt_without}" >> ${CFG_CASE_PARSE_OPT_FILE}
echo " ;;" >> ${CFG_CASE_PARSE_OPT_FILE}
fi
fi
}
###########################################################
CFG_PARSE_OPT_HEADER="#!/bin/sh
cfg_parse_user_opts()
{
for user_opt in \"\$@\"
do
case \$user_opt in"
CFG_PARSE_OPT_FOOTER="
*)
return 1
;;
esac
done
}
"
###########################################################
cfg_gen_help_string()
{
#add lines
if ! test -z "${CFG_CUSTOM_HELP}"; then
line="\n"
else
line=""
fi
#gen message
CFG_HELP_MESSAGE="'configure' is a cmake wrapper to build ${CFG_PROJECT_NAME}
For more control, prefer to use cmake directely, this wrapper only aims
to ease your life for standard cases.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--srcdir=DIR find the sources in DIR [configure dir or '${CFG_SOURCE_DIR}']
Installation directories:
--prefix=PREFIX install files in PREFIX [${CFG_DEFAULT_PREFIX}]
--lib-suffix=SUFFIX used to force suffix for lib directory eg. lib64. [empty].
By default, 'make install' will install all the files in
'/usr/local/bin', '/usr/local/lib' etc. You can specify
an installation prefix other than '/usr/local' using '--prefix',
for instance '--prefix=$HOME/usr'.
Optional Features:
`cat ${CFG_FEATURES_HELP_FILE}`
To find libs and commands :
--with-cmake={command} Define the cmake command to use [cmake].
`cat ${CFG_WITH_HELP_FILE}`
To get the generated cmake command :
--show Display the cmake command and didn't execute it.
${line}${CFG_CUSTOM_HELP}${line}
Extra cmake option:
-D{VARNAME}={VALUE} Transmit direct cmake options in cmake format.
Some influential environment variables:
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
CC C compiler command
CFLAGS C compiler flags
CXX C++ compiler command
CXXFLAGS C++ compiler flags
FC Fortran compiler
FFLAGS Fortran compiler flags"
}
###########################################################
cfg_push_cmake_opt()
{
echo "$@" >> ${CFG_CMAKE_OPTS_FILE}
}
###########################################################
#parse arguments
cfg_parse_global_args()
{
for arg in "$@"
do
#extract
val="`echo \"$arg\" | cut -f 2- -d =`"
case "$arg" in
--enable-*)
ON='ON'
OFF='OFF'
WITH='WITH'
WITHOUT='WITHOUT'
;;
--disable-*)
ON='OFF'
OFF='ON'
WITH='WITHOUT'
WITHOUT='WITH'
;;
--with-*)
ON='ON'
OFF='OFF'
WITH='WITH'
WITHOUT='WITHOUT'
;;
--without-*)
ON='OFF'
OFF='ON'
WITH='WITHOUT'
WITHOUT='WITH'
;;
esac
#loop on args
case "$arg" in
-h | --help)
echo "$CFG_HELP_MESSAGE"
cfg_exit 0
;;
--prefix=*)
cfg_push_cmake_opt "-DCMAKE_INSTALL_PREFIX=${val}"
;;
--srcdir=*)
SOURCE_DIR="${val}"
;;
--with-cmake=*)
CFG_CMAKE_COMMAND="${val}"
;;
--show)
ENABLE_DISPLAY_COMMAND='true'
;;
-D*)
cfg_push_cmake_opt "${arg}"
;;
CC=*)
CFG_EXTRA_CC="${val}"
;;
FC=*)
CFG_EXTRA_FC="${val}"
;;
CXX=*)
CFG_EXTRA_CXX="${val}"
;;
CFLAGS=*)
cfg_add_to_var CFG_EXTRA_CFLAGS "${val}"
;;
CXXFLAGS=*)
cfg_add_to_var CFG_EXTRA_CXXFLAGS "${val}"
;;
FFLAGS=*)
cfg_add_to_var CFG_EXTRA_FFLAGS "${val}"
;;
LDFLAGS=*)
cfg_add_to_var CFG_EXTRA_LDFLAGS "${val}"
;;
*)
cfg_parse_user_opts "${arg}" || cfg_parse_custom_opts "${arg}" || cfg_fail "Invalid argument : ${arg}, please check in --help."
;;
esac
done
}
###########################################################
cfg_push_defaults()
{
cfg_push_cmake_opt "-DCMAKE_INSTALL_PREFIX=${CFG_DEFAULT_PREFIX}"
cfg_push_cmake_opt "-DCMAKE_BUILD_TYPE=${CFG_DEFAULT_BUILD_TYPE}"
}
###########################################################
# emulate tac in a portable way with awk
cfg_portable_tac()
{
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }'
}
###########################################################
# clean options by removing double definitions and keep only the
# last one. To proceed we reverse the file and keep definition
# only if not already seen
# - $1 : File to clean
cfg_remove_dup()
{
#vars
file="${1}"
tmpfile="${file}.tmp"
#prep
touch "${tmpfile}"
#loop on reversed file
cat "${file}" | cfg_portable_tac | while read line
do
var=$(echo "${line}" | cut -f 1 -d =)
#check if not already seen
if ! egrep -q "^${var}=" "${tmpfile}" ; then
echo "${line}" >> "${tmpfile}"
fi
done
#reverback the file and replace orig
cat "${tmpfile}" | cfg_portable_tac > "${file}"
}
###########################################################
# Gen final command
# - $1 : true of false to enable or disable args quote protection
cfg_gen_final_command_lines()
{
#set protection
quote=''
if test "${1}" = "true"; then
quote="\""
fi
#protect all and output
result=""
while read line; do
result="${result} ${quote}${line}${quote}"
done < "${CFG_CMAKE_OPTS_FILE}"
# final
echo "${result} ${CFG_SOURCE_DIR}"
}
###########################################################
# custom pre check function to be replaced by user function
# to perform some checks
# All cmake -DVAR will be loaded into shell script by
# being named prefixed by 'OPT_', eg OPT_CMAKE_C_COMPILER
cfg_custom_pre_check()
{
return 0
}
###########################################################
# custom option parse to be replaced by user function
# in setup file
# here we can parse our own options if we want
# Vars available are :
# - $arg : full argument (eg. --with-gcc=gcc)
# - $val : value after first '=', egg 'gcc'
# - $ON $OFF, $ENABLE, $DISABLE, $WIDTH, $WITHOUT
cfg_parse_custom_opts()
{
return 1
}
###########################################################
# load vars into shell script to we can performe some
# extra checking actions into the cfg_custom_pre_check function
# which can be overloaded by project options.
cfg_load_vars()
{
while read fline; do
case "${fline}" in
-D*)
load_val=`echo "${fline}" | cut -f 2- -d =`
load_var=`echo "${fline}" | cut -f 1 -d = | sed -e 's/^-D//'`
eval "${load_var}=\"${load_val}\""
;;
*)
cfg_fail "Unrecognized definition : ${fline}"
;;
esac
done < "${CFG_CMAKE_OPTS_FILE}"
}
###########################################################
#setup colors and check tmp
cfg_check_tmp
cfg_auto_enable_color
###########################################################
#build configuration
echo "${CFG_PARSE_OPT_HEADER}" > ${CFG_CASE_PARSE_OPT_FILE}
cfg_setup_options
echo "${CFG_PARSE_OPT_FOOTER}" >> ${CFG_CASE_PARSE_OPT_FILE}
#load the generated swtich case to parse user args
. ${CFG_CASE_PARSE_OPT_FILE}
#gen help
cfg_gen_help_string
###########################################################
#push defults
cfg_push_defaults
#parse
cfg_parse_global_args "$@"
#clean
cfg_remove_dup "${CFG_CMAKE_OPTS_FILE}"
#load and check
cfg_load_vars
cfg_custom_pre_check
###########################################################
#Check current directory
if [ -f 'CMakeLists.txt' ] && [ -f 'configure' ]; then
cfg_fail "ERROR : CMake isn't adapted to support build directely in source"
"directory. Prefer to create a subdirectory to build."
""
"Example : mkdir build && cd build && ../configure"
fi
###########################################################
#Gen CC/CXX/LDFLAGS commands
if [ ! -z "$CFG_EXTRA_CC" ]; then cfg_push_cmake_opt "-DCMAKE_C_COMPILER=${CFG_EXTRA_CC}" ; fi
if [ ! -z "$CFG_EXTRA_CFLAGS" ]; then cfg_push_cmake_opt "-DCMAKE_C_FLAGS=${CFG_EXTRA_CFLAGS}" ; fi
if [ ! -z "$CFG_EXTRA_CXX" ]; then cfg_push_cmake_opt "-DCMAKE_CXX_COMPILER=${CFG_EXTRA_CXX}" ; fi
if [ ! -z "$CFG_EXTRA_CXXFLAGS" ]; then cfg_push_cmake_opt "-DCMAKE_CXX_FLAGS=${CFG_EXTRA_CXXFLAGS}" ; fi
if [ ! -z "$CFG_EXTRA_FFLAGS" ]; then cfg_push_cmake_opt "-DCMAKE_Fortran_FLAGS=${CFG_EXTRA_FFLAGS}" ; fi
if [ ! -z "$CFG_EXTRA_LDFLAGS" ]; then cfg_push_cmake_opt "-DCMAKE_EXE_LINKER_FLAGS=${CFG_EXTRA_LDFLAGS}" ; fi
if [ ! -z "$CFG_EXTRA_LDFLAGS" ]; then cfg_push_cmake_opt "-DCMAKE_SHARED_LINKER_FLAGS=${CFG_EXTRA_LDFLAGS}" ; fi
if [ ! -z "$CFG_EXTRA_LDFLAGS" ]; then cfg_push_cmake_opt "-DCMAKE_STATIC_LINKER_FLAGS=${CFG_EXTRA_LDFLAGS}" ; fi
if [ ! -z "$CFG_EXTRA_FC" ]; then cfg_push_cmake_opt "-DCMAKE_Fortran_COMPILER=${CFG_EXTRA_FC}" ; fi
###########################################################
#execute or display
if [ "${ENABLE_DISPLAY_COMMAND}" = 'true' ]; then
# display raw
echo "${CFG_CMAKE_COMMAND} `cfg_gen_final_command_lines true`"
# status
cfg_exit 0
else
# display in yellow (if color is enabled)
printf "${CFG_COLOR_YELLOW}"
echo ">>> ${CFG_CMAKE_COMMAND} `cfg_gen_final_command_lines true`"
printf "${CFG_COLOR_RESET}"
# dump in log
echo "----------- $(date) --------------" >> configure.log
echo >> configure.log
echo "$0 $@" >> configure.log
echo ">>> ${CFG_CMAKE_COMMAND} `cfg_gen_final_command_lines true`" >> configure.log
echo >> configure.log
# execute
eval "${CFG_CMAKE_COMMAND}" `cfg_gen_final_command_lines true`
# status
cfg_exit $?
fi