文書の表示以前のリビジョンバックリンク文書の先頭へ この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。 ====== Autoconf - configure スクリプトの生成 ====== Autoconf は、さまざまなシステムに適応するようにソースコードパッケージを自動的に設定するシェルスクリプトを作成するためのツールです。\\ Autoconf によって生成された設定スクリプトは、実行時に Autoconf から独立しているため、ユーザーは Autoconf をインストールしている必要はありません。\\ \\ 各種コマンドは以下のパッケージに含まれる。\\ <code> $ sudo dnf install automake </code> ===== ビルドまでの流れ ===== <html> <style> table { font-size: 12px; } table .col1 { width: 250px; } table pre { margin: 0; padding: 0.2em 0.2em; } table p { margin: 0 0 0.5em 0; } table .col2 { width: 411px; } table .row2 { height: 113px; } table .row3 { height: 52px; } table .row4 { height: 70px; } table .row5 { height: 100px; } table .row8 { height: 68px; } img { max-width: 411px; } </style> <script> /*jQuery(function() { // toc をフロー図の上に重ねて、フロー図の幅が縮まない様にする jQuery("#dw__toc > div").css({"position": "absolute", "background-color": "white"}); // Dokuwiki が生成する不要な列を削除 var row = 0; jQuery("#autoconf_workflow > div > table > tbody > tr").each(function() { if (row >= 1) { jQuery(this).children(':last').remove(); } row++; }); // rowspan でフロー図の列を連結する jQuery("#autoconf_workflow > div > table > tbody > tr.row1 > td.col2").attr('rowspan', row); });*/ </script> </html> <WRAP #autoconf_workflow> ^ 手順 ^ 説明 ^ フロー図 ^ | **[[#step1makefileam_の作成|STEP1: Makefile.am の作成]]** | <WRAP prewrap 100%><code> $ touch INSTALL NEWS README LICENSE AUTHORS ChangeLog $ vi Makefile.am $ vi src/Makefile.am </code></WRAP> | {{:c_cpp:autoconf_workflow.png?411|Autoconf Workflow}} | | **[[#step2autoscan_の実行|STEP2: autoscan の実行]]** | <code>$ autoscan</code>カレントディレクトリやサブディレクトリの内容を元に configure.scan が生成される。<code> $ mv configure.scan configure.ac </code> configure.scan を configure.ac にリネーム。 | | | **[[#step3configureac_の修正|STEP3: configure.ac の修正]]** | <code> $ vi configure.ac </code>configure.ac の内容を修正する。 | | | **[[#step4autoheader_の実行|STEP4: autoheader の実行]]** | <code> $ autoheader </code>configure.ac の内容を元に config.h.in が生成される。 | | | **[[#step5aclocal_の実行|STEP5: aclocal の実行]]** | <code> $ aclocal </code>configure.ac の内容を元に aclocal.m4 が生成される。 | | | **[[#step6autoconf_の実行|STEP6: autoconf の実行]]** | <code> $ autoconf </code>configure.ac と aclocal.m4 の内容を元に configure が生成される。 | | | **[[#step7automake_の実行|STEP7: automake の実行]]** | <code> $ automake --add-missing </code>configure.ac の内容を元に Makefile.in が生成される。 | | | **[[#step8configuremake_の実行|STEP8: ./configure; make の実行]]** | <code> $ ./configure; make </code>configure によって環境に応じた Makefile が生成されて、make でビルドが開始される。 | | </WRAP> ※開発者ではない一般ユーザーは、STEP8 で ./configure; make のみでビルドを行う。\\ ===== ディレクトリ構成 ===== 以下の構造を想定している。 <code> autoconf_sample (directory) +-AUTHORS (file) +-ChangeLog (file) +-INSTALL (file) +-LICENSE (file) +-Makefile.am (file) +-NEWS (file) +-README (file) +-configure.ac (file) +-src (directory) +hello.cpp (file) </code> ===== C++ サンプルの準備 ===== ここでは wxGTK アプリの hello.cpp をサンプルとする。\\ <file cpp src/hello.cpp> #include <vector> #include <iterator> #include <iostream> #include <wx/wx.h> #include <stdbool.h> #include "config.h" using namespace std; // 定番のこんにちは世界 class HelloApp : public wxApp { public: bool OnInit(); }; IMPLEMENT_APP(HelloApp) bool HelloApp::OnInit() { std::vector<int> intVec; // intの vector を宣言 intVec.push_back(10); // いくつかの値を追加 intVec.push_back(20); intVec.push_back(30); std::copy(intVec.begin(), intVec.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << std::endl; //ここから始まる wxFrame *frame = new wxFrame((wxFrame*)NULL, -1, "Hello World !!"); frame->Show(true); //フレームの表示 SetTopWindow(frame); //トップウィンドウに設定 return true; } </file> ===== STEP1: Makefile.am の作成 ===== 空ファイルでも構わないので、INSTALL、NEWS、README、LICENSE、AUTHORS、ChangeLog のファイルを準備する。\\ <WRAP prewrap 100%><code> $ touch AUTHORS ChangeLog INSTALL LICENSE NEWS README </code></WRAP> Makefile.am を作成する。\\ <code> $ vi Makefile.am </code> <file autoconf Makefile.am> # 作成する実行ファイル名 bin_PROGRAMS = hello # 実行ファイルのソースコード hello_SOURCES = src/hello.cpp # C++コンパイラオプション test_CXXFLAGS = -g </file> ===== STEP2: autoscan の実行 ===== ソースコードと Makefile.am が置かれたディレクトリで autoscan を実行する。\\ <code> $ autoscan </code> autoscan はソースコードツリーを調べて、configure.scan という Autoconf の設定ファイルの雛形を生成する。 <file autoconf configure.scan> # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) AC_CONFIG_SRCDIR([src/hello.cpp]) AC_CONFIG_HEADERS([config.h]) # Checks for programs. AC_PROG_CC AC_PROG_CXX # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL # Checks for library functions. AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT </file> configure.scan を configure.ac にリネームする。\\ <code> $ mv configure.scan configure.ac </code> ===== STEP3: configure.ac の修正 ===== <code> $ vi configure.ac </code> <file autoconf configure.ac> # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([hello],[1.0],[tomoyan@tomoyan.net]) AC_CONFIG_SRCDIR([src/hello.cpp]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([1.16 subdir-objects foreign]) # Checks for programs. AC_PROG_CC AC_PROG_CXX # Checks for libraries. AM_OPTIONS_WXCONFIG reqwx=3.0.4 AM_PATH_WXCONFIG($reqwx, wxWin=1) if test "$wxWin" != 1; then AC_MSG_ERROR([ wxWidgets must be installed on your system. Please check that wx-config is in path, the directory where wxWidgets libraries are installed (returned by 'wx-config --libs' or 'wx-config --static --libs' command) is in LD_LIBRARY_PATH or equivalent variable and wxWidgets version is $reqwx or above. ]) fi CPPFLAGS="$CPPFLAGS $WX_CPPFLAGS" CXXFLAGS="$CXXFLAGS $WX_CXXFLAGS_ONLY" CFLAGS="$CFLAGS $WX_CFLAGS_ONLY" LIBS="$LIBS $WX_LIBS" # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL # Checks for library functions. AC_CONFIG_FILES([Makefile]) AC_OUTPUT </file> ===== STEP4: autoheader の実行 ===== configure.ac の内容を元に config.h.in が生成される。\\ <code> $ autoheader </code> ===== STEP5: aclocal の実行 ===== configure.ac の内容を元に aclocal.m4 が生成される。\\ <code> $ aclocal </code> ===== STEP6: autoconf の実行 ===== configure.ac と aclocal.m4 の内容を元に configure が生成される。\\ <code> $ autoconf </code> ===== STEP7: automake の実行 ===== configure.ac の内容を元に Makefile.in と src/Makefile.in が生成される。\\ <code> $ automake --add-missing configure.ac:12: installing './compile' configure.ac:9: installing './install-sh' configure.ac:9: installing './missing' Makefile.am: installing './depcomp' </code> ===== STEP8: ./configure; make の実行 ===== configure によって環境に応じた Makefile が生成されて、make でビルドが開始される。\\ <code> $ ./configure; make checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking whether make supports the include directive... yes (GNU style) checking dependency style of gcc... gcc3 checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking dependency style of g++... gcc3 checking for wx-config... /usr/bin/wx-config checking for wxWidgets version >= 3.0.4... yes (version 3.0.4) checking for wxWidgets static library... no checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for stdbool.h that conforms to C99... yes checking for _Bool... yes checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating Makefile config.status: creating config.h config.status: config.h is unchanged config.status: executing depfiles commands make all-am make[1]: ディレクトリ '/home/tomoyan/my_projects/autoconf_sample' に入ります depbase=`echo src/hello.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\ g++ -DHAVE_CONFIG_H -I. -I/usr/lib64/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -g -O2 -MT src/hello.o -MD -MP -MF $depbase.Tpo -c -o src/hello.o src/hello.cpp &&\ mv -f $depbase.Tpo $depbase.Po g++ -g -O2 -o hello src/hello.o -pthread -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_webview-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_qa-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 make[1]: ディレクトリ '/home/tomoyan/my_projects/autoconf_sample' から出ます </code> ===== hello の実行 ===== <code> $ ./hello 10 20 30 </code> ===== 参考文献 ===== [[https://www.gnu.org/software/autoconf/manual/autoconf.html|Autoconf]]\\ [[http://web.sfc.wide.ad.jp/~sagawa/gnujdoc/autoconf-2.59/index.html|Autoconf: Autoconf-2.59(日本語訳)]]\\ [[https://sourceware.org/autobook/|GNU Autoconf, Automake and Libtool]]\\ [[https://qiita.com/kagemiku/items/5aed05f7bd70d8035f54|Autotoolsを使ってプロジェクトのMakefileを生成する]]\\ c_cpp/autoconf.txt 最終更新: 2023/09/27 05:30by ともやん