Your SlideShare is downloading. ×
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

GNU Make, Autotools, CMake 簡介

9,251

Published on

2014/Aug/20 新增implicit rules和.PHONY說明 …

2014/Aug/20 新增implicit rules和.PHONY說明
2014/Jul/19 Fix minor error
2014/Jul/12 Fix minor error

Published in: Technology
0 Comments
93 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
9,251
On Slideshare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
291
Comments
0
Likes
93
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. GNU Make, Autotools, CMake ⡆௓ Wen Liao
  • 2. Disclaimer ᢞᙳ∦㈨ᩱⅭస⪅ᩚ⌮㈨ᩱཬಶேពぢ䠈ἄ᭷⥂ 㐣ᄫㅽ☜ㄆ䠈ㄳㆫ⪅⮬⾜᩵㓃
  • 3. ┠ᶆ ● ⡆௓GNU Make, Autotools, ࿴CMake ○ Autotools࿴CMake㒊௷ᴟᗘ⡆௓
  • 4.  ヨ⎔ቃ
  • 5. Outline ● GNU Make ● Autotools ● CMake ● ཨ⪃㈨ᩱ ● Q & A
  • 6. ஦ඛ‽ഛ ● Ⅽ஢ᝍⓗ⏕άᖾ⚟⨾⁹䠈ㄳ☜ㄆ⦅㍴ჾᨭ᥼㢷 ♧✵ⓑᏐඖ࿴<tab>Ꮠඖ! geany: <tab> trailing space vim:
  • 7. 㜝᪊GNU Make ● man make ○ GNU make utility to maintain groups of programs ○ ???
  • 8. ┤᥋┳౛Ꮚ ᛠ㯟⦅㆞?
  • 9. ⡆ႝ䠈gcc hello.c
  • 10. ຍ☞䠈㏺ಶᛠ㯟⦅㆞?
  • 11. GG! 㑏せຍinclude Path
  • 12. 㑣㯟ୖⓒಶ᷐᱌ᛠ㯟㎨䠛ᡴ฿Ṛ䠛
  • 13. ᑙ᱌᷐᱌㔞኱⦅㆞ⓗၥ㢟 ● ᡃ⬟୙⬟ᡴ୍⾜ᣦ௧ᑵᖳᡃ⮬ື⦅㆞? ● ᡃ⬟୙⬟ྈ⦅㆞᭦ື㐣ⓗ᷐᱌? ○ ໟྵᨵ஢*.h᷐᱌ᑞ᠕*.c㒔ྍ௨⮬ື㔜⦅ ● ྍ୙ྍ௨᭷ἄ᭷㟰άⓗ⦅㆞⤌ែ? ○ タᐃdebug mode㑏᫝release mode ○ タᐃ⦅㆞ჾ㑅㡯 ○ Compile timeᣦᐃᕧ㞟 ■ -DMY_VAR=1 ○ ...
  • 14. Yes You Can!
  • 15. 㜝᪊GNU Make ● man make ○ The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them. ○ ⓑヰ: ༠ຓ⦅㆞ⓗ᫬ೃỴᐃ ■ 㑣㒊௷せ㔜⦅ ■ ᣦᐃ㔜᪂⦅㆞ⓗືస
  • 16. Hello Makefile target prerequisites recipe ୍ᐃせ<tab>㛤㢌! ௨ୗ᝟ἣ᭳ᇳ⾜recipe ● ᪂ቔ䠖target᷐᱌୙Ꮡᅾ ○ ㏻ᖖtarget᫝୍ಶ᷐᱌䠈ణ᫝㏺୙᫝ᚲせᲄ௳ ● ᭦᪂䠖prerequisites᷐᱌᭦ື᫬㛫ẚtarget᷐ ᱌㑏せ᪂
  • 17. ㄡ說Makefile୍ᐃせ⦅㆞᷐᱌? target prerequisites ୍㛤ጞྈ᭷Makefile䠈ୗmakeฟ⌧㘒ㄗ說↓ἲ產⏕dep_file 產⏕dep_fileᚋ᭳ᇳ⾜@echo Test 產⏕test_fileᑵ୙ᇳ⾜@echo Test ᭦᪂dep_file ᭦ື᫬㛫ᚋ᭳ᇳ⾜@echo Test recipe
  • 18. ᶞ≪target ● ➨୍ಶtarget✃Ⅽdefault target䠈ஓ᫝makeⓗ㐍ධ㯶䚹 ● @⾲♧୙せᢕᣦ௧༳ฟ䠈ྍ௨⦎⩦ᢕ௚ᣡᤶ┳┳䚹 ● $@ᒎ㛤ᚋ᫝targetⓗྡ✃
  • 19. ㄳẚᑞୖ㡫䠈やᐹ㡰ᗎ䟿
  • 20. ㆰᩝ ● タᐃ ○ VAR = VAL ○ VAR := VAL ○ VAL ?= VAL ○ VAR += VAL ○ ඼௚ᡃ୙᠐ⓗ ● タᐃ᫬ᶵ ○ ᷐᱌䠈㏻ᖖᑵ᫝Makefile內 ○ make ࿨௧ⓗཨᩝ ○ ⎔ቃㆰᩝ ● ྲྀ值 ○ $(VAR)
  • 21. VAR = VAL VAR := VAL VAL ?= VAL VAR += VAL
  • 22. ୕ᑠ䠛
  • 23. ㆰᩝタᐃ: 㐃ືᆺ = VAR1 ➨୍ḟタᐃ VAR2 ⓗ值࿴VAR1┦ྠ ༳ฟVAR2ⓗ內ᐜ VAR1 ➨஧ḟタᐃ ෌༳ฟVAR2ⓗ內ᐜ
  • 24. ඳḟVAR2ⓗ內ᐜ䠈᭳㞉VAR1ᨵㆰ
  • 25. ㆰᩝタᐃ䠖❧้⏕ᩀᆺ := ྈᨵ㏺⾜䠈ᢕ = ᨵᡂ :=
  • 26. ㆰᩝタᐃ: 㡸タᆺ ?=
  • 27. ㆰᩝタᐃ䠖ຍ☞ᆺ +=
  • 28. ᑠ⤖ タᐃ ⌮ゎ᪉ᘧ VAR = VAL 㐃ືᙧ VAR := VAL ❧༶⏕ᩀᙧ VAL ?= VAL 㡸タᙧ VAR += VAL ຍ☞ᙧ ඼௚ᡃ୙᠐ⓗ ୙᠐ⓗ୙▱㐨ᛠ㯟ゎ㔚
  • 29. 內ᘓㆰᩝ (⠇㗴) ྡ✃ ព⩏ $@ targetྡ✃ $^ ᡤ᭷ⓗprerequisitesྡ✃ $< ➨୍ಶprerequisiteྡ✃ ⏝㏵அ୍䠖 target: dep1.c inc.h test.h <tab> gcc -o $@ $< $? ẚtarget㑏᪂ⓗprerequisitesྡ✃
  • 30. ⠊౛ タᐃせ產⏕ⓗᇳ⾜᷐ タᐃせ⦅㆞ⓗ⛬ᘧ᷐ ⦅㆞ཨᩝ ᒎ㛤ㆰᩝ䠈౫ᒎ㛤ⓗ ㆰᩝ⦅㆞᷐᱌ Ύ㝖產⏕ⓗ᷐᱌つ๎
  • 31. ┠㗴ୗ᭷ཎጞ᷐࿴Makefile ⦅㆞᭷ᒎ㛤ㆰᩝ୪ᣦᐃᑞ ᠕᷐᱌┠㗴ୗ᭷ཎጞ᷐࿴ Makefile ᇳ⾜᷐ᕬ⥂產⏕ Ύ㝖ᇳ⾜᷐୪㔜᪂⦅㆞
  • 32. ᲄ௳ุ᪇⠊౛ LOGNAME᫝⎔ቃㆰᩝ!
  • 33. LOGNAME᫝⎔ቃㆰᩝ! ே⫗タᐃLOGNAME內ᐜ
  • 34. function⠇㗴 ● ㄒἲ ○ $(ภᩝྡ✃ ཨᩝ) ศ㢮 ภᩝྡ✃ 說᫂ ⠊౛ (ㄳ㈞฿Makefileᐿ !) イᜥ $(waring イᜥ) 㢷♧㆙࿌イᜥ௨ཬᑞ᠕ⓗ⾜⹰ $(warning Your gcc version is too old) $(error イᜥ) 㢷♧㘒ㄗイᜥ䚸ᑞ᠕ⓗ⾜⹰ᚋ⤖᮰ make conf=my_file $(error file $(conf) not found) Ꮠ୵ ⹦⌮ $(subst from,to,⹦⌮ᩥᏐ) Ꮠ୵᭰᥮,ᚋ㠃✵ⓑⅭཨᩝⓗ୍㒊௷ $(warning $(subst .c,.o,test.c hello.c)) $(patsubst pattern,᭰᥮ᩥᏐ,⹦⌮ᩥᏐ) patternᏐ୵᭰᥮,ᚋ㠃✵ⓑⅭཨᩝⓗ୍ 㒊௷䚹%௦⾲௵ព㛗ᗘⓗ௵ពᏐඖ䚹 $(warning $(patsubst t%.c,a%.o,test.c hello.c)) ඼௚ $(shell ࿨௧) ᇳ⾜࿨௧䠈ᅇബᩥᏐ⤖ᯝ $(warning $(shell ls /))
  • 35. 㐃⧰ᢏ ● OBJS=$(patsubst %.c,%.o,$(shell ls *.c))
  • 36. ᖖぢ㘒ㄗ䠖ẗಶrecipe ᇳ⾜≪ែ୙ᘏ⧰ 㐀ᡂⓗᝒ๻ ⠊౛䠖ᘓ❧୍ಶ┠㗴䠈㐍ධヱ┠㗴๓ᚋ ༳ฟ┠๓ᕤస┠㗴☜ㄆษ᥮┠㗴ᡂຌ
  • 37. 㛤⊼䠈ἄ᭷ษ᥮฿test┠㗴
  • 38. ✽Ꮿ┳ⓗ䠈ྍ௨┳฿make⹦⌮recipeⓗ ᪉ᘧ᫝產⏕᪂ⓗprocess䠈ᇳ⾜recipe䠈 ↛ᚋ⤖᮰ヱprocess $ strace -f make vfork(Process 8949 attached (waiting for parent) Process 8949 resumed (parent 8947 ready) ) = 8949 [pid 8949] execve("/bin/mkdir", ["mkdir", "-p", "test"], [/* 42 vars */]) = 0 <... wait4 resumed> [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 8949 --- SIGCHLD (Child exited) @ 0 (0) ---
  • 39. ᑠ⤖ ● GNU make: ༠ຓ⦅㆞ⓗ᫬ೃỴᐃ ○ 㑣㒊௷せ㔜⦅ ○ ᣦᐃ㔜᪂⦅㆞ⓗືస ● ᡤ௨ᑃMakefile䠈୺せᥥ㏙ ○ 產⏕᷐᱌࿴ཎጞ᷐ⓗ㜝⫃ᛶ ○ ␜㏺ல᷐᱌᭦ື᫬㛫㜝ಀ᭷ㆰ໬ⓗ᫬ೃ䠈ヱ ೴ொ㯟஦?
  • 40. ⿵඘1: ἄ᭷Makefileⓗmake ┠๓┠㗴ἄ᭷Makefile ↷ᶏmakeქქ ↷ᶏmake++
  • 41. Implicit Rules ୕ᑠ䠛
  • 42. make -p CPP㏺㑔ྍ୙᫝C++䠈᭷ ⯆㊃man cpp 㑏グᚓㆰᩝႫ䠛
  • 43. make -p (᥋㜝䠅 make᭷內ᘓ㡸タⓗ⹦⌮つ๎䠈ㄳ࿴ୖ㡫ㆰᩝ௨ཬ๓㠃ⓗㄒ ἲᑞ↷
  • 44. ⿵඘2: .PHONY ⠊౛Makefile䠈ໟྵ產⏕binary࿴Ύ㝖binary
  • 45. ⋵┳┳ Ύ㝖binary 產⏕᪂᷐䠈ྡ✃Ⅽclean ᷐᱌cleanᏑᅾ䠈↓ἲΎ㝖binary ᚲ㡲฽㝖᷐᱌cleanᡯ⬟ᇳ⾜target
  • 46. ศᯒ ● recipe ⓗᇳ⾜࿴target௨ཬprerequisites᷐᱌ ᫬㛫㈨イ᭷㜝 ● cleanⓗ┠ⓗ୪୙᫝せ產⏕clean᷐᱌䠈ஓᑵ᫝ 說targetᇳ⾜recipe࿴target᫝ྰⅭ᷐᱌↓㜝
  • 47. .PHONY ● ࿴᷐᱌↓㜝ⓗtarget ● ⏝ἲ .PHONY: ௨✵ⓑ㝸㛤ⓗTARGETྡ✃ ● ⠊౛ .PHONY: clean install
  • 48. ಟṇ .PHONYᅾ㏺㑔
  • 49. ┳┳ᩀᯝ
  • 50. ᘏఙ㢟ᮦ/ᅇᐙຌㄢ ● ዴఱ⮬ື㐍ධ୙ྠ┠㗴Make? ● ዴఱ⮬ື產⏕C source᷐࿴Header᷐᱌rule? ○ hello.c includes f1.h, f2.h䠈ඳኳᚋཪຍධf3.h䚹ᡭືᨵ ᚇ⣼䚹 ● ᭷ἄ᭷㎨ἲᢕᡤ᭷ⓗタᐃᨺᅾ᷐᱌內⤥ Makefile include?
  • 51. ๦ୗᑵ᫝⣽⠇䠈ㄳ⮬⾜ ┳᭩䠈つ๸タィ⮬ᕫⓗ ᐿ⩦ㄢ䚹
  • 52. Outline ● GNU Make ● Autotools ● CMake ● ཨ⪃㈨ᩱ ● Q & A
  • 53. 」⩦䠖GNU Makeᑠ⤖ ● GNU make: ༠ຓ⦅㆞ⓗ᫬ೃỴᐃ ○ 㑣㒊௷せ㔜⦅ ○ ᣦᐃ㔜᪂⦅㆞ⓗືస ● ᡤ௨ᑃMakefile䠈୺せᥥ㏙ ○ 產⏕᷐᱌࿴ཎጞ᷐ⓗ㜝⫃ᛶ ○ ␜㏺ல᷐᱌᭦ື᫬㛫㜝ಀ᭷ㆰ໬ⓗ᫬ೃ䠈ヱ ೴ொ㯟஦?
  • 54. 㑣㯟᭳ொ㯟㑏せ᭷autotools ● ㊬ᖹྎⓗၥ㢟 ○ memset v.s. bzero ○ ㊰ᚏ䚸᷐᱌୙ྠ ○ system call୙ྠ ● ྠᖹྎ ○ ภᘧᗜ∧ᮏ୙ྠ䠈prototypeྍ⬟୙ྠ ● ┦౫ᛶၥ㢟
  • 55. autotools ● autotoolⓗ┠ⓗᑵ᫝產⏕ᖹྎୖྍ௨⦅㆞ⓗ⎔ ቃ ● Ⅽ஢㐩฿㏺ᶏⓗ┠ⓗ䠈⣔⤫㟂せ೴฿ୗ㠃ⓗຌ ⬟ ○ ᷙ查ᖹྎ⎔ቃ ○ 產⏕Makefile
  • 56. ὶ⛬ http://en.wikipedia.org/wiki/GNU_build_system#mediaviewer/File:Autoconf-automake-process.svg
  • 57. http://en.wikipedia.org/wiki/GNU_build_system#mediaviewer/File:Autoconf-automake-process.svg
  • 58. http://en.wikipedia.org/wiki/GNU_build_system#mediaviewer/File:Autoconf-automake-process.svg
  • 59. ᚇ」㞯䠛ཱྀ㢌ㅮᑵ᫝ 1. ⮬ᖿᡈ㊝ᕤලᚋ產⏕᭦ືconfigure. ac䠈࿴ᑃMakefile.am 2. ㊝ᕤල產⏕configure, Makefile.in࿴ config.in 3. ㊝configure䠈產⏕Makefile࿴config.h 4. make; make install
  • 60. 㑏୙᠐䠛౗┳⠊౛ ఼せᑃⓗᮾす
  • 61. autoreconfᖳ఼࿧ྉ┦㜝ᕤ ලዴaclocal, autoconf, automake➼
  • 62. 產⏕ฟ౗ⓗ᷐᱌
  • 63. 產⏕ฟ౗ⓗ᷐᱌
  • 64. configure.ac # せồ∧ᮏ AC_PREREQ([2.68]) # ዓ௳㈨イ AC_INIT([Test_Autotools], [0], [test]) # ⤥Automake㈨イ䠈foreign⾲♧୙⏝GNUᶆ‽ # ஓᑵ᫝୙㟂せchangelog, AUTHORS➼᷐᱌ AM_INIT_AUTOMAKE([foreign -Wall -Werror])
  • 65. configure.ac # config᷐᱌ AC_CONFIG_HEADERS([config.h]) # ᮏḟdemo౑⏝ static library AC_PROG_RANLIB # Makefile ㊰ᚏ AC_CONFIG_FILES([Makefile src/Makefile libs/Makefile])
  • 66. configure.ac # ᦏᑜCC ⦅㆞ჾ AC_PROG_CC # ⤖᮰config䠈㛤ጞ產⏕┦㜝᷐᱌ AC_OUTPUT
  • 67. Makfile.am SUBDIRS = libs src
  • 68. libs/Makefile.am # ᣦᐃinclude㊰ᚏ AM_CFLAGS = -I../include # 產⏕liba.a ࿴libb.b # lib_௦⾲Ᏻ⿶᫬せᨺᅾ$(prefix)/lib୰ # 㡸タprefix=/usr/local lib_LIBRARIES = liba.a libb.a
  • 69. libs/Makefile.am # 產⏕liba.aⓗ┦౫᷐᱌ liba_a_SOURCES = liba.c liba.h # 產⏕libb.aⓗ┦౫᷐᱌ libb_a_SOURCES = libb.c libb.h # Ᏻ⿶฿$(prefix)/includeⓗ᷐᱌ include_HEADERS = ../include/liba.h .. /include/libb.h
  • 70. src/Makefile.am # ᣦᐃlinkီலlibrary LDADD = ../libs/liba.a ../libs/libb.a # ᣦᐃinclude㊰ᚏ AM_CFLAGS = -I../include
  • 71. src/Makefile.am # Ᏻ⿶฿$(prefix)/bin bin_PROGRAMS = test # 產⏕ⓗ᷐᱌┦౫ⓗ᷐᱌ test_SOURCES = test.c
  • 72. ● configure ● make ● make install ● make dist # ⮬ືᖳ఼ᡴໟtarball
  • 73. ᑠ⤖ ● ౑⏝autotools㟂せ⮬ᕫᑃ ○ configure.ac ○ Makefile.am ● ୖ㠃ⓗ⠊౛ᴟᗘ⡆␎
  • 74. ᘏఙ㢟ᮦ/ᅇᐙຌㄢ ● ዴఱ產⏕shared library? ● ᫝ྰ᭷᭦⫄᫂ⓗlibrary產⏕᪉ᘧ䠛 ○ hint: libtools
  • 75. ๦ୗᑵ᫝⣽⠇䠈ㄳ⮬⾜ ┳᭩䠈つ๸タィ⮬ᕫⓗ ᐿ⩦ㄢ䚹
  • 76. Outline ● GNU Make ● Autotools ● CMake ● ཨ⪃㈨ᩱ ● Q & A
  • 77. 㜝᪊CMake CMake᫝1999ᖺ᥎ฟⓗ㛤※⮬⏤㌾㧓ィ␓䠈┠ⓗ ᫝ᥦ౪୙ྠᖹྎஅ㛫ඹྠⓗ⦅㆞⎔ቃ䚹 ≉ᛶ: ● ᨭ᥼୙ྠᖹྎ ● ྍ௨ᑘBuild࿴ཎᮏ⛬ᘧ☞ศ㛤 ○ out-place build ○ in-place build ● ᨭ᥼cacheຍᛌ⦅㆞㏿ᗘ
  • 78. ὶ⛬ ● ᧝ᑃCMakeLists.txt ● ౑⏝⪅ᇳ⾜cmake ○ 產⏕ヱᖹྎᑞ᠕ⓗ⦅㆞⎔ቃ᷐᱌ዴMakefile➼ ● ౑⏝⪅ᇳ⾜ᖹྎୖⓗ⦅㆞᪉ἲ ○ ዴmake ● ౑⏝⪅ᇳ⾜cmake installᏳ⿶㌾㧓䚹
  • 79. ⠊౛ ఼せᑃⓗᮾす
  • 80. CMakeLists.txt # ∧ᮏ㟂ồ cmake_minimum_required(VERSION 2.8) # ఼ⓗProjectྡ✃ project(testcmake)
  • 81. CMakeLists.txt # タᐃㆰᩝ set(SRC_DIR src) set(LIB_DIR libs) set(INC_DIR include) # Compile flags set(CMAKE_C_FLAGS "-Wall -Werror")
  • 82. CMakeLists.txt # ᣦ௧include┠㗴 include_directories(${INC_DIR}) # ࿌ッCMakeせཤୗิⓗ┠㗴⦅㆞ add_subdirectory(${SRC_DIR}) add_subdirectory(${LIB_DIR}) add_subdirectory(${INC_DIR})
  • 83. libs/CMakeLists.txt # タᐃㆰᩝ䠈ᣦᐃlibrary┦౫᪊ီಶ᷐᱌ set(liba_SRCS liba.c) set(libb_SRCS libb.c) # ᣦᐃ⦅㆞ᆺᘧⅭshared library add_library(a SHARED ${liba_SRCS}) add_library(b SHARED ${libb_SRCS})
  • 84. libs/CMakeLists.txt # Ᏻ⿶᱁ᘧ # install(TARGETS ภᘧᗜྡ✃ LIBRARY # DESTINATION Ᏻ⿶┠㗴㊰ᚏ) install(TARGETS a b LIBRARY DESTINATION lib)
  • 85. src/CMakeLists.txt # タᐃㆰᩝ set(test_SRCS test.c) # 產⏕ᇳ⾜᷐ add_executable(${PROJECT_NAME} ${test_SRCS}) # ᣦ௧linkภᘧᗜ target_link_libraries(${PROJECT_NAME} a b)
  • 86. src/CMakeLists.txt # Ᏻ⿶᱁ᘧ # install(TARGETS ᇳ⾜᷐ྡ✃ # DESTINATION Ᏻ⿶┠㗴㊰ᚏ) install(TARGETS ${PROJECT_NAME} DESTINATION bin)
  • 87. include/CMakeLists.txt # install(FILES Header᷐ྡ✃ # DESTINATION Ᏻ⿶┠㗴㊰ᚏ) install(FILES liba.h libb.h DESTINATION include)
  • 88. out-place build
  • 89. ᑠ⤖ ● ఼せᑃCMakeLists.txt䠈ᣦᐃせ㐍ධီல┠㗴 ⦅㆞䠈ᡈ᫝┦㜝ⓗ᷐᱌௨ཬ㡸ᮇ⦅㆞࿴Ᏻ⿶ⓗ ᆺែ ● ୖ㠃ⓗ⠊౛ᴟᗘ⡆␎
  • 90. ᘏఙ㢟ᮦ/ᅇᐙຌㄢ ● ヲ⣽ㄒἲ ○ ㆰᩝタᐃ ○ ᲄ௳タᐃ ○ ᕧ㞟࿴ภᩝ ● ᡴໟ᪉ᘧ
  • 91. ๦ୗᑵ᫝⣽⠇䠈ㄳ⮬⾜ ┳᭩䠈つ๸タィ⮬ᕫⓗ ᐿ⩦ㄢ䚹
  • 92. Outline ● GNU Make ● Autotools ● CMake ● ཨ⪃㈨ᩱ ● Q & A
  • 93. ཨ⪃㈨ᩱ ● GNU Makeᡭ෉ ○ http://www.gnu.org/software/make/manual/make.html ● GNU Make ᛌ㏿ཨ⪃ ○ http://www.gnu.org/software/make/manual/make. html#Quick-Reference ● GNU Automakeᡭ෉ ○ http://www.gnu. org/software/automake/manual/automake.html ● Alexandre Duret Lutz: Autotools Tutorial (኱ ᥎) ○ https://www.lrde.epita.fr/~adl/autotools.html
  • 94. ཨ⪃㈨ᩱ ● CMake Wiki ○ http://www.cmake.org/Wiki/CMake ● CMake-tutorial (኱᥎) ○ https://github.com/TheErk/CMake-tutorial
  • 95. Outline ● GNU Make ● Autotools ● CMake ● ཨ⪃㈨ᩱ ● Q & A

×