···11+# This file is part of Darling.
22+#
33+# Copyright (C) 2017 Lubos Dolezel
44+#
55+# Darling is free software: you can redistribute it and/or modify
66+# it under the terms of the GNU General Public License as published by
77+# the Free Software Foundation, either version 3 of the License, or
88+# (at your option) any later version.
99+#
1010+# Darling is distributed in the hope that it will be useful,
1111+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313+# GNU General Public License for more details.
1414+#
1515+# You should have received a copy of the GNU General Public License
1616+# along with Darling. If not, see <http://www.gnu.org/licenses/>.
1717+1818+import sys, subprocess
1919+2020+def usage():
2121+ print "Usage: %s <Mach-O> <output directory>" % sys.argv[0]
2222+2323+if len(sys.argv) != 3:
2424+ usage()
2525+2626+macho = sys.argv[1]
2727+dest = sys.argv[2]
2828+2929+out = subprocess.check_output(["nm", "-Ug", macho])
3030+3131+functions = []
3232+for line in out.split("\n"):
3333+ if line == "":
3434+ continue
3535+ components = line.split(" ")
3636+ id = components[1]
3737+ name = components[2]
3838+ # Remove the underscore
3939+ name = name[1 : len(name)]
4040+4141+ if id == "T":
4242+ functions.append(name)
4343+4444+header = open(dest + "/functions.h", "w")
4545+source = open(dest + "/functions.c", "w")
4646+4747+copyright ="""/*
4848+This file is part of Darling.
4949+5050+Copyright (C) 2017 Lubos Dolezel
5151+5252+Darling is free software: you can redistribute it and/or modify
5353+it under the terms of the GNU General Public License as published by
5454+the Free Software Foundation, either version 3 of the License, or
5555+(at your option) any later version.
5656+5757+Darling is distributed in the hope that it will be useful,
5858+but WITHOUT ANY WARRANTY; without even the implied warranty of
5959+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6060+GNU General Public License for more details.
6161+6262+You should have received a copy of the GNU General Public License
6363+along with Darling. If not, see <http://www.gnu.org/licenses/>.
6464+*/
6565+6666+"""
6767+6868+header.write(copyright)
6969+source.write(copyright)
7070+7171+for funcname in functions:
7272+ header.write("void %s(void);\n" % funcname)
7373+ source.write("void %s(void) { }\n" % funcname)
7474+7575+header.close()
7676+source.close()