Skip to content

Commit bfbd2db

Browse files
committed
Introduce compilation profiles
- default is equal to debug unless --flag is present and overwrites all arguments - debug is the developement profile, options given by --flag are appended - release is the production profile, options given by --flag are appended
1 parent b4a266f commit bfbd2db

File tree

2 files changed

+67
-56
lines changed

2 files changed

+67
-56
lines changed

fpm/src/fpm_command_line.f90

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module fpm_command_line
6565
logical :: list=.false.
6666
logical :: show_model=.false.
6767
character(len=:),allocatable :: compiler
68+
character(len=:),allocatable :: profile
6869
character(len=:),allocatable :: build_name
6970
character(len=:),allocatable :: flag
7071
end type
@@ -108,7 +109,7 @@ module fpm_command_line
108109
& ' ', 'fpm', 'new', 'build', 'run', &
109110
& 'test', 'runner', 'install', 'update', 'list', 'help', 'version' ]
110111

111-
character(len=:), allocatable :: val_runner, val_build, val_compiler, val_flag
112+
character(len=:), allocatable :: val_runner, val_build, val_compiler, val_flag, val_profile
112113

113114
contains
114115
subroutine get_command_line_settings(cmd_settings)
@@ -155,7 +156,7 @@ subroutine get_command_line_settings(cmd_settings)
155156
& --target " " &
156157
& --list F &
157158
& --all F &
158-
& --release F&
159+
& --profile "default"&
159160
& --example F&
160161
& --runner " " &
161162
& --compiler "'//get_env('FPM_COMPILER','gfortran')//'" &
@@ -194,6 +195,7 @@ subroutine get_command_line_settings(cmd_settings)
194195
cmd_settings=fpm_run_settings(&
195196
& args=remaining,&
196197
& build_name=val_build,&
198+
& profile=val_profile,&
197199
& compiler=val_compiler, &
198200
& flag=val_flag, &
199201
& example=lget('example'), &
@@ -204,7 +206,7 @@ subroutine get_command_line_settings(cmd_settings)
204206

205207
case('build')
206208
call set_args( '&
207-
& --release F &
209+
& --profile "default" &
208210
& --list F &
209211
& --show-model F &
210212
& --compiler "'//get_env('FPM_COMPILER','gfortran')//'" &
@@ -217,6 +219,7 @@ subroutine get_command_line_settings(cmd_settings)
217219
allocate( fpm_build_settings :: cmd_settings )
218220
cmd_settings=fpm_build_settings( &
219221
& build_name=val_build,&
222+
& profile=val_profile,&
220223
& compiler=val_compiler, &
221224
& flag=val_flag, &
222225
& list=lget('list'),&
@@ -342,7 +345,7 @@ subroutine get_command_line_settings(cmd_settings)
342345
call printhelp(help_text)
343346

344347
case('install')
345-
call set_args('--release F --no-rebuild F --verbose F --prefix " " &
348+
call set_args('--profile "default" --no-rebuild F --verbose F --prefix " " &
346349
& --list F &
347350
& --compiler "'//get_env('FPM_COMPILER','gfortran')//'" &
348351
& --flag:: " "&
@@ -355,6 +358,7 @@ subroutine get_command_line_settings(cmd_settings)
355358
install_settings = fpm_install_settings(&
356359
list=lget('list'), &
357360
build_name=val_build, &
361+
profile=val_profile,&
358362
compiler=val_compiler, &
359363
flag=val_flag, &
360364
no_rebuild=lget('no-rebuild'), &
@@ -378,7 +382,7 @@ subroutine get_command_line_settings(cmd_settings)
378382
call set_args('&
379383
& --target " " &
380384
& --list F&
381-
& --release F&
385+
& --profile "default"&
382386
& --runner " " &
383387
& --compiler "'//get_env('FPM_COMPILER','gfortran')//'" &
384388
& --flag:: " "&
@@ -410,6 +414,7 @@ subroutine get_command_line_settings(cmd_settings)
410414
cmd_settings=fpm_test_settings(&
411415
& args=remaining, &
412416
& build_name=val_build, &
417+
& profile=val_profile, &
413418
& compiler=val_compiler, &
414419
& flag=val_flag, &
415420
& example=.false., &
@@ -459,20 +464,23 @@ subroutine get_command_line_settings(cmd_settings)
459464
contains
460465

461466
subroutine check_build_vals()
467+
character(len=:), allocatable :: flags
462468

463469
val_compiler=sget('compiler')
464470
if(val_compiler.eq.'') then
465471
val_compiler='gfortran'
466472
endif
467473

468474
val_flag = sget('flag')
475+
val_profile = sget('profile')
469476
if (val_flag == '') then
470-
call get_default_compile_flags(val_compiler, lget('release'), val_flag)
477+
call get_default_compile_flags(val_compiler, val_profile == "release", val_flag)
471478
else
472-
if (lget('release')) then
473-
write(stdout,'(a)') &
474-
'<WARNING> --release ignored since explicit --flag argument provided'
475-
end if
479+
select case(val_profile)
480+
case("release", "debug")
481+
call get_default_compile_flags(val_compiler, val_profile == "release", flags)
482+
val_flag = flags // " " // val_flag
483+
end select
476484
end if
477485
allocate(character(len=16) :: val_build)
478486
write(val_build, '(z16.16)') fnv_1a(val_flag)
@@ -536,17 +544,17 @@ subroutine set_help()
536544
' ']
537545
help_list_dash = [character(len=80) :: &
538546
' ', &
539-
' build [--compiler COMPILER_NAME] [--release] [--flag FFLAGS] [--list] ', &
547+
' build [--compiler COMPILER_NAME] [--profile PROF] [--flag FFLAGS] [--list] ', &
540548
' help [NAME(s)] ', &
541549
' new NAME [[--lib|--src] [--app] [--test] [--example]]| ', &
542550
' [--full|--bare][--backfill] ', &
543551
' update [NAME(s)] [--fetch-only] [--clean] [--verbose] ', &
544552
' list [--list] ', &
545-
' run [[--target] NAME(s) [--example] [--release] [--flag FFLAGS] [--all] ', &
553+
' run [[--target] NAME(s) [--example] [--profile PROF] [--flag FFLAGS] [--all] ', &
546554
' [--runner "CMD"] [--compiler COMPILER_NAME] [--list] [-- ARGS] ', &
547-
' test [[--target] NAME(s)] [--release] [--flag FFLAGS] [--runner "CMD"] [--list]', &
555+
' test [[--target] NAME(s)] [--profile PROF] [--flag FFLAGS] [--runner "CMD"] [--list]', &
548556
' [--compiler COMPILER_NAME] [-- ARGS] ', &
549-
' install [--release] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] [options] ', &
557+
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] [options] ', &
550558
' ']
551559
help_usage=[character(len=80) :: &
552560
'' ]
@@ -612,7 +620,7 @@ subroutine set_help()
612620
' ', &
613621
' # bash(1) alias example: ', &
614622
' alias fpm-install=\ ', &
615-
' "fpm run --release --runner ''install -vbp -m 0711 -t ~/.local/bin''" ', &
623+
' "fpm run --profile release --runner ''install -vbp -m 0711 -t ~/.local/bin''" ', &
616624
' fpm-install ', &
617625
'' ]
618626
help_fpm=[character(len=80) :: &
@@ -652,25 +660,26 @@ subroutine set_help()
652660
' ', &
653661
' Their syntax is ', &
654662
' ', &
655-
' build [--release] [--flag FFLAGS] [--list] [--compiler COMPILER_NAME]', &
663+
' build [--profile PROF] [--flag FFLAGS] [--list] [--compiler COMPILER_NAME]', &
656664
' new NAME [[--lib|--src] [--app] [--test] [--example]]| ', &
657665
' [--full|--bare][--backfill] ', &
658666
' update [NAME(s)] [--fetch-only] [--clean] ', &
659-
' run [[--target] NAME(s)] [--release] [--flag FFLAGS] [--list] [--example]', &
667+
' run [[--target] NAME(s)] [--profile PROF] [--flag FFLAGS] [--list] [--example]', &
660668
' [--all] [--runner "CMD"] [--compiler COMPILER_NAME] [-- ARGS] ', &
661-
' test [[--target] NAME(s)] [--release] [--flag FFLAGS] [--list] ', &
669+
' test [[--target] NAME(s)] [--profile PROF] [--flag FFLAGS] [--list] ', &
662670
' [--runner "CMD"] [--compiler COMPILER_NAME] [-- ARGS] ', &
663671
' help [NAME(s)] ', &
664672
' list [--list] ', &
665-
' install [--release] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] [options]', &
673+
' install [--profile PROF] [--flag FFLAGS] [--no-rebuild] [--prefix PATH] [options]', &
666674
' ', &
667675
'SUBCOMMAND OPTIONS ', &
668-
' --release Builds or runs in release mode (versus debug mode). fpm(1)', &
669-
' Defaults to using common compiler debug flags. ', &
670-
' When this flag is present common compiler optimization flags', &
671-
' are used.', &
676+
' --profile PROF Builds or runs with the given profile (either release or debug).', &
677+
' fpm(1) defaults to using common compiler debug flags with debug', &
678+
' profile, common compiler optimization flags are used with the', &
679+
' release profile', &
672680
' --flag FFLAGS Use compile arguments provided in FFLAGS rather than', &
673-
' defaults from debug or release mode, module flags are', &
681+
' defaults, if a profile (debug or release) is present the', &
682+
' FFLAGS are appended rather than replaced, module flags are', &
674683
' provided by fpm(1) and must not be present in FFLAGS', &
675684
' --list List candidates instead of building or running them. On ', &
676685
' the fpm(1) command this shows a brief list of subcommands.', &
@@ -693,7 +702,7 @@ subroutine set_help()
693702
' fpm run ', &
694703
' fpm run --example ', &
695704
' fpm new --help ', &
696-
' fpm run myprogram --release -- -x 10 -y 20 --title "my title" ', &
705+
' fpm run myprogram --profile release -- -x 10 -y 20 --title "my title"', &
697706
' fpm install --prefix ~/.local ', &
698707
' ', &
699708
'SEE ALSO ', &
@@ -730,7 +739,7 @@ subroutine set_help()
730739
' run(1) - the fpm(1) subcommand to run project applications ', &
731740
' ', &
732741
'SYNOPSIS ', &
733-
' fpm run [[--target] NAME(s) [--release] [--flag FFLAGS]', &
742+
' fpm run [[--target] NAME(s) [--profile PROF] [--flag FFLAGS]', &
734743
' [--compiler COMPILER_NAME] [--runner "CMD"] [--example]', &
735744
' [--list] [--all] [-- ARGS]', &
736745
' ', &
@@ -756,7 +765,7 @@ subroutine set_help()
756765
' the special characters from shell expansion. ', &
757766
' --all Run all examples or applications. An alias for --target ''*''. ', &
758767
' --example Run example programs instead of applications. ', &
759-
' --release selects the optimized build instead of the debug build. ', &
768+
' --profile PROF Selects the compilation profile for the build. ', &
760769
' --flags FFLAGS selects compile arguments for the build', &
761770
' --compiler COMPILER_NAME Specify a compiler name. The default is ', &
762771
' "gfortran" unless set by the environment ', &
@@ -788,7 +797,7 @@ subroutine set_help()
788797
' fpm run myprog -- -x 10 -y 20 --title "my title line" ', &
789798
' ', &
790799
' # run production version of two applications ', &
791-
' fpm run --target prg1,prg2 --release ', &
800+
' fpm run --target prg1,prg2 --profile release ', &
792801
' ', &
793802
' # install executables in directory (assuming install(1) exists) ', &
794803
' fpm run --runner ''install -b -m 0711 -p -t /usr/local/bin'' ', &
@@ -798,7 +807,7 @@ subroutine set_help()
798807
' build(1) - the fpm(1) subcommand to build a project ', &
799808
' ', &
800809
'SYNOPSIS ', &
801-
' fpm build [--release] [--flags FFLAGS] [--compiler COMPILER_NAME] [-list]', &
810+
' fpm build [--profile PROF] [--flags FFLAGS] [--compiler COMPILER_NAME] [-list]', &
802811
' ', &
803812
' fpm build --help|--version ', &
804813
' ', &
@@ -820,7 +829,7 @@ subroutine set_help()
820829
' specified in the "fpm.toml" file. ', &
821830
' ', &
822831
'OPTIONS ', &
823-
' --release build in build/*_release instead of build/*_debug with ', &
832+
' --profile PROF selects the compilation profile for the build ', &
824833
' high optimization instead of full debug options. ', &
825834
' --flags FFLAGS selects compile arguments for the build', &
826835
' --compiler COMPILER_NAME Specify a compiler name. The default is ', &
@@ -834,8 +843,8 @@ subroutine set_help()
834843
'EXAMPLES ', &
835844
' Sample commands: ', &
836845
' ', &
837-
' fpm build # build with debug options ', &
838-
' fpm build --release # build with high optimization ', &
846+
' fpm build # build with debug options ', &
847+
' fpm build --profile release # build with high optimization ', &
839848
'' ]
840849

841850
help_help=[character(len=80) :: &
@@ -979,7 +988,7 @@ subroutine set_help()
979988
' test(1) - the fpm(1) subcommand to run project tests ', &
980989
' ', &
981990
'SYNOPSIS ', &
982-
' fpm test [[--target] NAME(s)] [--release] [--flag FFLAGS]', &
991+
' fpm test [[--target] NAME(s)] [--profile PROF] [--flag FFLAGS]', &
983992
' [--compiler COMPILER_NAME ] [--runner "CMD"] [--list][-- ARGS]', &
984993
' ', &
985994
' fpm test --help|--version ', &
@@ -996,7 +1005,7 @@ subroutine set_help()
9961005
' any single character and "*" represents any string. ', &
9971006
' Note The glob string normally needs quoted to ', &
9981007
' protect the special characters from shell expansion.', &
999-
' --release selects the optimized build instead of the debug build. ', &
1008+
' --profile PROF selects the compilation profile for the build.', &
10001009
' --flags FFLAGS selects compile arguments for the build', &
10011010
' --compiler COMPILER_NAME Specify a compiler name. The default is ', &
10021011
' "gfortran" unless set by the environment ', &
@@ -1020,7 +1029,7 @@ subroutine set_help()
10201029
' # run a specific test and pass arguments to the command ', &
10211030
' fpm test mytest -- -x 10 -y 20 --title "my title line" ', &
10221031
' ', &
1023-
' fpm test tst1 tst2 --release # run production version of two tests ', &
1032+
' fpm test tst1 tst2 --profile PROF # run production version of two tests', &
10241033
'' ]
10251034
help_update=[character(len=80) :: &
10261035
'NAME', &
@@ -1046,8 +1055,8 @@ subroutine set_help()
10461055
' install(1) - install fpm projects', &
10471056
'', &
10481057
'SYNOPSIS', &
1049-
' fpm install [--release] [--flag FFLAGS] [--list] [--no-rebuild] [--prefix DIR]', &
1050-
' [--bindir DIR] [--libdir DIR] [--includedir DIR]', &
1058+
' fpm install [--profile PROF] [--flag FFLAGS] [--list] [--no-rebuild]', &
1059+
' [--prefix DIR] [--bindir DIR] [--libdir DIR] [--includedir DIR]', &
10511060
' [--verbose]', &
10521061
'', &
10531062
'DESCRIPTION', &
@@ -1060,7 +1069,7 @@ subroutine set_help()
10601069
'OPTIONS', &
10611070
' --list list all installable targets for this project,', &
10621071
' but do not install any of them', &
1063-
' --release selects the optimized build instead of the debug build', &
1072+
' --profile selects the compilation profile for installation', &
10641073
' --flags FFLAGS selects compile arguments for the build', &
10651074
' --no-rebuild do not rebuild project before installation', &
10661075
' --prefix DIR path to installation directory (requires write access),', &
@@ -1076,7 +1085,7 @@ subroutine set_help()
10761085
'EXAMPLES', &
10771086
' 1. Install release version of project:', &
10781087
'', &
1079-
' fpm install --release', &
1088+
' fpm install --profile release', &
10801089
'', &
10811090
' 2. Install the project without rebuilding the executables:', &
10821091
'', &

0 commit comments

Comments
 (0)