Buildsystems and What the Heck for We Actually Use the Autotools

Buildsystems and What the Heck for We Actually Use the Autotools

Buildsystems and what the heck for we actually use the autotools Tom´aˇsChv´atal SUSE Packagers team 2013/07/19 Introduction Who the hell is Tom´aˇsChv´atal • SUSE Employee since 2011 - Team lead of packagers team • Packager of Libreoffice and various other stuff for openSUSE • openSUSE promoter and volunteer • Gentoo developer since fall 2008 3 of 37 Autotools process Complete autotools process 5 of 37 Make Why not just a sh script? Always recompiling everything is a waste of time and CPU power 7 of 37 Plain makefile example CC ?= @CC@ CFLAGS ?= @CFLAGS@ PROGRAM = examplebinary OBJ = main.o parser.o output.o $ (PROGRRAM) : $ (OBJ) $ (CC) $ (LDFLAGS) −o $@ $^ main.o: main.c common.h parser.o: parser.c common.h output.o: output.c common.h setup.h i n s t a l l : $ (PROGRAM) # You have to use tabs here $(INSTALL) $(PROGRAM) $(BINDIR) c l e a n : $ (RM) $ (OBJ) 8 of 37 Variables in Makefiles • Variables expanded using $(), ie $(VAR) • Variables are assigned like in sh, ie VAR=value • $@ current target • $<the first dependent file • $^all dependent files 9 of 37 Well nice, but why autotools then • Makefiles can get complex fast (really unreadable) • Lots of details to keep in mind when writing, small mistakes happen fast • Does not make dependencies between targets really easier • Automake gives you automatic tarball creation (make distcheck) 10 of 37 Autotools Simplified autotools process 12 of 37 Autoconf/configure sample AC INIT(example , 0.1, [email protected]) AC CONFIG HEADER([ config .h]) AC PROG C AC PROG CPP AC PROG INSTALL AC HEADER STDC AC CHECK HEADERS([string.h unistd.h limits.h]) AC CONFIG FILES([ Makefile doc/Makefile src/Makefile]) AC OUTPUT 13 of 37 Autoconf syntax • The M4 syntax is quite weird on the first read • It is not interpreted, it is text substitution machine • Lots of quoting is needed, if in doubt add more [] • Everything that does or might contain whitespace or commas has to be quoted • Custom autoconf M4 macros are almost unreadable 14 of 37 Automake bin PROGRAMS = examplebinary examplebinary SOURCES = n s r c /main . c n src/parser.c n src/output.c n src/setup.c noinst HEADERS = src/common.h src/setup.h 15 of 37 Basic rules • Always use just one Makefile.am in root folder • All files that are to be distributed must be added to relevant parts or EXTRA DIST • Always run make distcheck to verify your package really works • Use check BINARIES/etc. to have test phase 16 of 37 Variables for automake - SUFFIXES • PROGRAMS • LIBRARIES DO NOT USE go for LTLIBRARIES • SCRIPTS • SOURCES • HEADERS • OBJECTS • DATA • LDADD 17 of 37 Variables for automake - PREFIXES • bin will be installed to bindir • sbin will be installed to sbindir • lib will be installed to libdir • noinst will not be installed • EXTRA will be packaged upon make dist • check used only for make check 18 of 37 Libtool Libtool versioning • Start with version information of `0:0:0' for each libtool library • If the library source code has changed at all since the last update, then increment revision (`c:r:a' becomes `c:r+1:a') • If any interfaces have been added, removed, or changed since the last update, increment current, and set revision to 0 • If any interfaces have been added since the last public release, then increment age • If any interfaces have been removed or changed since the last public release, then set age to 0 20 of 37 configure.ac changes LT VERSION=m4 esyscmd([./ version .sh −v ] ) LT INIT([ disable −s t a t i c pic −o n l y ] ) AC PROG LIBTOOL 21 of 37 Makefile.am changes lib LTLIBRARIES = libexample.la libexample la SOURCES = n src/something.c n src/somethingelse.c n src/whatever.c libexample la CFLAGS = n $ (MYEXTERNALPACKAGE CFLAGS) libexample la LDFLAGS = n $ (MYEXTERNALPACKAGE LIBS) n −v e r s i o n −i n f o $ (LT VERSION) n −export −symbols−r e g e x '^ foo ' 22 of 37 Autotools and windows Initial thoughts • Well for multiplatform support you can count on autotools on any UNIX-ish system • On windows you have to use cygwin/mingw • Per above you will spent bit of time getting that running • You have to write yourself the .rc or rc.in file to be processed by cmake (see librevenge/etc.) 24 of 37 Changes for configure.ac AC MSG CHECKING([ for native Win32]) AS CASE([ $host] , [∗−∗−mingw ∗ ],[ n a t i v e w i n 3 2=y e s BINARY WIN32 RESOURCE=binary−win32res.lo AC CHECK TOOL(WINDRES, w i n d r e s ) ],[ n a t i v e w i n 3 2=no BINARY WIN32 RESOURCE= ] ) # Ensure compat with MSVC AS IF([test "x$native win32" = "xyes"], [ AC CHECK TOOL(WINDRES, w i n d r e s ) AS IF([test x"$GCC" = xyes], [ AC MSG CHECKING ( [ how to g e t MSVC−compatible struct packing]) AS IF ( [ t e s t −z " $ a c c v p r o g CC"],[ o u r g c c="$CC" ],[ o u r g c c="$ a c c v p r o g CC" ]) AS IF ( [ $ o u r g c c −v −−h e l p 2>/dev / n u l l j grep ms−b i t f i e l d s >/dev/null], [ m s n a t i v e s t r u c t="−mms−b i t f i e l d s " CFLAGS="$CFLAGS $ m s n a t i v e s t r u c t " CXXFLAGS="$CXXFLAGS $ m s n a t i v e s t r u c t " AC MSG RESULT ( [ $f m s n a t i v e s t r u c t g ]) ],[ AC MSG RESULT ( [ no way ] ) 25 of 37 AC MSG WARN([produced libraries might be incompatible with MSVC−compiled code]) ]) ]) ]) Changes for Makefile.am bin PROGRAMS = examplebinary examplebinary SOURCES = n s r c / main . c n src/parser.c n src/output.c n src/setup.c examplebinary LDADD = n $ ( OTHER LIBS ) n @BINARY WIN32 RESOURCE@ noinst HEADERS = src/common.h src/setup.h i f OS WIN32 @BINARY WIN32 RESOURCE@ : examplebinary.rc $(examplebinary OBJECTS) chmod +x $(top srcdir)/build/∗ compile−r e s o u r c e && n WINDRES=@WINDRES@ $ ( t o p srcdir)/build/lt −compile−resource examplebinary.rc @BINARY WIN32 RESOURCE@ e n d i f 26 of 37 Additional points for Makefile.am • Always pass -avoid-version to libtool • Remember to add the resource file to DEPENDENCIES • Script to compile the .lo files https://github.com/AbiWord/enchant/blob/master/lt-compile- resource 27 of 37 Autotools usability • Not hard as people are led to believe -> you can deploy it unless your files are too messy • It, because of mingw, produces slower binaries than MSVC • Most people are fine with it, but if not use Visual Studio project file and be done • For .rc files you usualy have to use some shellscript as libtool has no clue 28 of 37 CMake What are the benefits? • No libtool! • Multiplatform generator for free Mac/Win/Linux... • Can swap make for ninja 30 of 37 Any disadvantages? • FindBLA.cmake are sometimes pretty crappy • If you rely on just .pc files you loose multiplatformity • Can get unreadable fast • Conflicting guides online, fine when you have someone to ask • Distribution archive generator using CPack confuse many people 31 of 37 CMake example cmake minimum required(VERSION 2.8) project(example C) set (Example VERSION MAJOR 0) set (Example VERSION MINOR 1) s e t ( src EXAMPLE s r c /main . c src/parser.c src/output.c src/setup.c src/common.h src/setup.h ) a d d executable(examplebinary $fsrc EXAMPLE g) i n s t a l l (TARGETS e x a m p l e b i n a r y DESTINATION b i n ) 32 of 37 CPack example include (InstallRequiredSystemLibraries) s e t ( CPACK RESOURCE FILE LICENSE "$fCMAKE CURRENT SOURCE DIRg/LICENSE ") s e t (CPACK PACKAGE VERSION MAJOR "$fTutorial VERSION MAJOR g") s e t (CPACK PACKAGE VERSION MINOR "$fTutorial VERSION MINOR g") include (CPack) 33 of 37 Reading Reading 35 of 37 Endnote Thanks Thank you for your attention. 37 of 37.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    37 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us