Lazarus Packages/ja

From Lazarus wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) français (fr) 日本語 (ja) português (pt) русский (ru) slovenčina (sk)

Lazarusのパッケージシステムの概要

lazarusパッケージとは?

lazarusパッケージとは、ユニットやコンポーネントを集めたものです。それには、どのようにコンパイルできるかという情報や、IDEや他のパッケージや、プロジェクトで、どうやって使うか、といった情報が含まれています。Delphiと大きく違うところは、パッケージはOSに依存したライブラリではないということです。(Delphiの場合、パッケージは特定のアプリケーションやIDEで使われるために特別にコンパイルされたライブラリで、Delphiパッケージは、コンパイラマジックを必要としています。fpcは現在の時点では、この特定のOS環境に依存するコンパイラマジックを受け付けません。)

現在、Free Pascalコンパイラは、スタティックパッケージしかサポートしません。ですから、パッケージをインストールしたり、アンインストールするときには、コンパイルして、IDEを再起動しなくてはなりません。

lazarusパッケージは名前とバージョンによって識別され、区別されます。


よくある質問

Q: 私はパッケージをインストールする必要はありますか?

A: 必要としているパッケージが、IDEのコンポーネントパレットのコンポーネントのように、設計時の何らかの機能を含んでいるときに、インストールすればよいでしょう。それらを使わないときは、パッケージはインストールする必要はありません。プロジェクトでパッケージを使いたくなければ、インストールしないでください。


Q: パッケージをインストールしました。しかし、IDEがユニットを見つけてくれません。

A: パッケージをインストールする、ということは、パッケージがIDEに統合されたことを意味します。あなたのプロジェクトに、ではありません。それらは、別々のものです。あなたのプロジェクトでパッケージを使いたいときは、メニューからProject -> Project Inspector -> Add -> New Requirement を選択してください。プロジェクトにIDEのおまけ機能が必要でなくなったら、パッケージをアンインストールしてください。

クイックスタート

パッケージシステムを使う操作方法です。次のようにしてください。

新規のパッケージを作る:

  • File->New... -> Package -> Standard Package
  • パッケージエディタが開きます。
  • 左上のSaveボタンを使います。
  • 'enviroment options'の中で設定したあなたの名前付けによっては、IDEは小文字で保存するように尋ねるかもしれませんが、yesとしてください。

これでめでたく最初のパッケージを作ることができました。

新しいコンポーネントを追加する:

  • Addボタンを押す -> New component
  • 先祖型コンボボックスからコンポーネントを選びます。たとえば、TBevelなど。
  • Okをクリック
  • パッケージにファイルが追加され、エディタ内に表示されます。
  • パッケージエディタの上にある'install'ボタンをクリックすると、パッケージがインストールされます。
  • Lazarusはパッケージを保存し、IDEをリビルドするかどうか尋ねます。Yesを選択してください。
  • パッケージは静的にリンクされて、IDEの再起動が必要になります。
  • Lazarusが再起動し、コンポーネントパレットに新しいコンポーネントが表示されます。(この例でいうと、「TBevel1」がAdditionalページに表示されるでしょう。).
  • もし、コンポーネントパレットに新しいコンポーネントが見つからないなら、おそらく、新しくコンパイルしたLazarusを動かしていないからです。Lazarusの再構築の設定は Environment -> Environment options -> Files -> Lazarus directory でおこなうことができます。

Lazarusを直接呼び出すほかに、startlazarusコマンドもつ変えます。これは新しく作ったLazarsuをスタートします。たとえば、Lazarusの実行ファイルが ~/.lazarusにあり、Lazarusがインストールされたディレクトリに書き込み権限がない場合に使います。

これでめでたく最初のコンポーネントを入れた最初のパッケージをインストールできました。

パッケージのためのIDEメニュー

  • File->New... -> Package -> Standard Package

Creates a new package.

  • Project -> Project Inspector
 Here you can see, what packages are required by the currently open project.
 You can add new dependencies and remove unneeded ones.
  • Run -> Compiler options -> Inherited
 Here you can see what compiler options are inherited from which package.

