1 / 47

Embedded System Design GNU tool chain ( 2 )

Embedded System Design GNU tool chain ( 2 ). Zhaofeng SJTU-SoME 2007-09-29. Courseware WebSites. 1. Google svn server TortoiseSVN (svn client) http://esdlab.googlecode.com/svn/trunk/ 2. FTP ftp://202.120.46.8/Master/ESD_M/esd 3. Moodle 网站 http://202.120.46.2/moodle

miyo
Télécharger la présentation

Embedded System Design GNU tool chain ( 2 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Embedded System Design GNU tool chain(2) Zhaofeng SJTU-SoME 2007-09-29

  2. Courseware WebSites • 1. Google svn server • TortoiseSVN (svn client) • http://esdlab.googlecode.com/svn/trunk/ • 2. FTP • ftp://202.120.46.8/Master/ESD_M/esd • 3. Moodle网站 • http://202.120.46.2/moodle • 4. www.eefocus.com: 公开课程 • 5. www.openhard.com: 公开课程项目

  3. Review • 试写出一个完整makefile,来编译facedetect.c;facedetect.h;main.c;生成可执行文件facedetect。要求写出一个稳健的clean伪目标。

  4. Outline • GNU history • Tool Chain Overview • A hello world • Advanced topic • Version Control System • Auto tools

  5. Version Control System

  6. VCS的分类 • 1. 集中式模型 • 文件锁定(锁定-修改-解锁) • VSS • 版本合并 • CVS/SVN • 2. 分布式模型 • Bazaar/Git/Mercurial • *. 手工作坊式:rar+msn:土八路

  7. What is CVS? • CVS = Concurrent Versions System • Open source • Client/server design • Client and servers available for just about any platform OS X, Windows, and Linux • Traditionally command line based but there are several excellent GUI clients

  8. Terminology • Repository - area on the server where the files are stored • Sandbox - a local copy of the code which you work on and then commit to the repository • Checkout - act of getting a local a copy of the latest version of the code from the repository • Commit - saving the changes to your local file(s) to the cvs repository

  9. 术语 • CVSROOT: 代码库 • Repository: 项目仓库 • Version(revision): 版本号 • Branch: 版本分支

  10. Terminology (part 2) • Update - getting code changes that have been committed since you checked out the project • Merge - combining changes between two versions of the same file • History - shows a list of commit messages, times and, who committed for a particular file • Revision - cvs assigned version number for a file • Tagging - a way to mark a group of files and revisions • Branching - a way to work on multiple copies of your application

  11. Other CVS Tools • ViewCVS - http://viewcvs.sourceforge.net/ • CVSMonitor - http://ali.as/devel/cvsmonitor/

  12. 多人协同开发中的问题 • 同步的最新修改 • 文件的版本回溯 • 多人同时修改同一个文件产生的冲突 • 项目的分支开发 • 文件权限控制

  13. 正确的运行模式 用一个代码管理库集中管理代码同步 版本库 user1 user3 user2

  14. CVS开始第一个项目 • 环境变量$CVSROOT: • bash: CVSROOT=/home/cvsroot ; export CVSROOT • tcsh: setenv CVSROOT /home/cvsroot • CVSROOT库初始化:cvs init • 项目包首次导入:cvs import • cvs import -m "write some comments here" project_name vender_tag release_tag

  15. CVS的使用命令 • cvs checkout proj_name 导出项目包 • cvs commit –m “write comments” file_name 提交更新 • cvs update –m “write comments” file_name 同步库 • cvs log file_name查看修改日志 • cvs diff –r1.2 –r1.3 file_name 查看文件版本区别 • cvs add file_name 添加新文件到项目包 • cvs remove file_name 从项目包里删除文件

  16. CVS的使用流程 cvs checkout(首次导出) cvs up(同步代码)cvs commit(提交修改)cvs up(同步代码)cvs commit(提交修改)….. 恢复到一个旧的版本: 如果用cvs update -r1.2 file.name 这个命令是给file.name加一个STICK TAG: "1.2" ,虽然你的本意只是想将它恢复到1.2版本 正确的恢复版本的方法是:cvs update -p -r1.2 file.name >file.name 如果不小心忘了-p加成STICK TAG的话:用cvs update –A 解决

  17. CVSupdate/commit CVS没有锁定机制edit/unedit VSS get_lastest_version /check_in checkout/undo checkout CVS vs VSS 通用的标记$Header$$Author$$Date$ $Revision$

  18. WinCVS http://www.wincvs.org/ • Cvs Folders->Macros folder->Change Root • Cvs Admin->Preferencescvs server: username@server.ip.address:/path/to/cvsrootAuthenitication:passwd at cvs server • Cvs Admin->Login… • Cvs Admin->Checkout module…

  19. CVSTrac WEB界面的 • CVS用户管理 • CVS WEB浏览 • BUG TRACKING • Wiki讨论版

  20. What cvs isn’t/doesn’t... • build system • project management • talking to your friends • change control: • all changes are isolated vs. single logical change • bug fix tracking • track change verification • testing program (regression testing) • work flow or process model

  21. SVN • CVS的替代产品 • 使用SVN客户端从http://esdbook.googlecode.com/svn/trunk/ 下载第二章,阅读版本控制一节 • 要求会用svn管理自己的代码和文档 • 要求结合google管理项目组的代码和文档

  22. Auto tools

  23. GNU AutoTools简介 Autoconf , Automake and Libtool

  24. GNU Package的典型安装 幕后英雄—— GNU Auto Tools: autoconf, automake, libtool, autoscan, autoheader…… • FAQ 0039 @ smth • 下载源代码包foo-1.0.tar.gz • tar xvzf foo-1.0.tar.gz • cd foo-1.0 • ./configure • make • (su) make install 问题1:配置脚本configure是怎么生成的? 问题2:configure脚本怎么知道该如何生成Makefile

  25. Makefile’s Big Trouble? • GNU的Makefile规范相当复杂,随着项目复杂性的增加,要写出一个正确而高效的Makefile相当困难,对新手而言更是如此。 • 不同的类Unix操作系统之间存在着差异,移植性如何保证?需要大量手工编写的脚本和条件编译。

  26. All in One Solution? • GNU Auto Tools是上个世纪90年代开始发展起来的一系列辅助开发、打安装包的自动化工具。 • 各种工具分别开发,但是协同工作的很好。比如autoconf, automake, libtool等等。 • 但是,连开发者自己也承认,这套工具虽然好用,但是学习曲线很陡峭。 • 困难在于:一套新的思路和习惯,一套自定义的宏和规则

  27. Hello World – Step by Step • 1. hello.c #include <stdio.h> int main() { printf(“Hello World!\n”); return 0; } • 2. Makefile.am bin_PROGRAMS = hello hello_SOURCES = hello.c • 3. configure.in AC_INIT(hello.c) AM_INIT_AUTOMAKE(hello, 0.1) AC_PROG_CC AC_OUTPUT(Makefile) • 4. aclocal • 5. autoconf • 6. automake --add-missing --foreign • 7. ./configure • 8. make (make install 安装,make dist 产生安装包)

  28. Hello World! 演示 ——如何杀鸡用牛刀

  29. 来龙去脉 autoscan edit aclocal configure.scan configure.in aclocal.m4 Src code autoconf automake Makefile.am Makefile.in configure Makefile

  30. configure.in(1) • 是configure脚本的输入文件,为了解决在不同unix变种之间移植程序的问题:库名可能不同,应用程序名可能不同,结构和常量的定义可能不同…… • configure脚本完成autoconf与automake的初始化工作,为不同的平台定义相应的宏,检测并指定适当的程序名、库名、结构和常量名等等,指定要为哪些目录输出Makefile文件。总之,为编译程序做好一切准备工作。

  31. configure.in(2) configure.in的八股文 • 基本初始化部分:包括AC_INIT (必须第一个出现), AM_INIT_AUTOMAKE(程序包名,版本号), AC_CONFIG_HEADER • 可选宏:如AC_ARG_ENABLE • 检测某些程序的存在性 • 检查程序用到的库

  32. configure.in(3) • 检查某些头文件是否存在。 • 检查Typedefs and structures。 • 检查Functions。 • 指定在哪些目录输出Makefile。 Seems troublesome, mmm? Don’t worry, autoscan will do most of the work for you.

  33. Makefile.am(1) • 一种比Makefile更高层次的规则。只指定要生成什么目标,它由什么源文件生成,要安装到什么目录。 • Just simple and stupid!  • 可执行文件: bin_PROGRAMS = foo foo_SOURCES = foo1.c foo1.h foo2.c foo_LDADD = foo3.o -lm foo4.a foo_LDFLAGS = -L<lib_path> foo_DEPENDENCIES =

  34. Makefile.am(2) • 对静态库: lib_LIBRARIES = libfoo.a foo_a_SOURCES = foo_a_LDADD = foo_a_LIBADD = foo_a_LDFLAGS = 只在make时做静态连接用,不安装的库: noinst_LIBRARIES = libfoo.a …… • 对头文件:include_HEADERS = foo.h • 对数据文件:data_DATA = data1 data2

  35. Makefile.am(3) • 全局变量(对所有目标都适用) INCLUDES = -I/dir1 -I/dir2 LDFLAGS = -L/dir1 -L/dir2 LDADD = foo.o foo.a -lfoo EXTRA_DIST = file1 file2 源程序和一些默认的文件自动打入.tar.gz包,其它文件若要进入.tar.gz包可以用这种办法,比如配置文件, 数据文件等等。 SUBDIRS = dir1 dir2 在处理本目录之前要递归处理哪些子目录

  36. Makefile.am(4) • 标准安装路径 $(prefix) = /usr/local 是所有安装目录的默认前缀,可以通过./configure --prefix=<new_prefix>的方法覆盖。 其它的预定义目录如:bindir = $(prefix)/bin, libdir = $(prefix)/lib, datadir = $(prefix)/share, sysconfdir = $(prefix)/etc, … • 想定义一个新的安装路径?比如config, 可定义 confdir = $(prefix)/config, 然后conf_DATA = file1 file2,则file1, file2会作为数据文件安装到$(prefix)/config目录下。

  37. Makefile.am(5) • 尽量用相对路径引用源程序的位置,以下两个变量是预定义好的: • $(top_srcdir)无论在哪个目录层次,该变量定义了包含src目录的目录位置,用于引用源程序; • $(top_builddir)定义了生成目标文件上最上层目录,用于引用.o等编译出来的目标文件。 • ……

  38. Makefile.am to Makefile • Automake takes a (relatively) simple file called Makefile.am and • Creates a (relatively) complicated file called Makefile • Notes: • Makefile.am is 85 lines (mostly boilerplate). • Makefile (generated) is 672 lines

  39. configure’s Gifts • configure脚本生成的Makefile中已经带了很多常用的目标如:check, all, install, uninstall, clean, dist, distcheck, distclean, tags, maintainerclean. • If configure or make did it, make distclean undoes it. • If make did it, make clean undoes it. • If make install did it, make uninstall undoes it. • If you did it, make maintainer-clean undoes it.

  40. libtool简介 • 生成各种程序库的方便工具。 • 提供一个统一的接口,程序员不用关心各种烦人的底层细节:不同的平台的库可能要求不同的后缀,不同平台对库的安装方法不同,有些平台不支持动态库等等。 • 生成高层次的库,称为libtool library,后缀是.la。用它连接时,默认产生动态连接库,也可以用-static参数指定生成静态连接库。 • 既可单独使用又可与automake和autoconf一起使用更加强大、方便。

  41. 使用libtool • 在configure.in文件中加上AC_PROG_LIBTOOL宏,如果原来有AC_PROG_RANLIB宏,删去它。 • 在Makefile.am文件中: lib_LTLIBRARIES = libshell.la libshell_la_SOURCES = object.c subr.c symbol.c 与原来的写法非常相似! • .la库只能连入.lo(使用libtool生成的目标文件) libshell_la_LDADD = xmalloc.lo @LTLIBOBJS@ • 传入库的版本号: libshell_la_LDFLAGS = -version-info 1:0:1 • 与其它目标文件连接时用LDFLAGS指定连接的方式(默认是动态方式):-static, --all-static指定静态连接。

  42. 小结 • Autoconf:根据用户提供的configure.in文件,生成一个名为configure的脚本。该脚本可以搜集有关移植性的平台相关信息,这些信息被用来生成Makefiles,配置头文件和其它平台相关的文件。 • Automake:根据用户提供的一个高层次的生成规则Makefile.am,生成Makefile文件的模板Makefile.in。Automake生成的Makefiles符合GNU的Makefile标准,用户无需再手工编写Makefile文件。 • Libtool:生成内存位置无关的代码且让共享库在不同平台间移植成为可能。它可以不依赖autoconf和automake单独运行,另一方面,automake和libtool可以无缝地集成使用。

  43. GNU autoconf Source Code configure.ac(configure.in) aclocal autoconf autoscan configure configure.scan

  44. GNU automake Makefile.am Makefile.in configure automake Makefile

  45. Homework • 1. TASK1-LAB4-AUTOtools.doc • 2. TASK1-LAB5-CVServerv0.doc • 3. 使用SVN客户端从http://esdbook.googlecode.com/svn/trunk/ 下载第二章,阅读版本控制一节 • 要求会用svn管理自己的代码和文档 • 要求结合google管理项目组的代码和文档

  46. Case Study 1: Face Detection • CaseStudy1_FaceDetection.ppt

  47. Project • 1. 建立7个组:人脸识别(3) 指纹识别(4) • 2. 在www.openhard.com上建立项目组 • 3. 第一阶段任务,完成PC上的演示程序 • 时间:两周:07.10.16日晚结束 • 验收:课上演示,并完成设计过程报告

More Related