-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cmd
executable file
·1514 lines (1153 loc) · 40.6 KB
/
build.cmd
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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@if defined TRACEON (@echo on) else (@echo off)
REM If this batch file works, then it was written by Fish.
REM If it doesn't then I don't know who the heck wrote it.
setlocal
pushd .
set "_versnum=2.3"
set "_versdate=April 2, 2019"
goto :init
::-----------------------------------------------------------------------------
:: BUILD.CMD
::-----------------------------------------------------------------------------
:help
echo.
echo NAME
echo.
echo %nx0% -- Builds and installs a Hercules external package
echo.
echo SYNOPSIS
echo.
echo %nx0% [ { -d ^| --pkgdir } [ pkgdir ] ]
echo [ { -n ^| --pkgname } [ pkgname ] ]
echo [ { -m ^| --cpu } { arch } ]
echo [ { -a ^| --arch } { 64 ^| 32 ^| BOTH } ]
echo [ { -c ^| --config } { Release ^| Debug ^| BOTH } ]
echo [ { -all ^| --all } ]
echo [ { -r ^| --rebuild } ]
echo [ { -i ^| --install } [ instdir ] ]
echo [ { -u ^| --uninstall } [ uinstdir ] ]
echo [ { -f ^| --force }
echo.
echo ARGUMENTS
echo.
echo pkgdir The package directory where the CMakeLists.txt
echo file exists. This is usually the name of the
echo package's primary source directory ^(i.e. its
echo repository directory^). The default when not
echo specified is the same one as where %nx0%
echo is running from.
echo.
echo pkgname The single word alphanumeric package name. The
echo default if not specified is derived from the last
echo directory component of pkgdir. The value "." may
echo be specified to derive from the last component of
echo the current directory instead.
echo.
echo cpu The machine (CPU) architecture of the target system
echo if other than x86. Recognized machine architectures
echo are: aarch, arm, mips, ppc, sparc, xscale, s390x, x86
echo and unknown. The default if not specified is x86.
echo.
echo arch The build architecture. Use '32' to build an x86
echo 32-bit version of the package. Use '64' to build
echo an x64 64-bit version of the package. Use 'BOTH'
echo to build both architectures. The default is 64.
echo.
echo config The build configuration. Specify 'Debug' to build
echo an unoptimized debug version of the product. Use
echo Release to build an optimized version ^(which also
echo has debugging symbols). The default is Release.
echo.
echo install Install the package into the specified directory.
echo If not specified the package will not be installed.
echo.
echo instdir The package installation directory. If specified
echo the given directory MUST exist. If not specified
echo the directory specified in a previous run is used
echo if such is possible. Otherwise the package CMake
echo default installation directory is used instead.
echo.
echo uninstall Uninstall the package from the specified directory.
echo.
echo uinstdir The directory where the package was installed. If
echo specified without the force option, the value MUST
echo match the install directory used in a previous run.
echo If not specified, then the install directory from
echo the previous run is retrieved from the CMake cache
echo and used instead. If the directory isn't found in
echo CMake's cache the package default install directory
echo is used instead. The directory MUST exist.
echo.
echo OPTIONS
echo.
echo all Shorthand for "--arch BOTH --config BOTH".
echo.
echo rebuild Forces a complete CMake reconfigure and rebuild.
echo.
echo force Overrides CMake's cached install directory used in
echo a previous run and forces the uninstall to use the
echo specified directory instead. It effectively forces
echo a complete CMake reconfigure just like the rebuild
echo option does but is used exclusively for uninstalls.
echo.
echo NOTES
echo.
echo %nx0% first creates a build directory in the current directory,
echo switches to the build directory, runs vstools.cmd ^(to initialize
echo the proper build environment^) followed by the cmake command ^(to
echo create the makefile^) and then finally runs nmake and nmake install
echo commands to actually build and install the package for the specified
echo architecture and configuration combination. The name of the binary
echo build directory is derived from the package's name and the specified
echo cpu/architetcure/configuration combination. The vstools.cmd batch
echo file is presumed to exist in the same directory as %nx0%.
echo.
echo EXIT STATUS
echo.
echo 0 All requested actions successfully completed.
echo n One or more actions failed w/error^(s^) where 'n' is the
echo highest return code detected.
echo.
echo AUTHOR
echo.
echo "Fish" ^(David B. Trout^)
echo.
echo VERSION
echo.
echo %_versnum% ^(%_versdate%^)
call :setrc1
%exit%
::-----------------------------------------------------------------------------
:: INIT
::-----------------------------------------------------------------------------
:init
@REM Define some constants...
set "TRACE=if defined DEBUG echo"
set "return=goto :EOF"
set "break=goto :break"
set "skip=goto :skip"
set "exit=goto :exit"
set "help=goto :help"
set "numbers=0123456789"
set "letters=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
set /a "rc=0"
set /a "maxrc=0"
set "n0=%~n0" && @REM (our name only)
set "nx0=%~nx0" && @REM (our name and extension)
set "dp0=%~dp0" && @REM (our own drive and path only)
set "dp0=%dp0:~0,-1%" && @REM (remove trailing backslash)
set "nx0_cmdline=%0 %*" && @REM (save original cmdline used)
@REM Define external tools
set "cmake=cmake.exe"
set "vstools=%dp0%\vstools.cmd"
set "JOM=jom.exe" && @REM (optional tool)
@REM Options as listed in help...
set "pkgdir="
set "pkgname="
set "install="
set "instdir="
set "uninstall="
set "uinstdir="
set "arch="
set "config="
set "rebuild="
set "force="
set "bldall="
set "cpu="
@REM Default values...
set "def_pkgdir=%dp0%"
set "def_arch=64"
set "def_config=Release"
goto :parse_args
::-----------------------------------------------------------------------------
:: load_tools
::-----------------------------------------------------------------------------
:load_tools
call :fullpath "%cmake%"
if not defined # (
call :errmsg %cmake% not found.
set "cmake="
)
call :fullpath "%vstools%" vstools
if not defined # (
call :errmsg %vstools% not found.
set "vstools="
)
:: PROGRAMMING NOTE: Qt JOM is optional. We'll use it if we find it,
:: but not finding it isn't considered to be a fatal error. Instead,
:: we simply use Microsoft's nmake tool like normal. JOM is a clone
:: of nmake to support the execution of multiple independent commands
:: in parallel. It basically adds the -j command line switch similar
:: to GNU make allowing makefile projects using JOM instead of nmake
:: to build much faster by using multiple parallel threads instead.
call :fullpath "%JOM%" JOM
if not defined # (
set "JOM="
%return%
)
for /f "tokens=1-3" %%a in ('"%JOM%" /VERSION') do (
set "JOM_version=%%c"
)
echo Using JOM version %JOM_version%
%return%
::-----------------------------------------------------------------------------
:: fullpath
::-----------------------------------------------------------------------------
:fullpath
set "@=%path%"
set "path=.;%path%"
set "#=%~$PATH:1"
set "path=%@%"
if defined # (
if not "%~2" == "" (
set "%~2=%#%"
)
)
%return%
::-----------------------------------------------------------------------------
:: isfile
::-----------------------------------------------------------------------------
:isfile
if not exist "%~1" (
set "isfile="
%return%
)
set "isfile=%~a1"
if defined isfile (
if /i "%isfile:~0,1%" == "d" set "isfile="
)
%return%
::-----------------------------------------------------------------------------
:: isdir
::-----------------------------------------------------------------------------
:isdir
if not exist "%~1" (
set "isdir="
%return%
)
set "isdir=%~a1"
if defined isdir (
if /i not "%isdir:~0,1%" == "d" set "isdir="
)
%return%
::-----------------------------------------------------------------------------
:: tempfn
::-----------------------------------------------------------------------------
:tempfn
setlocal
set "var_name=%~1"
set "file_ext=%~2"
set "%var_name%="
set "@="
for /f "delims=/ tokens=1-3" %%a in ("%date:~4%") do (
for /f "delims=:. tokens=1-4" %%d in ("%time: =0%") do (
set "@=TMP%%c%%a%%b%%d%%e%%f%%g%random%%file_ext%"
)
)
endlocal && set "%var_name%=%@%"
%return%
::-----------------------------------------------------------------------------
:: dirname
::-----------------------------------------------------------------------------
:dirname
set "dirname=%~nx1" && @REM (get just the final directory name component)
%return%
::-----------------------------------------------------------------------------
:: normalize_dir
::-----------------------------------------------------------------------------
:normalize_dir
if "%~2" == "" %return%
setlocal
set "var_name=%~1"
set "var_value=%~2"
:: Normalize path separator
:: Remove trailing separator
set "norm_val=%var_value:/=\%"
if "%norm_val:~-1%" == "\" (
set "norm_val=%norm_val:~0,-1%"
)
endlocal && set "%var_name%=%norm_val%"
%return%
::-----------------------------------------------------------------------------
:: is_valid_dir
::-----------------------------------------------------------------------------
:is_valid_dir
@REM Return value 'is_valid_dir' defined if valid, otherwise undefined.
@REM Passed variable will ALWAYS be updated (normalized) REGARDLESS of
@REM whether it is determined to be valid or not.
@REM Use quiet option to preserve rc/maxrc value if only interested in
@REM the 'is_valid_dir' return value. Otherwise an error message will
@REM be issued and 'rc' & 'maxrc' will be updated if directory invalid.
setlocal
set "is_valid_dir=1"
set "var_name=%~1"
set "var_value=%~2"
set "quiet=%~3"
call :normalize_dir norm_val "%var_value%"
call :fullpath "%norm_val%"
if not defined # (
set "is_valid_dir="
if not defined quiet (
call :errmsg %var_name% "%var_value%" not found.
)
goto :is_valid_dir_ret
)
set "norm_val=%#%"
call :isdir "%norm_val%"
if not defined isdir (
set "is_valid_dir="
if not defined quiet (
call :errmsg %var_name% "%var_value%" is not a directory.
)
)
:is_valid_dir_ret
if defined quiet (
endlocal && set "is_valid_dir=%is_valid_dir%" && set "%var_name%=%norm_val%"
) else (
endlocal && set "is_valid_dir=%is_valid_dir%" && set "%var_name%=%norm_val%" && set "rc=%rc%" && set "maxrc=%maxrc%"
)
%return%
::-----------------------------------------------------------------------------
:: isalphanum
::-----------------------------------------------------------------------------
:isalphanum
set "@=%~1"
set "isalphanum="
if not "%@%" == "" (
for /f "delims=%numbers%%letters%" %%i in ("%@%/") do (
if "%%i" == "/" set "isalphanum=1"
)
)
:: (ensure first char is letter not number)
set "@=%@:~0,1%"
if defined isalphanum (
for /f "delims=%letters%" %%i in ("%@%/") do (
if not "%%i" == "/" set "isalphanum="
)
)
%return%
::-----------------------------------------------------------------------------
:: get_cache_value
::-----------------------------------------------------------------------------
:get_cache_value
setlocal
set "_cachefile=%~1"
set "_varname=%~2"
set "cache_value=" && @REM (the value we will be returning_
if not exist "%_cachefile%" (
goto :get_cache_value_ret
)
for /f "tokens=*" %%a in (%_cachefile%) do (
call :cache_stmt "%%a"
if defined cache_value (
goto :get_cache_value_ret
)
)
:get_cache_value_ret
endlocal && set "cache_value=%cache_value%"
%return%
:cache_stmt
set "stmt=%~1"
for /f "tokens=1-2* delims=:=" %%a in ("%stmt%") do (
if /i "%%a" == "%_varname%" (
set "cache_value=%%c"
%return%
)
)
%return%
::-----------------------------------------------------------------------------
:: ( parse_options_loop helper )
::-----------------------------------------------------------------------------
:isopt
@REM Examines first character of passed value to determine
@REM whether it's the next option or not. If it starts with
@REM a '/' or '-' then it's the next option. Else it's not.
set "isopt=%~1"
if not defined isopt %return%
if "%isopt:~0,1%" == "/" %return%
if "%isopt:~0,1%" == "-" %return%
set "isopt="
%return%
::-----------------------------------------------------------------------------
:: ( parse_options_loop helper )
::-----------------------------------------------------------------------------
:parseopt
@REM This function expects the next two command line arguments
@REM %1 and %2 to be passed to it. %1 is expected to be a true
@REM option (its first character should start with a / or -).
@REM
@REM Both arguments are then examined and the results are placed into
@REM the following variables:
@REM
@REM opt: The current option as-is (e.g. "-d")
@REM
@REM optname: Just the characters following the '-' (e.g. "d")
@REM
@REM optval: The next token following the option (i.e. %2),
@REM but only if it's not an option itself (not isopt).
@REM Otherwise optval is set to empty/undefined since
@REM it is not actually an option value but is instead
@REM the next option.
set "opt=%~1"
set "optname=%opt:~1%"
set "optval=%~2"
setlocal
call :isopt "%optval%"
endlocal && set "#=%isopt%"
if defined # set "optval="
%return%
::-----------------------------------------------------------------------------
:: parse_args
::-----------------------------------------------------------------------------
:parse_args
set /a "rc=0"
if /i "%~1" == "?" %help%
if /i "%~1" == "/?" %help%
if /i "%~1" == "-?" %help%
if /i "%~1" == "-h" %help%
if /i "%~1" == "--help" %help%
call :load_tools
if %rc% NEQ 0 %exit%
:parse_options_loop
if "%~1" == "" goto :options_loop_end
@REM Parse next option...
set "cmdline_arg=%~1"
call :isopt "%~1"
call :parseopt "%~1" "%~2"
shift /1
if not defined isopt (
@REM Must be a positional option.
@REM Set optname identical to opt
@REM and empty meaningless optval.
set "optname=%opt%"
set "optval="
goto :parse_positional_arg
)
if /i "%optname%" == "?" goto :parse_help_opt
if /i "%optname%" == "h" goto :parse_help_opt
if /i "%optname%" == "d" goto :parse_pkgdir_opt
if /i "%optname%" == "n" goto :parse_pkgname_opt
if /i "%optname%" == "i" goto :parse_install_opt
if /i "%optname%" == "u" goto :parse_uninstall_opt
if /i "%optname%" == "a" goto :parse_arch_opt
if /i "%optname%" == "c" goto :parse_config_opt
if /i "%optname%" == "r" goto :parse_rebuild_opt
if /i "%optname%" == "f" goto :parse_force_opt
if /i "%optname%" == "all" goto :parse_all_opt
if /i "%optname%" == "m" goto :parse_cpu_opt
@REM Determine if "--xxxx" long option
call :isopt "%optname%"
if not defined isopt goto :parse_unknown_opt
@REM Long "--xxxxx" option parsing...
@REM We use %~1 here (instead of %~2)
@REM since shift /1 was already done.
call :parseopt "%optname%" "%~1"
if /i "%optname%" == "help" goto :parse_help_opt
if /i "%optname%" == "pkgdir" goto :parse_pkgdir_opt
if /i "%optname%" == "pkgname" goto :parse_pkgname_opt
if /i "%optname%" == "install" goto :parse_install_opt
if /i "%optname%" == "uninstall" goto :parse_uninstall_opt
if /i "%optname%" == "arch" goto :parse_arch_opt
if /i "%optname%" == "config" goto :parse_config_opt
if /i "%optname%" == "rebuild" goto :parse_rebuild_opt
if /i "%optname%" == "force" goto :parse_force_opt
if /i "%optname%" == "all" goto :parse_all_opt
if /i "%optname%" == "cpu" goto :parse_cpu_opt
if /i "%optname%" == "version" goto :parse_version_opt
goto :parse_unknown_opt
@REM ------------------------------------
@REM Options that require an argument
@REM ------------------------------------
:parse_pkgdir_opt
if not defined optval goto :parse_missing_optarg
set "pkgdir=%optval%"
shift /1
goto :parse_options_loop
:parse_pkgname_opt
if not defined optval goto :parse_missing_optarg
set "pkgname=%optval%"
shift /1
goto :parse_options_loop
:parse_arch_opt
if not defined optval goto :parse_missing_optarg
set "arch=%optval%"
shift /1
goto :parse_options_loop
:parse_config_opt
if not defined optval goto :parse_missing_optarg
set "config=%optval%"
shift /1
goto :parse_options_loop
:parse_cpu_opt
if not defined optval goto :parse_missing_optarg
set "cpu=%optval%"
shift /1
goto :parse_options_loop
@REM ------------------------------------
@REM Options whose argument is optional
@REM ------------------------------------
:parse_install_opt
set "install=1"
if not defined optval goto :parse_options_loop
set "instdir=%optval%"
shift /1
goto :parse_options_loop
:parse_uninstall_opt
set "uninstall=1"
if not defined optval goto :parse_options_loop
set "uinstdir=%optval%"
shift /1
goto :parse_options_loop
@REM ------------------------------------
@REM Options that are just switches
@REM ------------------------------------
:parse_help_opt
%help%
goto :parse_options_loop
:parse_rebuild_opt
set "rebuild=1"
goto :parse_options_loop
:parse_force_opt
set "force=1"
goto :parse_options_loop
:parse_all_opt
set "bldall=1"
goto :parse_options_loop
:parse_version_opt
echo %nx0% version %_versnum% ^(%_versdate%^) 1>&2
call :setrc1
goto :parse_options_loop
@REM ------------------------------------
@REM Positional arguments
@REM ------------------------------------
:parse_positional_arg
:: We do not have any positional arguments
goto :parse_unknown_arg
@REM ------------------------------------
@REM Error routines
@REM ------------------------------------
:parse_unknown_arg
call :errmsg Unrecognized/extraneous argument '%cmdline_arg%'.
goto :parse_options_loop
:parse_unknown_opt
call :errmsg Unknown/unsupported option '%cmdline_arg%'.
goto :parse_options_loop
:parse_missing_optarg
call :errmsg Option '%cmdline_arg%' is missing its required argument.
goto :parse_options_loop
:options_loop_end
%TRACE% Debug: values after parsing:
%TRACE%.
%TRACE% pkgdir = "%pkgdir%"
%TRACE% pkgname = "%pkgname%"
%TRACE% install = "%install%"
%TRACE% instdir = "%instdir%"
%TRACE% uninstall = "%uninstall%"
%TRACE% uinstdir = "%uinstdir%"
%TRACE% cpu = "%cpu%"
%TRACE% arch = "%arch%"
%TRACE% config = "%config%"
%TRACE% rebuild = "%rebuild%"
%TRACE% force = "%force%"
%TRACE% bldall = "%bldall%"
%TRACE%.
if %rc% NEQ 0 %exit%
goto :validate_args
::-----------------------------------------------------------------------------
:: validate_args
::-----------------------------------------------------------------------------
:validate_args
if not defined pkgdir (
set "pkgdir=%def_pkgdir%"
)
call :is_valid_dir pkgdir "%pkgdir%"
if %rc% NEQ 0 (
@REM error message already issued
goto :validate_pkgname
)
pushd "%pkgdir%"
call :fullpath "CMakeLists.txt"
popd
if not defined # (
call :errmsg File "CMakeLists.txt" not found in pkgdir.
goto :validate_pkgname
)
goto :validate_pkgname
::-----------------------------------------------------------------------------
:validate_pkgname
if "%pkgname%" == "." (
goto :validate_dot_pkgname
)
if defined pkgname (
goto :validate_specified_pkgname
)
:: Derive pkgname from pkgdir value
call :dirname "%pkgdir%"
set "pkgname=%dirname%"
goto :validate_derived_pkgname
:validate_dot_pkgname
:: Derive pkgname from current directory name
call :dirname "%cd%"
set "pkgname=%dirname%"
goto :validate_derived_pkgname
:validate_derived_pkgname
set "_pkgname=%pkgname%"
set "pkgname="
:: The following loop constructs a pkgname value
:: by skipping all non-alphanumeric characters
:: and ensuring the first character is a letter.
:validate_derived_pkgname_loop
if not defined _pkgname (
@REM We're done. Go validate our results.
goto :validate_specified_pkgname
)
:: Grab the next character from _pgkname...
set "@=%_pkgname:~0,1%"
set "_pkgname=%_pkgname:~1%"
for /f "delims=%numbers%%letters%" %%i in ("%@%/") do (
if "%%i" == "/" call :validate_derived_pkgname_append_sub
goto :validate_derived_pkgname_loop
)
:validate_derived_pkgname_append_sub
set "pkgname=%pkgname%%@%"
%return%
:validate_specified_pkgname
call :isalphanum "%pkgname%"
if not defined isalphanum (
call :errmsg Invalid pkgname "%pkgname%".
goto :validate_instdir
)
goto :validate_instdir
::-----------------------------------------------------------------------------
:validate_instdir
if defined instdir (
call :is_valid_dir instdir "%instdir%"
)
goto :validate_uinstdir
::-----------------------------------------------------------------------------
:validate_uinstdir
if defined uinstdir (
call :is_valid_dir uinstdir "%uinstdir%"
)
goto :validate_build
::-----------------------------------------------------------------------------
:validate_build
:: Ignore specified arch and config values if bldall was specified
if defined bldall (
if defined arch (
if /i not "%arch%" == "BOTH" (
echo WARNING: arch ignored due to 'all' option. 1>&2
)
set "arch="
)
if defined config (
if /i not "%config%" == "BOTH" (
echo WARNING: config ignored due to 'all' option. 1>&2
)
set "config="
)
) else (
if not defined arch set "arch=%def_arch%"
if not defined config set "config=%def_config%"
)
:: Validate arch and config if not bldall
if not defined bldall (
if /i not "%arch%" == "32" (
if /i not "%arch%" == "64" (
if /i not "%arch%" == "BOTH" (
call :errmsg Invalid arch "%arch%"
)
)
)
if /i not "%config%" == "Debug" (
if /i not "%config%" == "Release" (
if /i not "%config%" == "BOTH" (
call :errmsg Invalid config "%config%"
)
)
)
)
:: Both 'arch' and 'config' == "BOTH" implies 'bldall'
if /i "%arch%" == "BOTH" (
if /i "%config%" == "BOTH" (
set "arch="
set "config="
set "bldall=1"
)
)
goto :validate_cpu
::-----------------------------------------------------------------------------
:validate_cpu
if not defined cpu set "cpu=x86"
if /i "%cpu%" == "aarch" %break%
if /i "%cpu%" == "arm" %break%
if /i "%cpu%" == "mips" %break%
if /i "%cpu%" == "ppc" %break%
if /i "%cpu%" == "sparc" %break%
if /i "%cpu%" == "xscale" %break%
if /i "%cpu%" == "x86" %break%
if /i "%cpu%" == "s390x" %break%
if /i "%cpu%" == "unknown" %break%
call :errmsg Invalid machine cpu "%cpu%"
:break
if /i "%cpu%" == "x86" set "cpu="
goto :validate_arg_sanity
::-----------------------------------------------------------------------------
:validate_arg_sanity
:: Check for conflicting options, etc...
if defined uninstall (
if defined install (
call :errmsg Cannot specify both install and uninstall.
call :errmsg Choose one or the other but not both.
)
)
if defined install (
if defined force (
call :errmsg Option --force is only for uninstalls.
call :errmsg For installs specify --rebuild instead.
)
)
if defined uninstall (
if defined rebuild (
call :errmsg Option --rebuild is only for installs.
call :errmsg For uninstalls specify --force instead.
)
)
goto :validate_args_done
::-----------------------------------------------------------------------------
:validate_args_done
%TRACE% Debug: values after validation:
%TRACE%.
%TRACE% pkgdir = "%pkgdir%"
%TRACE% pkgname = "%pkgname%"
%TRACE% install = "%install%"
%TRACE% instdir = "%instdir%"
%TRACE% uninstall = "%uninstall%"
%TRACE% uinstdir = "%uinstdir%"
%TRACE% cpu = "%cpu%"
%TRACE% arch = "%arch%"
%TRACE% config = "%config%"
%TRACE% rebuild = "%rebuild%"
%TRACE% force = "%force%"
%TRACE% bldall = "%bldall%"
%TRACE%.
if %rc% NEQ 0 %exit%
goto :BEGIN
::-----------------------------------------------------------------------------
:: get_prev_instdir
::-----------------------------------------------------------------------------
:get_prev_instdir
set "prev_instdir="
if not exist "%cachefile%" %return%
call :get_cache_value "%cachefile%" "CMAKE_INSTALL_PREFIX"
if defined cache_value (
call :normalize_dir prev_instdir "%cache_value%"
)
%return%
::-----------------------------------------------------------------------------
:: is_configure_needed
::-----------------------------------------------------------------------------
:is_configure_needed
set "configure_needed="
@REM Initialization...
set "blddir=%pkgname%%arch%.%config%"
set "cachefile=%blddir%\CMakeCache.txt"
call :get_prev_instdir
@REM configure is needed ONLY if:
@REM
@REM * rebuild specified, OR
@REM * blddir does NOT exist yet, OR
@REM * blddir does NOT contain makefile, OR
@REM * uninstall --force specified
if defined rebuild (
goto :configure_is_needed
)
call :isdir "%blddir%"
if not defined isdir (
goto :configure_is_needed
)
call :isfile "%blddir%\Makefile"
if not defined isfile (
goto :configure_is_needed
)
if defined uninstall (
if defined force (
goto :configure_is_needed
)