Skip to content

Instantly share code, notes, and snippets.

@king1600
Created November 14, 2017 18:12
Show Gist options
  • Save king1600/23565d1ebb668665c73d81a7ea8f62db to your computer and use it in GitHub Desktop.
Save king1600/23565d1ebb668665c73d81a7ea8f62db to your computer and use it in GitHub Desktop.
My Haskell Build script
import os
import sys
import shutil
CC = "ghc"
EXT = '.hs'
BINARY = 'app'
SAME_DIR = True
SRC_DIR = os.path.join(os.getcwd(), 'src')
BUILD_DIR = os.path.join(os.getcwd(), 'build')
if not os.path.exists(BUILD_DIR):
os.mkdir(BUILD_DIR)
if not os.path.exists(SRC_DIR):
raise Exception("Source Directory does not exist!")
SOURCES = ' '.join((
f.split(os.getcwd())[1][1:] if SAME_DIR else f for f in
(
os.path.join(root, f)
for root, _, files in os.walk(SRC_DIR)
for f in files if f.endswith(EXT)
)
))
INCLUDES = []
LIBS = ''
FLAGS = '-threaded -feager-blackholing +RTS -N'
INCLUDES = ' '.join(['i' + i for i in INCLUDES])
OUTPUT = ' '.join(['-odir', BUILD_DIR, '-hidir', BUILD_DIR, '-o', BINARY])
def debug(verbose=False):
flags = '-Wall'
command = ' '.join([CC, INCLUDES, SOURCES, flags, OUTPUT, LIBS, FLAGS])
if verbose: print (command)
os.system(command)
def release(verbose=False):
flags = '-Werror -O2'
command = ' '.join([CC, INCLUDES, SOURCES, flags, OUTPUT, LIBS, FLAGS])
if verbose: print (command)
os.system(command)
def clean(verbose=False):
if os.path.exists(BUILD_DIR):
for root, _, files in os.walk(BUILD_DIR):
for f in files:
if verbose: print ("Deleting: " + f)
os.remove(os.path.join(root, f))
if len(sys.argv) > 1:
if sys.argv[1] == __file__:
sys.argv = sys.argv[1:]
task = sys.argv[1].lower()
verbose = '-v' in sys.argv
if task == 'debug' or task == 'build':
debug(verbose)
elif task == 'release':
release(verbose)
elif task == 'clean' or task == 'clear':
clean(verbose)
else:
debug(verbose)
else:
debug()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment