blob: 53f2befded92e394a3623483c5acdc18df25b0a9 [file] [log] [blame]
Luca Weissb1111222019-09-07 17:25:31 +02001#!/usr/bin/env python3
Rob Herringa5ac29b2019-06-20 15:19:40 -06002# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
Simon Glass50f25072017-03-17 16:14:30 -06003
Luca Weissb1111222019-09-07 17:25:31 +02004# While Python 3 is the default, it's also possible to invoke
5# this setup.py script with Python 2.
6
Simon Glass50f25072017-03-17 16:14:30 -06007"""
8setup.py file for SWIG libfdt
Simon Glass90db6d92017-04-07 15:51:32 -06009Copyright (C) 2017 Google, Inc.
10Written by Simon Glass <sjg@chromium.org>
Simon Glass50f25072017-03-17 16:14:30 -060011"""
12
13from distutils.core import setup, Extension
14import os
Simon Glass90db6d92017-04-07 15:51:32 -060015import re
Simon Glass50f25072017-03-17 16:14:30 -060016import sys
17
David Gibson98972f12018-08-10 14:25:42 +100018
19VERSION_PATTERN = '^#define DTC_VERSION "DTC ([^"]*)"$'
Simon Glass90db6d92017-04-07 15:51:32 -060020
21
David Gibson98972f12018-08-10 14:25:42 +100022def get_version():
David Gibson1e4a0922018-08-10 17:33:24 +100023 version_file = "../version_gen.h"
David Gibson98972f12018-08-10 14:25:42 +100024 f = open(version_file, 'rt')
25 m = re.match(VERSION_PATTERN, f.readline())
26 return m.group(1)
Simon Glass90db6d92017-04-07 15:51:32 -060027
David Gibson607b8582018-11-23 22:11:33 +110028
David Gibson1e4a0922018-08-10 17:33:24 +100029setupdir = os.path.dirname(os.path.abspath(sys.argv[0]))
30os.chdir(setupdir)
Simon Glass50f25072017-03-17 16:14:30 -060031
32libfdt_module = Extension(
33 '_libfdt',
David Gibson607b8582018-11-23 22:11:33 +110034 sources=['libfdt.i'],
35 include_dirs=['../libfdt'],
36 libraries=['fdt'],
37 library_dirs=['../libfdt'],
38 swig_opts=['-I../libfdt'],
Simon Glass50f25072017-03-17 16:14:30 -060039)
40
Simon Glassb04a2cf2017-04-05 10:01:39 -060041setup(
42 name='libfdt',
David Gibson607b8582018-11-23 22:11:33 +110043 version=get_version(),
Simon Glassb04a2cf2017-04-05 10:01:39 -060044 author='Simon Glass <sjg@chromium.org>',
45 description='Python binding for libfdt',
46 ext_modules=[libfdt_module],
David Gibson1e4a0922018-08-10 17:33:24 +100047 py_modules=['libfdt'],
Simon Glassb04a2cf2017-04-05 10:01:39 -060048)