Η δομή δημιουργίας
Generation of the source code for a gtkmm-style wrapper API requires use of tools such as gmmproc and generate_wrap_init.pl, which are included in glibmm. In theory you could write your own build files to use these appropriately, but a much better option is to make use of the build infrastructure provided by the mm-common module. To get started, it helps a lot to pick an existing binding module as an example to look at.
Για παράδειγμα, ας θεωρήσουμε ότι πακετάρουμε μια βιβλιοθήκη C που λέγεται libsomething. Παρέχει μια API με βάση GObject με επώνυμους τύπους, για παράδειγμα, SomeWidget και SomeStuff.
- G.1.1. Αντιγραφή του έργου σκελετού
- G.1.2. Τροποποίηση αρχείων δόμησης
G.1.1. Αντιγραφή του έργου σκελετού
Typically our wrapper library would be called libsomethingmm. We can start by copying the skeleton source tree from the mm-common module. Starting with mm-common 1.0.0 this skeleton application is built with the Meson build system.
$ git clone https://gitlab.gnome.org/GNOME/mm-common.git $ cp -a mm-common/skeletonmm libsomethingmm
This provides a directory structure for the source .hg and .ccg files and the hand-written .h and .cc files, with meson.build files that can specify the various files in use, in terms of Meson variables. The directory structure usually looks like this, after we have renamed the directories appropriately:
-
libsomethingmm: The top-level directory.
-
libsomething: Contains the main include file and the pkg-config .pc file.
- src: Contains .hg and .ccg source files.
- libsomethingmm: Contains hand-written .h and .cc files.
-
As well as renaming the directories, we should rename some of the source files. For instance:
$ for f in $(find libsomethingmm -depth -name '*skeleton*'); do \ d="${f%/*}"; b="${f##*/}"; mv "$f" "$d/${b//skeleton/libsomething}"; \ done
Σημειώστε ότι τα αρχεία που τελειώνουν σε .in θα χρησιμοποιηθούν για τη δημιουργία αρχείων με το ίδιο όνομα, αλλά χωρίς το επίθεμα .in, αντικαθιστώντας μερικές μεταβλητές με τις ενεργές τιμές κατά τη διάρκεια του σταδίου διαμόρφωσης.
Generated files are saved in the build tree, which is separated from the source tree when meson and ninja are used.
G.1.2. Τροποποίηση αρχείων δόμησης
Now we edit the files to adapt them to our needs. You might prefer to use a multiple-file search-replace utility for this, such as regexxer. Note that nearly all of the files provided with the skeleton source tree contain placeholder text. Thus, the substitutions should be performed globally, and not be limited to the Meson files.
Όλες οι αναφορές της skeleton πρέπει να αντικατασταθούν από το σωστό όνομα της βιβλιοθήκης C που συσκευάζεται, όπως "something" ή "libsomething". Με τον ίδιο τρόπο, όλα τα στιγμιότυπα της SKELETON πρέπει να αντικατασταθούν από "SOMETHING" ή "LIBSOMETHING" και όλες οι εμφανίσεις της Skeleton να αλλαχτούν σε "Something".
Παρόμοια, αντικαταστήστε όλα τα στιγμιότυπα της Joe Hacker με το όνομα του σκοπούμενου κατόχου πνευματικών δικαιωμάτων, που είσαστε προφανώς εσείς. Κάντε το ίδιο για τη διεύθυνση αλληλογραφίας joe@example.com.
- G.1.2.1. meson.build in the top-level directory
- G.1.2.2. Other meson.build files
- G.1.2.3. Δημιουργία αρχείων .hg και .ccg
G.1.2.1. meson.build in the top-level directory
- Είναι συνηθισμένο για σύνδεση ενοτήτων να ανιχνεύουμε τον αριθμό έκδοσης της βιβλιοθήκης που συσκευάζεται. Έτσι, για παράδειγμα, αν η βιβλιοθήκη C είναι στην έκδοση 1.23.4, τότε η αρχική έκδοση της ενότητας σύνδεσης μπορεί να είναι 1.23.0. Όμως, αποφύγετε το ξεκίνημα με έναν άρτιο δευτερεύοντα αριθμό έκδοσης επειδή αυτό συνήθως δείχνει μια σταθερή έκδοση.
- In the project() function, change the license and the C++ version, if necessary.
- You probably need to add more required modules than glibmm and skeleton (libsomething).
G.1.2.2. Other meson.build files
Next we must adapt the other meson.build files:
-
skeleton/meson.build: Perhaps not much to change here more than the global name substitutions.
-
skeleton/skeletonmm/meson.build
- defs_basefiles
If we have more .defs and docs.xml files, we add them here.
- hg_ccg_basenames
We must mention all of our .hg and .ccg files here.
- extra_cc_files, extra_h_files
Any additional hand-written .h and .cc source files go here.
G.1.2.3. Δημιουργία αρχείων .hg και .ccg
Πρέπει τώρα να δημιουργήσουμε τα πρώτα μας αρχεία .hg και .ccg, για να συσκευάσουμε ένα από τα αντικείμενα στη βιβλιοθήκη C. Ένα ζεύγος παραδείγματος πηγαίων αρχείων που ήδη υπάρχει: skeleton.ccg και skeleton.hg. Δημιουργήστε αντίγραφα αυτών των αρχείων όπως χρειάζεται.
Στην ενότητα .hg and .ccg files μπορείτε να μάθετε για τη χρησιμοποιούμενη σύνταξη σε αυτά τα αρχεία.