Components ->

 - 'Open package'
   A dialog shows all open packages with their state.
   
 - 'Open package file'
   Open a .lpk file
 - 'Open package of current unit'
   Open the .lpk file, that belongs to the file in the source editor
   
 - 'Open recent package'
   Open a recently open package file (lpk file)
 - 'Add active unit to a package'
   Adds the unit in the source editor to a package
   
 - 'Package Graph'
   The package graph shows all open packages and their dependencies.
 - 'Configure installed packages'
   Edit the list of packages installed in the IDE. Install or uninstall several packages at once.

Project -> Project Inspector

 Here you can see and edit all packages used by the project.

手順

Each Lazarus package has a .lpk file. A package is identified by its name and its version. The name must correspond to the lpk filename. For example:

Name: Package1, Version: 1.0, Filename: /home/.../package1.lpk.

  • The IDE automatically creates the main source file (package1.pas). See below. The lpk file contains information about the required packages, the files it uses, how to compile them, and what is needed to use the package by other packages/projects. The directory where the lpk file is, is called the "package directory".
  • The IDE maintains a list of all package files (<config directory>/packagelinks.xml). Everytime a package is opened in the IDE it will be added to this list. When a package is opened, the IDE automatically opens all required packages via this list.
  • There are three base packages: FCL, LCL and SynEdit. These are parts of the IDE and so they are autocreated, readonly and have no lpk file.
  • Normally a package has a source directory with some pascal units. And normally the lpk file will be there too. A package has also an output directory. Default is the subdirectory 'lib/$(TargetCPU)-$(TargetOS)/' in the package directory.
  • Before a package is compiled the IDE checks all required packages and if they need update and have the auto update flag, they are compiled first. Then the IDE creates the package main source file. If the lpk file was package1.lpk, then the main source file is package1.pas. This file contains all units in the uses section plus a 'Register' procedure, which is called in the intialization section.

For example:

This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install
the package GTKOpenGL 1.0.
unit GTKOpenGL; interface uses GTKGLArea, GTKGLArea_Int, NVGL, NVGLX, LazarusPackageIntf; implementation procedure Register; begin RegisterUnit('GTKGLArea', @GTKGLArea.Register); end; initialization RegisterPackage('GTKOpenGL', @Register) end.
  • Then the compiler is called and the package is compiled to the output directory.
  • After successful compilation the state file is created. The state file is put into the output directory. It has the name <packagename>.compiled and contains the information, how the package was compiled. This state file is used by the IDE to check if update is needed.

For example: gtkopengl.compiled:

<?xml version="1.0"?>
<CONFIG>
  <Compiler Value="/usr/bin/ppc386" Date="781388725"/>
  <Params Value=" -Rintel -S2cgi -CD -Ch8000000 -OG1p1
    -Tlinux -gl -vewnhi -l -Fu../../../lcl/units
    -Fu../../../lcl/units/gtk -Fu../../../packager/units
    -Fu. -FElib/ gtkopengl.pas"/>
</CONFIG>
  • The IDE opens all needed packages automatically. This means, it opens all installed packages, all packages marked for installation (auto install), all packages with an open Editor, all packages required by the project and all packages required by one of the other packages. Unneeded packages are automatically unloaded, when the IDE becomes idle.
  • The IDE never opens two packages with the same name at the same time. When the user opens another package file with the same name as an already opened package the IDE will ask to replace the old one.
  • The IDE maintains two extra sets of packages: The 'installed' packages and the 'auto install' packages. The auto install packages will be linked into the IDE on next compile. It creates two new files in the config directory: staticpackages.inc and idemake.cfg. Then it calls 'make ide OPT=@/path/to/your/config/idemake.cfg' to compile itself.

ヒントと例題

Please add any hints, tips or gotchas here.

  • To rename a package, use 'save as'.

Example

I will use the tiOPF framework as an example  The tiOPF has the
following directory layout, due to the fact that it compiles for FPC,
Delphi 5-7, D2005 and D2006.

Source                <= full path \Programming\3rdParty\tiOPF\Source
 \Compilers
    \Delphi7          <= Delphi 7 package files live here
    \D2005
    \FPC              <= the tiOPF.lpk lived here
 \Core                <= core unit files
 \Options             <= optional unit file for extra features
 \GUI

Using this example, I included in the "Options - Usage - Units"
editbox the following paths:
"$(PkgOutDir);..\..\Core;..\..\Options;..\..\GUI" which will be added
to whatever project uses this package.

貢献している人とコメント

This page has been converted from the epikwiki version.