1#!/usr/bin/env python3
2# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
3
4# While Python 3 is the default, it's also possible to invoke
5# this setup.py script with Python 2.
6
7"""
8setup.py file for SWIG libfdt
9Copyright (C) 2017 Google, Inc.
10Written by Simon Glass <sjg@chromium.org>
11"""
12
13from distutils.core import setup, Extension
14import os
15import re
16import sys
17
18
19VERSION_PATTERN = '^#define DTC_VERSION "DTC ([^"]*)"$'
20
21
22def get_version():
23    version_file = "../version_gen.h"
24    f = open(version_file, 'rt')
25    m = re.match(VERSION_PATTERN, f.readline())
26    return m.group(1)
27
28
29setupdir = os.path.dirname(os.path.abspath(sys.argv[0]))
30os.chdir(setupdir)
31
32libfdt_module = Extension(
33    '_libfdt',
34    sources=['libfdt.i'],
35    include_dirs=['../libfdt'],
36    libraries=['fdt'],
37    library_dirs=['../libfdt'],
38    swig_opts=['-I../libfdt'],
39)
40
41setup(
42    name='libfdt',
43    version=get_version(),
44    author='Simon Glass <sjg@chromium.org>',
45    description='Python binding for libfdt',
46    ext_modules=[libfdt_module],
47    py_modules=['libfdt'],
48)
49