16. make all, make clean
phony(ダミー)のダーゲッ
ト:allとcleanはファイルでな
い
“make all”で,mainを生成する
という意味のターゲット
“make clean”で,不要なファ
イルを削除するという意味の
ターゲット
ファイル名ではないターゲット
にはphony targetを利用する
.PHONY: all clean
all: main
clean:
rm -f main main.o myfunc.o
17. docker composeを利用する
起動する
$ cd 10_01_make
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
コードをチェックアウト
$ git checkout main
26. makeでlatexコンパイル
platex thesis.tex
dvipdfmx thesis.dvi
$ docker compose exec mylatex make
platex thesis.tex
This is e-pTeX, Version 3.141592653-p4.1.0-230214-2.6 (utf8.euc) (Te
restricted ¥write18 enabled.
entering extended mode
(./thesis.tex(guessed encoding #3: UTF-8 = utf8)
pLaTeX2e <2023-02-14>+1 (based on LaTeX2e <2022-11-01> patch level 1
L3 programming layer <2023-05-05>
(/usr/local/texlive/2023/texmf-dist/tex/platex/base/jarticle.cls(gue
Document Class: jarticle 2020/09/30 v1.8f Standard pLaTeX class
(/usr/local/texlive/2023/texmf-dist/tex/platex/base/jsize10.clo(gues
(/usr/local/texlive/2023/texmf-dist/tex/latex/l3backend/l3backend-dv
No file thesis.aux.
(./intro.tex(guessed encoding #6: UTF-8 = utf8)) (./method.tex(guess
Output written on thesis.dvi (1 page, 840 bytes).
Transcript written on thesis.log.
dvipdfmx thesis.dvi
thesis.dvi -> thesis.pdf
[1]
15976 bytes written
$
27. よくあるmakeの使い方
nmake all または make
• すべてビルド
nmake test
• テストコードを実行
nmake debug
• デバッグオプション(-g)をつけ
てコンパイル
nmake doc
• ドキュメントを作成
nmake clean
• 生成されたファイルを削除
nsudo make install
• システムにインストール
• (通常は)root権限が必要
nsudo make uninstall
• インストールしたファイルをシス
テムから削除
• (ファイルを記憶しておくなど特
殊処理が必要)
28. docker composeを利用する
起動する
$ cd 10_03_make_test
$ docker compose build
$ docker compose up -d
確認する
$ docker compose ps
停止する
$ docker compose down
29. .PHONY: clean test coverage
test:
python -m unittest test_compute.py
coverage:
coverage run test_compute.py
coverage report
coverage html
coverage xml
clean:
rm -rf *.pyc __pycache__/
rm -rf htmlcov/ coverage.xml .coverage
$ docker compose exec mypython make test
python -m unittest test_compute.py
..............
----------------------------------------
Ran 14 tests in 0.000s
OK
$ docker compose exec mypython make coverage
coverage run test_compute.py
..............
-----------------------------------------
Ran 14 tests in 0.001s
OK
coverage report
Name Stmts Miss Cover
-------------------------------------
compute.py 29 2 93%
test_add.py 26 1 96%
test_compute.py 5 0 100%
test_mult.py 26 1 96%
-------------------------------------
TOTAL 86 4 95%
coverage html
Wrote HTML report to htmlcov/index.html
coverage xml
Wrote XML report to coverage.xml
$ docker compose exec mypython make clean
rm -rf *.pyc __pycache__/
rm -rf htmlcov/ coverage.xml .coverage
$
make testでテストコードを実行する例
テスト実行
カバレッ
ジ計測
不要ファイルの削除
34. GNU autotools
nconfigureスクリプトからMakefileを生成
• 手順
./configure
make all
sudo make install
n複数のツール群
• aclocale, autoheader, autoconf, automake, …
• configureスクリプトの生成までは長い道程
n使っているOSS
• Apache
• FFmpeg
• Perl
• etc
GNU autoconf and automake process for generating
makefilesJdthood - Own work, based
on https://commons.wikimedia.org/wiki/File:Autoconf.svg
CC BY-SA 3.0
35. CMake
n設定ファイルCMakeLists.txtから色々と生成できる
• Makefile, Xcodeプロジェクトファイル,Visual Studioプロジェクトファイル
• GUI版もある
n現在多数のOSSで使われている
• OpenCV, PCL, ROS
• LLVM/Clang, ITK/VTK, KDE
• Blender
• etc
Logo di CmakeCmake team. The original uploader was Francesco
Betti Sorbelli at Italian Wikipedia.. Vectorized by Magasjukur2 -
File:Cmake.jpg
CC BY 2.0
36. ディレクトリ構成
n トップディレクトリ
• 設定ファイル
• プロジェクト全体のCMakeLists.txt
• 各種ディレクトリ
n srcディレクトリ
• 各種ソースがある
• 個別のCMakeLists.txt
• ソースファイル
n buildディレクトリ
• 最初は存在しない.cmakeで作成される
• ソースがここにコピーされて,ビルドが実行される
• ここでmakeを実行
• 不要になれば削除
39. $ docker compose exec myopencv cmake -S src/ -B build/
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local (found version "4.5.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/build
$
cmakeを実行 cmake
が作成
-Sでソースファイルの
パスを指定
-Bでビルド用のパスを
指定
Cコンパイラを
自動検索
C++コンパイ
ラを自動検索
パッケージを
自動検索