Skip to content

Commit

Permalink
Added target to make a script binary
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Sep 3, 2020
1 parent 0cfa6e4 commit 4b7de86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Guide/scripts.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@ Hello World, C!
This is made possible because of the [she-bang line](https://en.wikipedia.org/wiki/Shebang_%28Unix%29) `#!/usr/bin/env run-script` at the top of the task file.

In case you get a permission error, try to add the executable flag via `chmod +x Application/Script/HelloWorldToAllUsers.hs`.

## Building a script

In production you might want to build a script to a binary for performance reasons. Use make like this:

```bash
make build/bin/Script/HelloWorldToAllUsers
```

This will produce a binary `build/bin/Script/HelloWorldToAllUsers` from the source file `Application/Script/HelloWorldToAllUsers.hs`.
11 changes: 11 additions & 0 deletions lib/IHP/Makefile.dist
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,14 @@ ifneq ($(wildcard IHP/.*),)
else
ln -s ${IHP_LIB} build/ihp-lib
endif

build/bin/Script/%: build/Script/Main/%.hs
mkdir -p build/bin/Script
ghc -O2 ${GHC_OPTIONS} ${PROD_GHC_OPTIONS} $< -o $@ -odir build/Script -hidir build/Script

build/Script/Main/%.hs: Application/Script/%.hs
mkdir -p build/Script/Main
echo "module Main (main) where" > $@
echo "import IHP.ScriptSupport" >> $@
echo "import Application.Script.$* (run)" >> $@
echo "main = runScript run" >> $@

0 comments on commit 4b7de86

Please sign in to comment.