13:29:39 #startmeeting 13:29:39 Meeting started Mon May 3 13:29:39 2010 UTC. The chair is debiansid. Information about MeetBot at http://wiki.debian.org/MeetBot. 13:29:40 so is the teacher here 13:29:40 Useful Commands: #action #agreed #halp #info #idea #link #topic. 13:29:47 #meetingtopic Autotools workshop 13:29:54 #meetingname Autotools workshop 13:29:54 The meeting name has been set to 'autotools_workshop' 13:30:01 #chair debiansid 13:30:02 Current chairs: debiansid 13:30:07 Spencer_tt: debiansid is teacher 13:30:21 #info Introduction 13:30:25 k got it 13:30:28 Hi, I am Siddhesh Poyarekar, a FOSS contributor. I will be leading you guys through the autotools workshop today 13:30:31 debiansid: #topic 13:30:39 to set topic 13:31:15 FranciscoD: ahh yes, thanks. I was using info instead :) 13:31:45 :) 13:31:56 So we will be autotoolizing the program at http://siddhesh.in/linkc.tar.bz2 13:32:06 This program is a Turbo C++ clone written by Yogesh Wani and Narendra kangralkar 13:32:15 It is very raw, but the project is complete enough to demonstrate this workshop 13:32:30 You will need the gcc, make, autoconf and automake packages as a minimum for this workshop 13:32:46 Without them, you won't be able to get the real fun of it, which is being able to build the package yourself 13:32:56 If you plan to autotoolize anything related to libraries, then you'll also need libtool 13:33:08 We won't go into that in this session, since this is only meant as an introductory session 13:33:15 Please feel free to ask questions during the session by raising your hand (!) 13:33:36 #topic What are autotools 13:34:06 So autotools are programs used to make a bunch of scripts to ensure that the code we write can build correctly on the target system 13:34:24 It is how we get the 'configure' script in most popular GNU sources 13:34:37 The script does the job of choosing the compiler needed, checks for dependent libraries, files and programs 13:34:51 Based on the above it generates a bunch of makefiles, one for each directory within the source tree and one for the root source directory 13:35:08 We will be using an example program to demonstrate the process of "autotoolizing" any code 13:35:33 #topic Getting sources 13:35:47 ok 13:35:48 You can download the example program from http://siddhesh.in/linkc.tar.bz2 13:35:56 #link http://siddhesh.in/linkc.tar.bz2 13:36:04 ok 13:36:08 If you have git and know how to use it, you can clone this repository: git://github.com/siddhesh/linkc.git 13:36:23 cd into the directory once you have untarred/cloned your sources 13:36:30 * DiscordianUK has got and untarred the example 13:36:48 done 13:36:54 * tuxdna too 13:36:56 * Spencer_tt downloads and reads through 13:37:13 * praveenkumar downloaded 13:37:46 done 13:37:46 great, so the action starts now. Anyone needs some time/ stuck on anything? 13:37:55 ! 13:38:03 ashwin_man: yes 13:38:40 want to verify the contents of the tar file - 8 files and 1 folder. Correct ? 13:39:00 ashwin_man: yes, that should be it 13:39:07 thanks 13:39:24 eof 13:39:25 ok cool, so the first thing we do is move the Makefile out of the way 13:39:45 autotools generates that for us and the current one is quite primitive 13:40:26 So there are two files that we need to create to autotoolize our program: configure.ac and Makefile.am 13:40:42 If the source tree has subdirectories, then you need a Makefile.am for each of those directories 13:41:01 I'll explain the significance of those files as we start writing them 13:41:37 Anyone need help moving makefile out of the way? 13:41:58 moving = rm , right? 13:42:00 You can either delete it or back it up as Makefile.bak 13:42:17 FranciscoD: you're ruthless :P 13:42:44 well, "moving out of the way" ! :P 13:42:49 * Spencer_tt renames Makefile to Makefile.bkp 13:42:57 done 13:43:06 moved 13:43:10 Cool, so let us start with the first file, configure.ac 13:43:14 * tuxdna moved it 13:43:22 #topic configure.ac 13:44:18 adimania: http://meetbot.fedoraproject.org/fedora-classroom/2010-05-03/autotools_workshop.2010-05-03-13.29.log.txt logs so far 13:44:33 * adimania thanks :) 13:44:51 configure.ac is used the create the configure script that one runs (./configure) to detect various properties of the system 13:45:14 The various function-like constructs that we will be writing in this script are referred to as macros 13:45:21 Put the first line in the script as: 13:45:29 AC_INIT([linkc], [0.1], [your_email_address]) 13:46:22 got it 13:46:37 Cool, so the AC_INIT macro is used to initialize the autoconf subsystem 13:46:42 The first argument of the macro is the program name 13:46:46 The second is the version number 13:46:53 The third is the email address of the program maintainer. So enter your email address in place of your_email_address 13:47:22 ! are all three values mandatory? 13:47:44 ls 13:47:59 tuxdna: yes 13:48:10 debiansid, ok got it 13:48:26 You may use square brackets [] to nest multi-word or multi-line input for individual arguments 13:48:53 debiansid: ! 13:48:59 praveenkumar: yes 13:49:30 debiansid: we have to make a configure file and then write those things? 13:49:32 ! 13:49:37 ! this file must be made in the same folder where we downloaded the programme? 13:49:51 pranay_09: inside the linkc folder 13:49:55 praveenkumar: no, this is in the configure.ac file that I asked to create and open 13:49:59 * FranciscoD looks at debiansid for confirmation 13:50:12 pranay_09: yes, inside the linkc folder 13:50:19 debiansid: ok 13:50:21 any more lines 13:50:25 the second argument, is the version of autotools or the app youre doing? 13:50:41 tuxdna: only package and version are mandatory; AC_INIT(package, version, [bug-report], [tarname], [url]) 13:50:43 Spencer_tt: plenty more, let's take them one at a time :) 13:50:51 * Spencer_tt waits 13:50:58 #link http://www.gnu.org/software/autoconf/manual/autoconf.html#Initializing-configure 13:51:00 FranciscoD: this is the version of your app, so you decide it 13:51:00 and can the email be xxx AT yyy DOT zzz or has to be xxx@yyy.zzz ? 13:51:10 ! if the multi-line string contains square brackets itself, how do we escape them? 13:51:20 mbuf, thanks :) 13:51:27 mbuf: ahh ok, thanks for that :) 13:53:27 tuxdna: I haven't actually tried that, so don't know how that can be done 13:53:39 * Spencer_tt takes notes 13:53:51 debiansid, ok 13:54:25 FranciscoD: you can use xx DOT yy AT zz as the email address 13:55:05 debiansid: both i mean xx DOT yy AT zz or xxx@yyy.zzz 13:55:34 praveenkumar: yes, you can use either 13:55:43 debiansid: ok 13:55:50 Ok, so the next line is: 13:55:56 AM_INIT_AUTOMAKE(dist-bzip2) 13:56:11 This macro is used to initialize the automake subsystem 13:56:51 The macro basically tells some things to be done in the makefile 13:57:27 In the above usage, I've told the automake subsystem to add an additional distribution target, bzip2 13:57:35 By default you only have gzip 13:57:59 So when you eventually do a 'make dist', it will now build a tar.zg and a tar.bz2 13:58:27 There are a number of other options available which can control make options 13:58:38 For example, there is an option 'check-news', which causes 'make dist' to fail if the first few lines of the NEWS file does not have the current version number 13:58:55 you enter multiple options as a space separated list 13:59:11 for example: AM_INIT_AUTOMAKE(dist-bzip2 dist-zip check-news) 13:59:36 A full list of these options is available here: http://www.gnu.org/software/libtool//manual/automake/Options.html#Options 13:59:36 debiansid: how do you comment? # ? 13:59:46 * FranciscoD would like to comment the file for future reference 13:59:50 FranciscoD: There is # and there is dnl 14:00:03 dnl This is a comment 14:00:05 or 14:00:09 # This is a comment 14:00:14 both work 14:00:46 So I move on to the next line, which is: 14:00:49 AC_CONFIG_SRCDIR([main.c]) 14:00:53 single hash or double hash for comments 14:01:03 Spencer_tt: single has is enough 14:01:33 ok 14:02:03 AC_CONFIG_SRCDIR is a simple safety check to ensure that the source code is in the directory specified 14:02:23 This is an optional check, so you can skip it if you like 14:02:38 ! 14:02:41 You can put in any existing file instead of main.c too 14:02:44 ashwin_man: yes 14:02:58 ! 14:03:06 is it directory or folder specific or file specific check..? 14:03:16 ashwin_man: file specific 14:03:21 FranciscoD: yes 14:03:27 is there any other way to make a file specific check...? 14:03:50 debiansid: same query as ashwin_man , is it directory or file, and what file? 14:03:51 ashwin_man: what kind of a check are you looking at? 14:04:06 FranciscoD: any source file in your package 14:04:24 ok 14:04:45 Cool, so the next line is: 14:04:47 AM_MAINTAINER_MODE 14:05:07 This is another optional macro, but an important one 14:05:46 mbuf :) 14:06:00 So AM_MAINTAINER_MODE adds additional build rules to the Makefile so that it will do an autoreconf whenever configure.ac or Makefile.am change 14:06:22 I'll come to what autoreconf is a little later 14:06:56 in short, the macro puts in a check to rebuild the configure script whenever the autotools input scripts (configure.ac and Makefile.am) change 14:07:42 Without this macro, you can have a situation where you change these scripts and then wonder why your build is not reflecting the change 14:07:47 happens way too often 14:07:55 This can be enabled at configure time with the --enable-maintainer-mode switch 14:08:11 Alright, So the lines you've entered so far told the autotools subsystem about our program and about the properties of the output 14:08:24 Again, there is a lot more you can do here, but that is something you can find out when you actually need it. $SEARCH_ENGINE is your best friend :) 14:08:39 Next up is the important part: detection of various programs, libraries and headers to make sure they exist 14:08:57 This is where you do what is know as "dependency checks" 14:09:10 Put in the next two lines as: 14:09:17 AC_PROG_CC 14:09:17 AC_PROG_INSTALL 14:09:47 The first line checks for the C compiler installed on the system 14:10:10 The second line checks for the 'install' program. You will have it in your Fedora boxes as /usr/bin/install 14:10:17 debiansid: are AM and AC prefixes supposed to mean something? 14:10:23 ok 14:10:25 AutoMake and AutoConf 14:11:18 Next we check for libraries needed to build the program 14:11:22 This sample program uses libncurses, so we need to check whether libncurses is installed or not 14:11:40 libncurses is part of a Fedora base install, but there will always be some *nix boxes that do not have it by default 14:12:02 So here's what you need as the next two lines: 14:12:14 AC_CHECK_LIB([ncurses], [initscr],, AC_MSG_ERROR([Could not find ncurses library])) 14:12:14 AC_CHECK_LIB([menu], [new_menu],, AC_MSG_ERROR([Could not find ncurses menu library])) 14:12:32 The AC_CHECK_LIB macro is used to check for existence of a particular library 14:12:41 The macro needs 4 arguments 14:12:46 The first one is the library name as you would specify to the linker as -l 14:13:34 The -l switches are provided to the linker to tell it the libraries the program needs to build 14:13:41 So if the library is 'libncurses.so', you need to specify 'ncurses' here 14:13:50 The next argument is any function name present inside the library 14:14:03 The third argument is an action you need to perform if the check succeeds. We don't need to do anything, so we leave it blank 14:14:17 Typically, the space is used to define preprocessor macros or even print out messages, but we need neither of those 14:15:10 Once the above checks are successful, the LDFLAGS Makefile variable will have -lncurses and -lmenu 14:15:32 Finally, the last argument is what you need to do if the check fails 14:15:53 Here we use the AC_MSG_ERROR macro to print out an error message and exit. This will cause the configure script to fail. 14:16:18 We all must have seen that happening due to missing libraries or programs 14:16:48 If you only want to print an error and proceed in case of such check failures, you use AC_MSG_WARNING macro instead -- usage is the same as AC_MSG_ERROR 14:17:24 This completes our checks section. We now need to generate makefiles as an output of the configure. 14:17:47 So put in the last macro in configure.ac as follows: 14:17:56 AC_OUTPUT([Makefile Help/Makefile]) 14:18:25 This tells that the output of configure should be Makefile (in source root directory) and Help/Makefile 14:18:49 That completes our configure.ac. You may now save and close it 14:19:07 Done 14:19:07 Next up is Makefile.am. Any questions so far? 14:19:35 done 14:19:36 Alright, I'll go on then 14:19:40 done 14:19:44 #topic Makefile.am 14:20:00 You can think of Makefile.am as a skeleton for a Makefile 14:20:11 automake creates an intermediate skeleton Makefile.in from this file 14:20:23 Makefile.in is then used by the configure script to generate the final Makefile 14:20:30 We need a Makefile for each subdirectory inside the source directory 14:20:36 So on the same lines, we need to put a Makefile.am for each subdirectory 14:20:51 So first, create a new file Makefile.am in the source root directory 14:21:41 Put in the first line as: 14:21:42 SUBDIRS = Help 14:22:31 This is similar to the SUBDIRS clause in a Makefile. It tells the automake utility to process Makefile.am in the given subdirectories 14:22:43 Next, need to tell automake about the program code. So here's our first line: 14:22:49 bin_PROGRAMS = linkc 14:23:19 This is to declare that our program executable output name is linkc. You can put multiple targets here too if required. We need only one 14:23:34 Next, we mention the sources that linkc needs as follows: 14:23:46 linkc_SOURCES = main.c design.c file.c help.c \ 14:23:46 design.h file.h help.h 14:24:37 I've made this multiline only for readability, and to show that you can continue on the next line with a \ 14:24:48 The directive above reads as _SOURCES 14:25:01 If the program name contains any non-alphanumeric characters, it is replaced by an underscore 14:25:21 Anyone stuck anywhere so far? 14:25:46 no carry on please 14:25:52 ok great 14:25:58 Next is an optional line: 14:26:02 noinst_HEADERS = design.h file.h help.h 14:26:19 which basically tells us that these header files are not to be installed into /usr/include when we do a "make install" 14:26:33 With this, you're done with the first Makefile.am. Save and close. 14:26:46 Next up, create and open Help/Makefile.am 14:26:57 This is where we will write makefile rules for content in Help/ 14:27:03 The Help/ directory contains some documents which the IDE uses to display short help and examples on your basic libraries 14:27:29 So you only really need to copy them to the right place 14:27:40 So all you need to add in this Makefile.am is the following: 14:27:50 Helpdir = $(datadir)/$(PACKAGE)/Help 14:27:50 Help_DATA = *.hlp 14:28:08 Helpdir specifies the directory where files need to be installed 14:28:55 Help_DATA specifies the files that need to be installed 14:29:02 The convention here is simply dir and _DATA 14:29:25 Save and close Help/Makefile.am 14:29:37 And you're done with your autotools configuration files 14:29:46 Now we need to execute a set of programs to generate the configure script 14:29:53 any questions so far? 14:30:25 debiansid: done 14:30:39 * Spencer_tt makes copious notes 14:30:42 done.....let us carry on 14:30:47 done 14:30:53 Ok, cool 14:30:56 #topic Building configure 14:31:04 So the first command is: 14:31:06 aclocal 14:31:12 ! 14:31:19 ashwin_man: yes 14:31:25 in which directory...? 14:31:34 in linkc 14:31:41 ok 14:31:43 eof 14:31:52 aclocal generates common macros (and any additional macros) in aclocal.m4 and in the directory autom4te.cache 14:31:58 Next: 14:32:02 autoconf 14:32:12 This generates the configure script 14:32:30 debiansid: please fpaste a copy of your configure.ac, Makefile.am so people can verify that they have the same as yours! 14:32:44 mbuf: ok, one sec, I'll do that 14:33:42 Here is my configure.ac: http://pastebin.com/AxGBCqUt 14:34:26 Makefile.am 14:34:29 http://pastebin.com/VJ3WMfyq 14:35:14 http://fpaste.org/CDO1/ 14:35:39 Help/Makefile.am: http://pastebin.com/NSF4XVCM 14:36:41 debiansid, the reason they asked for fpaste is that unlike pastebin it doesnt have ads 14:37:12 Southern_Gentlem: Ohh ok, I don't notice the ads much honestly :) 14:38:10 Makefile: http://fpaste.org/HMKx/ 14:38:40 Help/Makefile.am: http://fpaste.org/cEPo/ 14:38:57 The earlier one was Makefile.am, sorry about the typo 14:39:36 So any questions? 14:39:48 nope 14:39:48 no, carry on 14:40:00 carry on 14:40:00 Ok, so I assume everyone has run: 14:40:06 aclocal 14:40:08 autoconf 14:40:16 I have 14:40:18 yes 14:40:21 yes, done 14:40:28 yeah done 14:40:30 Next, type: 14:40:32 automake -a -c 14:40:40 This will fail 14:41:06 ya it does 14:41:13 i shows "option `dist-bzip2i' not recognized" 14:41:28 ! 14:41:32 praveenkumar: you have a different problem. You have a typo 14:41:48 'dist-bzip2' not 'dist-bzip2i' 14:41:54 ashwin_man: yes 14:41:57 debiansid: ok 14:42:18 it is failing with not found complaints 14:42:22 for NEWS 14:42:33 ashwin_man: yes, that is the failure I was referring to 14:42:35 README AUTHORS Changelog 14:42:49 ok...carry on please 14:42:50 automake generates the Makefile.in. -a adds any missing files, like the install script, depcomp (dependency generator), etc -c is to copy the files over. The default action is to create symlinks to existing files 14:42:51 eof 14:43:17 But it also checks for existence of some files 14:43:29 NEWS README AUTHORS ChangeLog 14:43:51 It does not add templates for these because they ought to be different for different programs 14:44:02 so you create blank placeholders for them for now 14:44:11 with this command: 14:44:11 touch NEWS README AUTHORS ChangeLog 14:44:30 Now run automake -a -c again 14:44:51 Does it fail for anyone now? 14:45:03 no. it is clean 14:45:03 works for me now 14:45:07 +1 14:45:08 ! 14:45:11 Makefile.am:4: variable `link_SOURCES' is defined but no program or 14:45:11 Makefile.am:4: library has `link' as canonical name (possible typo) 14:45:33 it should be linkc_SOURCES 14:45:36 pranay_09: probably a typo: What does your bin_PROGRAMS have? 14:45:55 tuxdna: yes 14:46:43 works for me too now 14:47:07 linkc 14:47:20 pranay_09: yes 14:47:27 Great, so the last point is the license of the program. It should be mentioned in the file COPYING 14:47:35 If there is no such file, automake installs a GPLv3 license by default 14:47:40 You need to replace the content with the license you actually want to use 14:48:11 That is it. You're package has now been autotoolized 14:48:16 You can now do './configure && make && make install' to install the application 14:48:42 Don't rest our hopes on it running though, the program itself is work in progress :) 14:48:56 ! 14:49:00 ! 14:49:12 To make things easier you can write a little script like this: http://fpaste.org/A1yS/ 14:49:17 ashwin_man: yes 14:49:30 where will it install the binary...? 14:49:33 * tuxdna thinks that it was like a breeze 14:49:40 ! 14:49:41 checking for initscr in -lncurses... no configure: error: Could not find ncurses library 14:49:52 * mbuf suggests using ./autogen.sh or autoreconf -vfi 14:49:57 ashwin_man: By default it is /usr/local 14:50:16 mbuf: autogen.sh is a gnome thingy AFAIK 14:50:22 it shows lots of errors 14:50:27 for make install 14:50:34 pranay_09: you need ncurses-devel package 14:50:54 ashwin_man: You will need root privileges for install 14:51:03 ashwin_man: please fpaste the output; don't try to explain the errors/output 14:51:51 mbuf: I prefer using the individual commands because I add that script to by vcs 14:52:05 mbuf: those commands are suggested for what? 14:52:06 debiansid: not necessarily; it is for the GNU build system 14:52:06 mbuf: That way, anyone who checks out the source starts with a ./gen 14:52:50 * FranciscoD 's dir has no autogen.sh as of now 14:52:53 debiansid: some projects use it; 14:53:03 http://fpaste.org/GT3J/ 14:53:15 debiansid: can't find it 14:53:22 FranciscoD: they run the configure and its pre-requisite commands for you 14:53:44 mbuf: ill have to write an autogen.sh? 14:53:53 FranciscoD: no! 14:53:55 debiansid: is it libncurses-dev? 14:53:59 FranciscoD: some upstream projects provide it already 14:54:04 the commands we used dint generate one for me. 14:54:08 FranciscoD: just have to run it 14:54:09 mbuf: I saw a lot of gnome projects use it, and they internally call gnome-autogen.sh 14:54:14 but after doing a ¨su¨ it works 14:54:22 debiansid: okay 14:54:29 mbuf: yeah, how do the upstream projects generate the file? 14:54:40 FranciscoD: it is a bash script 14:54:45 pranay_09: Ahh, yes. I forgot you're using ubuntu 14:54:56 debiansid: ok 14:54:58 debiansid: but, it is not just a Gnome thingy is what I am trying to tell you 14:55:15 debiansid: what is output of that program i installed it successfully but when i type linkc then it show me many hashes(#). 14:55:19 mbuf: Yeah, I explained why I assumed it was, which meant I agree with you :) 14:55:27 mbuf: yeah, if im autotoolizing my project, how do i get the bash script? 14:55:48 praveenkumar: don't try testing the program, it is quite broken the way it is written right now :) 14:55:58 FranciscoD: copy it 14:56:04 debiansid : Thanks 14:56:09 debiansid: ok 14:56:14 mbuf: +1 :D 14:56:22 :) 14:56:38 FranciscoD: generally, you shouldn't copy configure.ac, Makefile.am from other projects and use it blindly, but, always try to read the sources, and customize it to your needs 14:56:39 mbuf: heh, okay, all of them are the same that means? there's a standard autogen.sh then? 14:56:43 debiansid: anything more...? 14:56:58 by them here i mean autogen.sh 14:56:58 * zer0c00l is late to the party 14:57:04 ashwin_man: nope, I'm done 14:57:11 zer0c00l: no, youve missed the party :P 14:57:12 I just want to add couple of more links here 14:57:16 Thanks everyone for attending :) 14:57:23 THANKS ONCE AGAIN :) 14:57:23 omg 14:57:26 I encourage those interested in autotools to read this good book: 14:57:30 #link http://www.freesoftwaremagazine.com/books/autotools_a_guide_to_autoconf_automake_libtool 14:57:30 Thank you debiansid 14:57:30 mbuf: ahh ok, I'll wait for the links 14:57:40 and there is a very good presentation available at: 14:57:46 #link http://www.lrde.epita.fr/~adl/autotools.html 14:57:50 * tuxdna finally learned autotools... not its time to explore more 14:57:59 s/not/now 14:58:08 ok, thanks. 14:58:12 bye friends...dinner time 14:58:18 also the manuals for autoconf, automake and libtool are very details, and you are encouraged to kindly refer them! 14:58:19 debiansid, thanks 14:58:26 debiansid: thanks 14:58:41 great, Thanks mbuf! 14:58:48 #endmeeting