summaryrefslogtreecommitdiff
path: root/configure.py
blob: 613e143a0d7f60a4e5168045ca2fb30d84f8a1c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# This file is part of TALER
# (C) 2019 GNUnet e.V.
#
# Authors:
# Author: ng0 <ng0@taler.net>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
# LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
# THIS SOFTWARE.
#
# SPDX-License-Identifier: 0BSD

import argparse
import os
import sys
import logging

# This script so far generates config.mk.
# The only value it produces is prefix,
# which is either taken as the first argument
# to this script, or as --prefix=, or read
# from the environment variable PREFIX.
#
# TODO: Also respect DESTDIR ($PREFIX/$DESTDIR/rest).


def _read_prefix():
    logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(__name__)

    if 'PREFIX' in os.environ:
        # logger.debug('PREFIX from environment')
        myprefix = os.environ.get('PREFIX')
        if myprefix is not None and os.path.isdir(myprefix) is True:
            # logger.debug('PREFIX from environment: %s', myprefix)
            return myprefix

    else:
        # logger.debug('PREFIX from argv')
        parser = argparse.ArgumentParser()
        parser.add_argument("-p",
                            "--prefix",
                            type=str,
                            default="/usr/local",
                            # required=True,
                            help='Directory prefix for installation')
        parser.add_argument("-y",
                            "--yarn",
                            type=str,
                            required=True,
                            help='name of yarn executable')
        # logger.debug('parser.parse_args step')
        args = parser.parse_args()
        # logger.debug('%s', args)
        myprefix = args.prefix
        yarnexe = args.yarn
        # if args.prefix is not None and os.path.isdir(myprefix) is True:
        if args.prefix and os.path.isdir(myprefix) is True:
            return [myprefix, yarnexe];

def main():
    # mylist = str(_read_prefix())
    mylist = _read_prefix()
    myprefix = mylist[0]
    yarnexe = mylist[1]
    f = open('config.mk', 'w+')
    f.write('# this file is autogenerated by ./configure\n')
    f.write('prefix=' + myprefix + '\n')
    f.write('yarnexe=' + yarnexe + '\n')
    f.close()


main()