-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmake-library-m4.py
executable file
·61 lines (46 loc) · 1.46 KB
/
make-library-m4.py
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
#!/usr/bin/env python
"""
Recursively adds all files in a library to automake.
Usage example::
$ python make-library-m4.py lib > library.m4
Then, in Makefile.am, add::
include library.m4
This file is part of Mickey Scheme
Copyright (C) 2015 Christian Stigen Larsen
Distributed under the LGPL v2.1 or later.
"""
import os
import stat
import sys
def normalized(s):
"""Normalizes string for inclusion in an automake file."""
return s.replace("/", "_").replace("-", "_")
def isdir(path):
"""Checks if given path is a directory."""
return stat.S_ISDIR(os.stat(path).st_mode)
def isfile(path):
"""Checks if given path is a file."""
return stat.S_ISREG(os.stat(path).st_mode)
def make(path):
"""Recursively prints out automake build commands for a directory tree."""
files = []
subdirs = []
for f in os.listdir(path):
name = os.path.join(path, f)
if isfile(name):
files.append(name)
elif isdir(name):
subdirs.append(name)
if len(files):
print("lib_%sdir = $(pkgdatadir)/$(VERSION)/%s" % (normalized(path),
path))
print("lib_%s_DATA = \\" % normalized(path))
for i, f in enumerate(sorted(files)):
print("\t%s%s" % (f, " \\" if (i+1) < len(files) else ""))
print("")
if len(subdirs):
for s in sorted(subdirs):
make(s)
if __name__ == "__main__":
for directory in sys.argv[1:]:
make(directory)