From 86e3d025dfe57c1129b0667cf59eae364089324b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 21 Jul 2020 14:03:06 -0600 Subject: Implement initial `fpm build` Right now it only knows how to build itself. --- fpm/app/main.f90 | 21 +++++++++++++++++---- fpm/src/fpm.f90 | 32 ++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/fpm/app/main.f90 b/fpm/app/main.f90 index 0f03e95..8533f8c 100644 --- a/fpm/app/main.f90 +++ b/fpm/app/main.f90 @@ -1,7 +1,20 @@ program main - use fpm, only: say_hello +use fpm, only: print_help, cmd_build +implicit none +character(100) :: cmdarg - implicit none - - call say_hello +if (command_argument_count() == 0) then + call print_help() +else if (command_argument_count() == 1) then + call get_command_argument(1, cmdarg) + if (cmdarg == "build") then + call cmd_build() + else + print *, "Unknown command: ", cmdarg + error stop + end if +else + print *, "Too many arguments" + error stop +end if end program main diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index 0d1e6bf..e1e52e9 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -1,10 +1,30 @@ module fpm - implicit none - private +implicit none +private +public :: print_help, cmd_build - public :: say_hello contains - subroutine say_hello - print *, "Fortran Package Manager (fpm)" - end subroutine say_hello + +subroutine print_help() +print *, "Fortran Package Manager (fpm)" +end subroutine + +subroutine run(cmd) +character(len=*), intent(in) :: cmd +integer :: stat +print *, "+ ", cmd +call execute_command_line(cmd, exitstat=stat) +if (stat /= 0) then + print *, "Command failed" + error stop +end if +end subroutine + +subroutine cmd_build() +print *, "# Building project" +call run("gfortran -c src/fpm.f90 -o fpm.o") +call run("gfortran -c app/main.f90 -o main.o") +call run("gfortran main.o fpm.o -o fpm") +end subroutine + end module fpm -- cgit v1.2.3