mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Change a way how .pyc are generated from .py
Now Makefile does the search of .py in the source. Also change some dependencies between other modpython stuff. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2224 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -9,7 +9,7 @@ modpythonFLAGS := $(PYTHONCOMMON) -I.
|
||||
|
||||
PYTHONHOOK := modpython_install
|
||||
CLEAN += modpython/_znc_core.so modpython/_znc_core.cpp modpython/znc_core.py modpython/znc_core.pyc
|
||||
CLEAN += modpython/swigpyrun.h modpython/znc.pyc modpython/functions.cpp modpython/compiler
|
||||
CLEAN += modpython/swigpyrun.h modpython/znc.pyc modpython/functions.cpp modpython/compiler *.pyc
|
||||
ifneq "$(srcdir)" "."
|
||||
# Copied from source for out-of-tree builds
|
||||
CLEAN += modpython/znc.py
|
||||
@@ -19,11 +19,22 @@ else
|
||||
FILES := $(shell echo $(FILES) | sed -e "s/modpython//")
|
||||
endif
|
||||
|
||||
.PHONY: modpython_install modpython_compilepyc
|
||||
.PHONY: modpython_install modpython_all
|
||||
|
||||
install: $(PYTHONHOOK)
|
||||
|
||||
modpython.so: modpython/_znc_core.so modpython/swigpyrun.h modpython_compilepyc
|
||||
# This will run: modpython/compiler blah.py blah.pyc
|
||||
%.pyc: modpython/compiler %.py
|
||||
$(E) Compiling $@...
|
||||
$(Q)$^ $@
|
||||
|
||||
ifneq "$(PYCFG)" ""
|
||||
all: modpython_all
|
||||
endif
|
||||
modpython_all: modpython/_znc_core.so modpython/swigpyrun.h modpython/znc.pyc modpython/znc_core.pyc
|
||||
modpython_all: $(addsuffix c, $(notdir $(wildcard $(srcdir)/*.py)))
|
||||
|
||||
modpython/znc_core.py: modpython/_znc_core.so
|
||||
modpython/_znc_core.so: modpython/_znc_core.cpp Makefile modpython/functions.cpp
|
||||
$(E) Building ZNC python bindings library...
|
||||
$(Q)$(CXX) $(MODFLAGS) $(LDFLAGS) $(MODLINK) -I$(srcdir) $(PYTHONCOMMON) -o $@ $<
|
||||
@@ -44,20 +55,13 @@ modpython/compiler: modpython/compiler.cpp
|
||||
$(E) Building optimizator for python files...
|
||||
$(Q)$(CXX) $(PYTHONCOMMON) -o $@ $<
|
||||
|
||||
modpython_compilepyc: modpython/compiler
|
||||
# This is allowed to fail only if $(srcdir) == pwd.
|
||||
-$(Q)cp $(srcdir)/*.py ./
|
||||
-$(Q)cp $(srcdir)/*.pyc ./
|
||||
-$(Q)cp $(srcdir)/modpython/znc*.py modpython/
|
||||
$(Q)$<
|
||||
|
||||
modpython_install: create_install_dir install_metadirs modpython.so
|
||||
modpython_install: create_install_dir install_metadirs modpython_all
|
||||
for i in $(wildcard *.pyc); do \
|
||||
$(INSTALL_DATA) $$i $(DESTDIR)$(MODDIR); \
|
||||
done
|
||||
for a in $(srcdir)/*; do \
|
||||
if [ -d $$a ]; then \
|
||||
if [ -f $${a}.py ] || [ -f $${a}.pyc ]; then \
|
||||
if [ -f $${a}.py ]; then \
|
||||
cp -Rp $$a $(DESTDIR)$(DATADIR); \
|
||||
fi \
|
||||
fi \
|
||||
|
||||
@@ -10,15 +10,27 @@
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Py_Initialize();
|
||||
int res = PyRun_SimpleString(
|
||||
"import compileall\n"
|
||||
"print('Optimizing python files for later use...')\n"
|
||||
"import sys\n"
|
||||
"if sys.version_info < (3, 2):\n"
|
||||
" compileall.compile_dir('.')\n"
|
||||
"else:\n"
|
||||
" compileall.compile_dir('.', legacy=True)\n"
|
||||
);
|
||||
PyObject* pyModule = PyImport_ImportModule("py_compile");
|
||||
if (!pyModule) {
|
||||
PyErr_Print();
|
||||
Py_Finalize();
|
||||
return 1;
|
||||
}
|
||||
PyObject* pyFunc = PyObject_GetAttrString(pyModule, "compile");
|
||||
Py_CLEAR(pyModule);
|
||||
if (!pyFunc) {
|
||||
PyErr_Print();
|
||||
Py_Finalize();
|
||||
return 2;
|
||||
}
|
||||
PyObject* pyRes = PyObject_CallFunction(pyFunc, const_cast<char*>("ss"), argv[1], argv[2]);
|
||||
Py_CLEAR(pyFunc);
|
||||
if (!pyRes) {
|
||||
PyErr_Print();
|
||||
Py_Finalize();
|
||||
return 3;
|
||||
}
|
||||
Py_CLEAR(pyRes);
|
||||
Py_Finalize();
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user