Η δομή δημιουργίας

Η παραγωγή του πηγαίου κώδικα για μια API συσκευαστή τεχνοτροπίας gtkmm απαιτεί τη χρήση εργαλείων όπως gmmproc και generate_wrap_init.pl. Θεωρητικά, μπορείτε να γράψετε τα δικά σας αρχεία δόμησης για να χρησιμοποιήσετε κατάλληλα, αλλά μια πολύ καλύτερη επιλογή είναι να χρησιμοποιήσετε την παρεχόμενη υποδομή δημιουργίας από την ενότητα mm-common. Για να ξεκινήσετε, βοηθά πολύ η επιλογή υπαρχουσών ενοτήτων σύνδεσης ως ένα παράδειγμα για να δείτε.

Για παράδειγμα, ας θεωρήσουμε ότι πακετάρουμε μια βιβλιοθήκη C που λέγεται libsomething. Παρέχει μια API με βάση GObject με επώνυμους τύπους, για παράδειγμα, SomeWidget και SomeStuff.

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.

  $ git clone git://git.gnome.org/mm-common
  $ cp -a mm-common/skeletonmm libsomethingmm

This provides a directory structure for the source .hg and .ccg files and the generated .h and .cc files, with filelist.am Automake include files that can specify the various files in use, in terms of generic Automake 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 generated and hand-written .h and .cc files.

        • private: Contains generated *_p.h 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
A number of the skeleton files must still be filled in with project-specific content later.

Σημειώστε ότι τα αρχεία που τελειώνουν σε .in θα χρησιμοποιηθούν για τη δημιουργία αρχείων με το ίδιο όνομα, αλλά χωρίς το επίθεμα .in, αντικαθιστώντας μερικές μεταβλητές με τις ενεργές τιμές κατά τη διάρκεια του σταδίου διαμόρφωσης.

G.1.2. Τροποποίηση αρχείων δόμησης

Τώρα επεξεργαζόμαστε τα αρχεία για να προσαρμόσουμε στις ανάγκες μας. Μπορείτε να προτιμήσετε τη χρήση ενός βοηθήματος πολλαπλού αρχείου αναζήτησης-αντικατάστασης για αυτό, όπως regexxer. Σημειώστε ότι σχεδόν όλα τα παρεχόμενα αρχεία με το πηγαίο δένδρο σκελετού περιέχουν κείμενο δεσμευτικού θέσης. Έτσι, οι αντικαταστάσεις πρέπει να εκτελεστούν καθολικά και να μην περιοριστούν στα αρχεία Automake και Autoconf.

Όλες οι αναφορές της skeleton πρέπει να αντικατασταθούν από το σωστό όνομα της βιβλιοθήκης C που συσκευάζεται, όπως "something" ή "libsomething". Με τον ίδιο τρόπο, όλα τα στιγμιότυπα της SKELETON πρέπει να αντικατασταθούν από "SOMETHING" ή "LIBSOMETHING" και όλες οι εμφανίσεις της Skeleton να αλλαχτούν σε "Something".

Παρόμοια, αντικαταστήστε όλα τα στιγμιότυπα της Joe Hacker με το όνομα του σκοπούμενου κατόχου πνευματικών δικαιωμάτων, που είσαστε προφανώς εσείς. Κάντε το ίδιο για τη διεύθυνση αλληλογραφίας [email protected].

G.1.2.1. configure.ac

In configure.ac,

  • The AC_CONFIG_SRCDIR() line must mention a file in our source tree. We can edit this later if we don't yet know the names of any of the files that we will create.
  • It is common for binding modules to track the version number of the library they are wrapping. So, for instance, if the C library is at version 1.23.4, then the initial version of the binding module would be 1.23.0. However, avoid starting with an even minor version number as that usually indicates a stable release.
  • The AC_CONFIG_HEADERS() line is used to generate two or more configuration header files. The first header file in the list contains all configuration macros which are set during the configure run. The remaining headers in the list contain only a subset of configuration macros and their corresponding config.h.in file will not be autogenerated. The reason for this separation is that the namespaced configuration headers are installed with your library and define publically visible macros.
  • The AC_SUBST([SOMETHINGMM_MODULES], ['...']) line may need to be modified to check for the correct dependencies.
  • The AC_CONFIG_FILES() block must mention the correct directory names, as described above.

G.1.2.2. Αρχεία Makefile.am

Next we must adapt the various Makefile.am files:

  • In skeleton/src/Makefile.am we must mention the correct values for the generic variables that are used elsewhere in the build system:

    binding_name

    The name of the library, such as libsomethingmm.

    wrap_init_flags

    Additional command-line flags passed to the generate_wrap_init.pl script, such as the C++ namespace and the parent directory prefix of include files.

  • In skeleton/skeletonmm/Makefile.am we must mention the correct values for the generic variables that are used elsewhere in the build system:

    lib_LTLIBRARIES

    This variable must mention the correct library name, and this library name must be used to form the _SOURCES, _LDFLAGS, and _LIBADD variable names. It is permissible to use variables substituted by configure like @SOMETHINGMM_API_VERSION@ as part of the variable names.

    AM_CPPFLAGS

    The command line options passed to the C preprocessor.

    AM_CXXFLAGS

    The command line options passed to the C++ compiler.

G.1.2.3. Δημιουργία αρχείων .hg και .ccg

Πρέπει τώρα να δημιουργήσουμε τα πρώτα μας αρχεία .hg και .ccg, για να συσκευάσουμε ένα από τα αντικείμενα στη βιβλιοθήκη C. Ένα ζεύγος παραδείγματος πηγαίων αρχείων που ήδη υπάρχει: skeleton.ccg και skeleton.hg. Δημιουργήστε αντίγραφα αυτών των αρχείων όπως χρειάζεται.

Πρέπει να αναφέρουμε όλα τα αρχεία μας .hg και .ccg στο αρχείο skeleton/src/filelist.am, τυπικά στη μεταβλητή files_hg.

Οποιαδήποτε πρόσθετα μη δημιουργούμενα πηγαία αρχεία .h και .cc μπορεί να τοποθετηθούν στο skeleton/skeletonmm/ και καταχωρίζονται στο skeleton/skeletonmm/filelist.am, τυπικά στις μεταβλητές files_extra_h και files_extra_cc.

Στην ενότητα .hg and .ccg files μπορείτε να μάθετε για τη χρησιμοποιούμενη σύνταξη σε αυτά τα αρχεία.