aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndřej Čertík <ondrej@certik.us>2020-07-21 14:03:06 -0600
committerOndřej Čertík <ondrej@certik.us>2020-07-21 14:10:45 -0600
commit86e3d025dfe57c1129b0667cf59eae364089324b (patch)
treef883581dfd1dce2262ba102282f03aeba4e4f323
parent2dcd2df3692b8769558428ae0ae77d15fcc804f4 (diff)
downloadfpm-86e3d025dfe57c1129b0667cf59eae364089324b.tar.gz
fpm-86e3d025dfe57c1129b0667cf59eae364089324b.zip
Implement initial `fpm build`
Right now it only knows how to build itself.
-rw-r--r--fpm/app/main.f9021
-rw-r--r--fpm/src/fpm.f9032
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