FG42/fbt

128 lines
4.2 KiB
Plaintext
Executable File

:;exec emacs --no-site-file --no-site-lisp -batch -l "$0" -f main "$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)" "$@"
;;; FGBuildTool --- The build tool for FG42
;;
;; Copyright (c) 2010-2020 Sameer Rahmani <lxsameer@gnu.org>
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://gitlab.com/FG42/FG42
;; Version: 3.0.0
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;
;;; Commentary:
;;; Code:
(defvar FG42_VERSION "3.0.0-snapshot"
"The version number of the current build of FG42.")
(defun ->path (dir)
"Return the absolute path to the given DIR with respect to FG42_HOME."
(concat (getenv "FG42_HOME") (format "/%s" dir)))
(defun el-files-in (dir)
"Return a list of elisp files in the given DIR."
(split-string (shell-command-to-string
(format "find %s -iname \"*.el\"" (->path dir))) "\n" t))
(defun lint (dir)
"Run linter on all the elisp files in the given DIR."
(let ((files (el-files-in dir)))
(if files
(dolist (file files)
;; TODO: Setup flycheck here and use it to lint the elisp file.
;; tried to use flymake but it doesn't let you do it manually
(with-temp-buffer
(insert-file-contents file)))
(error "Couldn't find any elisp files"))))
(defun compile (dir)
"Compile all the elisp files in the given DIR regardless of timestamp.
The DIR should be relative to FG42_HOME."
(let ((target (->path dir)))
(message "Compiling '%s'..." target)
(add-to-list 'load-path target)
(byte-recompile-directory target 0 t)))
(defun build (&rest params)
"Compile the core and install the dependencies with the given PARAMS."
(compile "core"))
(defun todo (dir)
"Extract the TODO tags from the comments in the given DIR."
(message "TBD"))
(defun fpkg-init (params)
"Setup fpkg repository with the given PARAMS."
(require 'fg42/fpkg/core)
(fg42-fpkg/initialize FG42))
(defun print-fpkg-help (command)
"Print the usage for fpkg and the possible wrong COMMAND."
(message "Usage:\n")
(message "init - Setup the fpkg repository"))
(defun fpkg (params)
"The main interface to `fpkg' subcommand and PARAMS."
(let ((subcommand (car args))
(args (cdr params)))
(cond
((string= subcommand "init") (funcall #'fpkg-init args))
(t (print-fpkg-help subcommand)))))
(defun print-help (command)
"Print out a usage instructions and print out the invalid msg for COMMAND."
(when command
(warn "I don't know about '%s' command.\n" command))
(message "Usage:\n")
(message "compile [DIR] - Compiles the given DIR to bytecodes (default: \"core\")")
(message "build - Builds FG42 by compiling the code and installing dependencies."))
(defun main ()
"Execute a subcommand by looking into input arguments of the script."
(message (version))
(message "\nFG42 Build tool v%s\n\n" FG42_VERSION)
(let ((fg42-home (car command-line-args-left))
(command (cadr command-line-args-left))
(args (cddr command-line-args-left)))
;; FG42 Needs this env var to know where had it been installed
(setenv "FG42_HOME" fg42-home)
(setenv "FG42_VERSION" FG42_VERSION)
(add-to-list 'load-path (concat (file-name-as-directory fg42-home) "core"))
(load (concat (file-name-as-directory (getenv "FG42_HOME")) "system"))
(cond
((string= command "fpkg") (funcall #'fpkg args))
((string= command "lint") (funcall #'lint (or (car args) "core")))
((string= command "compile") (funcall #'compile (or (car args) "core")))
((string= command "build") (funcall #'build args))
(t (print-help command)))))
;; Local Variables:
;; mode: emacs-lisp
;; End:
;;; fbt ends here