0

https://github.com/koalaman/shellcheck

I can install the above package using cabal install. But I'd like to run the raw ghc commands that compile the binary without the installation.

How can I do it?

halfer
  • 19,824
  • 17
  • 99
  • 186
user1424739
  • 11,937
  • 17
  • 63
  • 152

2 Answers2

1

Here's the usual way. Step one is to get a copy of the code. One of these two will do it:

% git clone https://github.com/koalaman/shellcheck
% cabal unpack shellcheck

Once you are in the directory with the code, you can ask cabal to build it without installing it by using the build command instead of the install command.

% cabal build

If you'd like to see the sequence of subcommands that cabal invokes for this task, you can ask it to show them by increasing the verbosity.

% cabal build -v3
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • Using `cabal build -v3`, I don't see the raw ghc commands, I just see something like `[ 2 of 23] Compiling ShellCheck.Regex ( src/ShellCheck/Regex.hs, ..)`. How to see the raw `ghc` commands? – user1424739 May 27 '21 at 20:29
  • Those `Compiling ...` messages are from after/during the `ghc` invocations, you need to scroll up a bit. – Noughtmare May 27 '21 at 20:46
  • @user1424739 Hm, are you sure the commands aren't in there? Can you make a paste somewhere with the full output? – Daniel Wagner May 27 '21 at 20:52
  • See https://file.io/oMQisKUm0d14. I don't see the ghc commands above. – user1424739 May 27 '21 at 21:20
  • 1
    @user1424739 For example, lines 3148, 3221, and 3694 are `ghc` invocations. – Daniel Wagner May 27 '21 at 21:25
  • Shouldn't it compile each hs file individually and link them together? Those seem still a wrapper command that wraps more basic commands. – user1424739 May 27 '21 at 21:56
  • @user1424739 What does the "it" in your question refer to? What makes you believe that "it" does not compile each hs file individually and then link them together? – Daniel Wagner May 27 '21 at 22:02
  • 1
    It is each of the ghc that you mentioned. If ghc does compile each hs file individually, I'd expect to see a separate ghc command for each hs file instead of one ghc command for many hs files. – user1424739 May 27 '21 at 23:22
  • 1
    @user1424739 Okay, well, your expectations turn out to be incorrect. – Daniel Wagner May 28 '21 at 02:26
  • So there is no equivalent commands that compile each hs file with a single ghc command and link them with another ghc command? – user1424739 May 28 '21 at 13:37
  • @user1424739 Sure, there are such commands. But that wasn't what you asked for in the question... and I have to admit I don't see why you would want to make more work for yourself by expanding the list of things you must do to get the thing compiled. But if you're curious about different ways of invoking GHC, definitely take a look through its user manual, and open a fresh question with details of your needs if you can't work out from the documentation how to meet them. – Daniel Wagner May 28 '21 at 14:13
0

First of all you'll need to install all dependencies, you can do that with cabal install --dependencies-only. Then you need to make a file Paths_ShellCheck.hs with the contents:

module Paths_ShellCheck where
import Data.Version
version = Version [0,7,2] []

Then you can use this GHC command:

ghc \
  --make \
  -O \
  -package-db ~/.cabal/store/ghc-8.10.4/package.db \
  -hide-all-packages \
  -package regex-tdfa \
  -package parsec \
  -package containers \
  -package base \
  -package deepseq \
  -package mtl \
  -package QuickCheck \
  -package array \
  -package aeson \
  -package bytestring \
  -package Diff \
  -package filepath \
  -package directory \
  src/ShellCheck/*.hs \
  src/ShellCheck/*/*.hs \
  Paths_ShellCheck.hs \
  shellcheck.hs

Which will build the executable shellcheck. Note that this is specifically for GHC 8.10.4, you can change that if you want to use another GHC version.

If you don't even want to run cabal install --dependencies-only then the easiest way might be to copy all the *.hs source files of all the dependencies, add those to the globs at the end, and remove the corresponding -package ... argument. You can perhaps keep the packages that are bundled with GHC: namely base, deepseq, mtl, containers, array, bytestring, filepath, parsec, and directory. So that leaves Diff, aeson, QuickCheck and regex-tdfa and their transitive dependencies.

Noughtmare
  • 9,410
  • 1
  • 12
  • 38
  • Is this still a wrapper of more basic commands? Does ghc has something like .c -> .o -> .bin like per file compilation like gcc so that I can compile each file and link them? – user1424739 May 27 '21 at 20:31
  • GHC does generate .o files of all the input .hs files, you can pass the `-c` option to stop after generating those. And you can pass .o files as input to GHC which will then get linked into the final executable. – Noughtmare May 27 '21 at 20:51