forked from tliron/pygobject-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·127 lines (106 loc) · 3.28 KB
/
build
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
echo "Cleaning..."
rm -rf tmp
rm -rf lib
rm -rf type
rm -f test
mkdir tmp
mkdir lib
mkdir type
if [ "$1" == vala ]; then
echo "Building Vala library..."
# Note 1: Ubuntu package for valac: valac-0.14
# Note 2: Generates broken gir if --gir= has a directory prefixed to it
# Note 3: The -X switches for gcc are necessary!
# Note 4: The generated gir will include GObject-2.0. That gir is
# included in Ubuntu package: libgirepository1.0-dev
valac \
--library=Logging \
--directory=tmp \
--gir=Logging-1.0.gir \
--output=liblogging.so \
-X -shared \
-X -fPIC \
logging.vala
mv tmp/liblogging.so lib
mv tmp/Logging-1.0.gir type
# Note: We cannot generate C code and compile in the same call
# (We don't need the C code to run the test, but we are curious
# as to what Vala is generating. The resulting code will be in
# logging.c)
valac \
--ccode \
logging.vala
else
echo "Building C library..."
# Compile
gcc \
-c \
-fPIC \
$(pkg-config --cflags --libs gobject-2.0) \
logging_logger.c \
$(pkg-config --libs gobject-2.0) \
-o tmp/logging.o
# Link the shared library
gcc \
-shared \
tmp/logging.o \
$(pkg-config --libs gobject-2.0) \
-o lib/liblogging.so
# Link the static library (not used in this example, but it's here
# for the sake of completion)
ar crs lib/liblogging.a tmp/logging.o
echo "Creating gir..."
# Note 1: Ubuntu package for g-ir-scanner: gobject-introspection
# Note 2: I could not get g-ir-scanner to work with gcc above version
# 4.4! I'm sure it's due to some new defaults that must be
# explicitly changed, but could not find them. So, make sure
# to install Ubuntu package: gcc-4.4
# Note 3: If we do not explicitly include GObject-2.0, PyGObject will
# be able to to load the types, but will not actually call
# class and instance init functions! (valac includes it by
# default in its gir output)
# Note 4: The GObject-2.0 gir is included in Ubuntu package:
# libgirepository1.0-dev
CC=gcc-4.4 \
LD_LIBRARY_PATH=lib \
g-ir-scanner \
--warn-all \
--namespace=Logging \
--nsversion=1.0 \
--include=GObject-2.0 \
--library-path=lib \
--library=logging \
--pkg=gobject-2.0 \
--output=type/Logging-1.0.gir \
logging_logger.c logging_logger.h
echo "Building C executable..."
gcc \
$(pkg-config --cflags --libs gobject-2.0) \
test.c \
lib/liblogging.so \
$(pkg-config --libs gobject-2.0) \
-o test
echo "Test C..."
LD_LIBRARY_PATH=lib \
./test
fi
echo "Building typelib..."
# Note 1: Ubuntu package for g-ir-compiler: gobject-introspection
# Note 2: The --shared-library switch is really only necessary when using
# the gir produced by valac, because it does not include the
# 'shared-library' attribute in <namespace> tag.
g-ir-compiler \
--shared-library=liblogging.so \
--output=type/Logging-1.0.typelib \
type/Logging-1.0.gir
echo "Test Python..."
# Note 1: Ubuntu's default path for typelib files seems to be:
# /usr/lib/girepository-1.0/.
# Note 2: It is also possible to programmatically change the
# GI_TYPELIB_PATH environment var in Python (os.environ API).
# If you do so, make sure to set it before importing from
# gi.repository.
LD_LIBRARY_PATH=lib \
GI_TYPELIB_PATH=type \
./test.py