|
|
|
makeの作成 |
会員登録(SSL) 会員専用(SSL) |
|
基礎: Makefile 自分で作るMakefile $ gcc -c detail.cpp $ gcc -o test test.cpp detail.o のMakefileを作る 最初だけ詳しく説明を載せます。とは言っても私はMakeの専門家ではなく専門的な問題は他の書かgmakeのソースファイルを当たってください。 それでは始めます。makeは最初の依存関係だけを見ます。最初の例では all: test.cpp detail.o の部分です。allに対してtest.cpp detail.oとが依存しているとMakeは理解します。それで、今度はtest.cppを探しますが見当たりません。その次はdetail.oを探します。detail.oはdetail.cppに依存していてdetail.oを作るために $(CXX) -c detail.cpp を実行します。そして、最終的に $(CXX) test.cpp detail.o -o test を実行することが分かります。個別に一部分を実行したい時には make detail.o meke clean ということになります。抜けは無いと思いますが・・・?
同じく、このようにも書くことができます。
今度は、$@ $< $^を使ってみよう
ちょっと複雑になる ここでは、記号$@ $< $?が難しいですが、fileの修正・変更をした時など勝手に依存関係を調査してくれるということです。 .cpp.oは***.cppファイルから***.oを生成する時のコマンドです。 ${delete_SOURCES:.cpp=.o}は.cppの部分を.oに置き換えたものになります。
実践: MAKE 実際にやってみる! program(hello)は、hello_dataというデータファイルのパスが記入されているhello.confを読み込んだ後、hello_dataというファイルにアクセスしそのファイルに書かれている文字列を出力するプログラムで、実に単純であるがmakeを理解する上には格好のプログラムである。我ながら、すごいとは思わないが。
emacs hello.conf
hello.icoの説明はいらないだろう。 emacs hello_data
emacs hello.c
emacs Makefile
autoconf & automake
GTK2 を使用する場合は...茶色で示してあります。
helloworld.c
autom4te: configure.ac: no such file or directory autoscan: /usr/bin/autom4te failed with exit status: 1
autoscan.log configure.scan helloworld.c
# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) AC_INIT(helloworld.cpp, 1.0.0, ******@ryuuo.com) <---この部分 AC_CONFIG_SRCDIR([helloworld.c]) AC_CONFIG_HEADER([config.h]) ### この部分は後で追加する #AM_INIT_AUTOMAKE(helloworld, 1.0.0, no-define) ### # Checks for programs. AC_PROG_CC # -------------- gtk+ を使用する場合 AM_PATH_GTK(1.2.0, CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS", AC_MSG_ERROR(GTK+1.2.0 not found.)) AM_PATH_GTK_2_0(2.0.0, CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS", AC_MSG_ERROR(GTK+2.0.0 not found.)) # -------------- # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_OUTPUT([Makefile]) <---この部分 --------------------------- end --------------------------
. .. autom4te.cache autoscan.log config.h.in configure.in helloworld.c
. AUTHORS NEWS autom4te.cache config.h.in helloworld.c .. ChangeLog README autoscan.log configure.in bin_PROGRAMS = helloworld test helloworld_SOURCES = helloworld.c test_SOURCES = test.c INCLUDES = ${GTK_CFLAGS} helloworld_LDADD = ${GTK_LIBS} # autoconf & automake で 静的ライブラリを # リンカーに伝えるためには....... # $ g++ -o test test.c test_assist.o -lpthread # で、コンパイルしたい時には # test_LDADD = -lpthread # Makefile.am に関しての蘊蓄 # $ make distで、配付するtar.gzなどのファイルが生成されるが、このファイルには # ソースファイルとAUTHORS NEWS ChangeLog READMEのファイルしか梱包されない。 # その他のファイルを梱包するには、の説明です。 # EXTRA_DIST = example.sh # このように記述しておけば一緒に梱包してくれます。 # 次に考えるのがinstall場所です。 dist_bin_SCRIPTS = example.sh # このように記述すれば/usr/local/binにinstallしてくれます。 # 次に考えるのがinstallする場所の変更です。 # 最終的な記述は EXTRA_DIST = example.sh example_dir = ${PREFIX}/example dist_example_SCRIPTS = example.sh # その他、SCRIPTS(プライマリというそうです)に使える変数には # DATA HEADERS MANS TEXINFOS PROGRAMSLIBRAIES などだ。 -------------------- end ---------------------- --------------- configure.in の修正 ----------------- AC_CONFIG_HEADER([config.h]) を AM_CONFIG_HEADER([config.h]) に書き変え また、 AM_INIT_AUTOMAKE(helloworld, 1.0.0, no-define) を追加し --------------- end ----------------- ===== gtk+ を使用する場合 ===== $ cp /usr/share/aclocal/gtk.m4 ./acinclude.am $ cp /usr/share/aclocal/gtk-2.0.m4 ./acinclude.am
rpm -qa | grep gtk2-devel を確認してみては? # Configure paths for GTK+ # Owen Taylor 1997-2001 dnl AM_PATH_GTK_2_0([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]]) AM_PATH_GTK(1.2.0, CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS", AC_MSG_ERROR(GTK+1.2.0 not found.)) AM_PATH_GTK_2_0(2.0.0, CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS", AC_MSG_ERROR(GTK+2.0.0 not found.)) dnl Test for GTK+, and define GTK_CFLAGS and GTK_LIBS, if gthread is specified in MODULES, ------------------- end ---------------------
configure.in: installing `./install-sh' configure.in: installing `./mkinstalldirs' configure.in: installing `./missing' Makefile.am: installing `./INSTALL' Makefile.am: installing `./COPYING' Makefile.am: installing `./depcomp'
. ChangeLog NEWS autoscan.log depcomp mkinstalldirs .. INSTALL README config.h.in helloworld.c AUTHORS Makefile.am aclocal.m4 configure install-sh COPYING Makefile.in autom4te.cache configure.in missing $ ./configure $ make $ make install で、上手く行くと思います。 参考にしたWebPage: http://sources.redhat.com/automake/automake.html |