13-Jul-15Advanced Programming Spring 2002 autoconf Jonathan Lennox Department of Computer Science Columbia University.

Slides:



Advertisements
Similar presentations
Introduction to Linux Recap Installing programs Introduction to Video Editing with Linux.
Advertisements

Configuration management
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Systems Dev. Tutorial II: Make, utilities, & scripting Recitation Wednesday, Sept 13 th, 2006.
Linux+ Guide to Linux Certification, Second Edition
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
CSc 352 Shell Scripts Saumya Debray Dept. of Computer Science
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Lab 3 Department of Computer Science and Information Engineering National Taiwan University Lab3 - Cross Tools 2014/10/7/ 20 1.
Input/Output Controller (IOC) Overview Andrew Johnson Computer Scientist, AES Controls Group.
Windows Programming Lecture 05. Preprocessor Preprocessor Directives Preprocessor directives are instructions for compiler.
CCA Port, Component & Application Build Skeleton Templates “A new script toolkit for generating CCA build skeletons” Torsten Wilde and James Kohl Oak Ridge.
Trilinos 101: Getting Started with Trilinos November 7, :30-9:30 a.m. Mike Heroux Jim Willenbring.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Cs3157-fall2002- lect22 1 advanced programming -- fall 2002 lecture #22 -- mon nov 25  web programming review  slides from Henning Schulzrinne, coms.
Lab 11 Department of Computer Science and Information Engineering National Taiwan University Lab11 - Porting 2014/12/9/ 26 1.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
Chapter 1 What is UNIX? Graham Glass and King Ables,
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
CS 390 Unix Programming Summer Unix Programming - CS 3902 Course Details Online Information Please check.
Linux+ Guide to Linux Certification, Third Edition
CMake refactoring P. Hristov 19/03/2014. History I  Recursive makefiles (F.Carminati):  Problems in dependencies  Slow  "Recursive Makefiles.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Installing CompuCell3D from source. Why you might want to install from source? 1.There are no binaries for your platform (e.g. gentoo linux) 2.You want.
Presentation Name / 1 Visual C++ Builds and External Dependencies NAME.
CS2204: Introduction to Unix January 19 th, 2004 Class Meeting 1 * Notes adapted by Christian Allgood from previous work by other members of the CS faculty.
National Center for Supercomputing ApplicationsNational Computational Science Grid Packaging Technology Technical Talk University of Wisconsin Condor/GPT.
Dissecting the Windows CE Build Process James Y. Wilson Principal Engineer, Windows Embedded MVP CalAmp, Inc. James Y. Wilson Principal Engineer, Windows.
Basic UNIX Concepts. Why We Need an Operating System (OS) OS interacts with hardware and manages programs. A safe environment for programs to run is required.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
An Overview of ROMS Code Kate Hedstrom, ARSC April 2007.
Compiler Directives. The C Preprocessor u The C preprocessor (cpp) changes your source code based on instructions, or preprocessor directives, embedded.
Introduction to UNIX CS 2204 Class meeting 1 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
Software structure and distribution How to share your code with the rest of the world Why it has to be… AA: Kurtis AB: YongChul
Milan, 15 June 2001WP1 Meeting - F. Donno1 GRID Packaging and Code Management for WP1 F. Donno INFN - Pisa.
Linux+ Guide to Linux Certification, Second Edition
Duke CPS Problem: commands with state and undo support l How do applications with “undo” options (e.g., formatting in word processors) support.
Build Tools 1. Building a program for a large project is usually managed by a build tool that controls the various steps involved. These steps may include:
How to configure, build and install Trilinos November 2, :30-9:30 a.m. Jim Willenbring.
Problem Session 4 Header Files and Unix. Where are they? You may need to examine the header file to determine what the data structures and functions provided.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
C++ Functions A bit of review (things we’ve covered so far)
Wed Mar Michael Imamura / The GNU Autotools Your very own./configure.
Linux Administration Working with the BASH Shell.
CLHEP Infrastructure Improvements CHEP 2004 Lynn Garren, FNAL and Andreas Pfeiffer, CERN.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Building programs LinuxChix-KE. What happens in your CPU? ● It executes a small set of instructions called "machine code" ● Each instruction is just a.
Fixing autotools-related build issues
Developing Portable Applications ● Introduction GNU autotools – GNU toolchain ● Goals - cross-platform ● Supported platforms (POSIX compliant) ● GNU autotools.
A gentle introduction to Autotools The good, the bad and the ugly Kees-Jan Dijkzeul October 28 th, 2010.
Autoconf, Automake, and Libtool Tom Tromey. Copyright ● Copyright 2006 Tom Tromey ● Parts Copyright 2006 Alexandre Duret-Lutz ●
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
Build and Test system for FairRoot
Software Package development and management
Contiki and Code Composer Studio
C Preprocessor(CPP).
Software Installation
Presentation transcript:

13-Jul-15Advanced Programming Spring 2002 autoconf Jonathan Lennox Department of Computer Science Columbia University

13-Jul-15Advanced Programming Spring Software portability  Many software products need to run on lots of platforms  Unix, Windows, (old) Macintosh, VMS, …  Varieties of Unix: Linux, Solaris, SunOS 4.x, Free/Net/OpenBSD, MacOS X (Darwin), Tru64, AIX, HP/UX, SVR4, SCO, Minix, …, …  Open-source software especially needs to be portable  Create a developer community

13-Jul-15Advanced Programming Spring Historical Practice (1)  Ignore the problem  1982: “All the world’s a VAX” (running BSD 4.2)  1992: “All the world’s a Sun” (running SunOS 4.x)  2002: “All the world’s Linux” (on an x86)  This is great, for as long as it’s true…

13-Jul-15Advanced Programming Spring Historical Practice (2)  Sea of platform-specific #ifdef’s #ifdef __linux__ linux_specific_code() #elif defined(__sun__) && defined(__svr4__) /* Solaris */ solaris_specific_code() #else #error “What system is this?” #endif  This only works for platforms you’ve already ported your code to  Can quickly become unmanageable

13-Jul-15Advanced Programming Spring Historical Practice (3)  Makefile documents –D flags, -L flags, etc., to pass to compiler for specific systems or compilation options  User modifies the program’s Makefile by hand, in a text editor  Works okay for very small projects; runs into problems very quickly  Error-prone; users often forget to specify flags, mis-type them, or give the wrong ones  Porting to a new platform is very difficult

13-Jul-15Advanced Programming Spring Historical Practice (4)  Variant of (3): interactive scripts to set all the options  Run a shell script. It asks you lots of questions like “does this system support the argle(3) function with extended frobnitz? (y/n):”  Shell script automatically creates your make file  Very bad for inexperienced software builders  Not (easily) possible to build software non- interactively  With good per-system defaults, this can work, however. (Perl’s build system works like this.)

13-Jul-15Advanced Programming Spring Solution: autoconf  ‘configure’ script  Automatically checks the characteristics of the build system  Programs, libraries, header files, system calls  Generates a Makefile from a programmer- supplied template  Generates a config.h file defining compiler and system characteristics

13-Jul-15Advanced Programming Spring Autoconf file flows: Developer configure.in autoconf configure autoheader config.h.in aclocal.m4 acsite.m4

13-Jul-15Advanced Programming Spring Autoconf file flows: Builder Makefile.in config.h.in configure Makefile config.h./configure; make config.cacheconfig.log config.status make

13-Jul-15Advanced Programming Spring Autoconf philosophy  Check features, not systems  “Does this system support select() or poll()?”  Not, “Is this BSD or SysV”?  Where possible, check features directly  For example, try to compile a program that invokes a function. See if it compiles/links/runs (depending on the feature)  This isn’t always possible – e.g., “what kind of audio drivers does this OS use?”

13-Jul-15Advanced Programming Spring Typical configure.in dnl Process this file with autoconf to produce a configure script. AC_INIT([littleserver], [1.0]) AC_CONFIG_SRCDIR(littleserver.c) AC_CONFIG_FILES(Makefile) AC_CONFIG_HEADERS(config.h) dnl Checks for programs. AC_PROG_CC dnl Checks for libraries. AC_CHECK_LIB(nsl, gethostbyaddr) AC_CHECK_LIB(socket, bind) dnl Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS(limits.h sys/time.h unistd.h crypt.h string.h stdlib.h) AC_HEADER_TIME dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_TYPE_SIGNAL dnl Checks for library functions. AC_CHECK_FUNCS(select socket strftime strtol) AC_REPLACE_FUNCS(strerror strdup) AC_OUTPUT

13-Jul-15Advanced Programming Spring Typical configure run $./configure creating cache./config.cache checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... yes checking whether gcc accepts -g... yes checking for gethostbyaddr in -lnsl... yes checking for bind in -lsocket... yes checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for limits.h... yes checking for sys/time.h... yes checking for unistd.h... yes checking for crypt.h... yes checking for string.h... yes checking for stdlib.h... yes checking whether time.h and sys/time.h may both be included... yes checking for working const... yes checking return type of signal handlers... void checking for select... yes checking for socket... yes checking for strftime... yes checking for strtol... yes checking for strerror... yes checking for strdup... yes updating cache./config.cache creating./config.status creating Makefile creating config.h

13-Jul-15Advanced Programming Spring configure.in structure  AC_INIT (package, version, [bug-report-address])  start configure.in  AC_CONFIG_SRCDIR (unique-file-in-source-dir)  uniquely identify source directory  AC_CONFIG_FILES (file..., [cmds], [init-cmds])  create files from templates (e.g. Makefile)  AC_CONFIG_HEADERS (header..., [cmds], [init- cmds])  create header files (e.g. config.h)  AC_OUTPUT  output all the generated files

13-Jul-15Advanced Programming Spring configure.in: program checks  Autoconf can check if the build system has certain programs  AC_PROG_AWK  Sets output variable AWK to mawk, gawk, nawk, or awk  AC_PROG_LEX / AC_PROG_YACC  Find lex (flex) or yacc (byacc, bison)

13-Jul-15Advanced Programming Spring configure.in: compiler checks  Autoconf can find the compiler and check its characteristics  AC_PROG_CC, AC_PROG_CXX  Find the C or C++ compiler  AC_PROG_C_STDC  Check if the C compiler is ANSI C, after trying various compiler options to make it do so.  AC_C_CONST  Check if the C compiler supports ‘const’.  If not, #define const to the empty string, so you can use it anyway.  AC_C_BIGENDIAN  Check if the system is “big-endian”; i.e., stores integers most-significant-byte first. (Sparc is big-endian; x86 is little-endian.)

13-Jul-15Advanced Programming Spring configure.in: library checks  Autoconf can determine whether certain libraries are available  AC_CHECK_LIB(library, function)  Check whether the library can be linked (as ­ llibrary), and then whether the function can be found inside it.  Once a library is found, it’s linked in by default for future calls to AC_CHECK_LIB, so you can have one library depend on another.

13-Jul-15Advanced Programming Spring configure.in: header checks  Autoconf can check whether certain header files are available  AC_CHECK_HEADER  Check whether a header file is available  AC_HEADER_STDC  Check whether the system header files conform with ANSI C. (Not the same as AC_PROG_C_STDC, or __STDC__!)  AC_HEADER_TIME  Check whether and can both be included

13-Jul-15Advanced Programming Spring configure.in: type checks  Autoconf can check characteristics of structures and types in the compilation environment  Type checking code #includes all detected header files checked so far  AC_CHECK_MEMBER(aggregate.member)  Check whether the given aggregate (struct or union) is defined, and if so, whether it contains the given member  AC_CHECK_TYPE(type)  Check whether the compiler knows about a specific type  AC_TYPE_SIZE_T  Check whether the compiler knows about the type size_t; if not, typedef it to ‘unsigned’.

13-Jul-15Advanced Programming Spring configure.in: function checks  Autoconf can check whether system and library functions are available  AC_CHECK_FUNCS(functions…)  Check whether the given functions are available  AC_REPLACE_FUNCS(functions…)  Check whether the given functions are available, and if not, link in replacement code re-implementing them

13-Jul-15Advanced Programming Spring Autoconf output: Makefile  Some autoconf output is need by the Makefile, so is defined as template substitutions  Libraries, programs, search paths  Developer must write Makefile.in: template Makefile  Other than template variables, looks exactly like a normal Makefile  Patterns in Makefile.in are substituted with results of autoconf tests   C compiler   Awk executable   compiler flags   matched libraries

13-Jul-15Advanced Programming Spring Autoconf output: config.h  Other autoconf output is needed by the source code, so symbols are defined in config.h.  Source code #includes “config.h”, then makes decisions based on the symbols defined. HAVE_SYS_TIME_H exists WORDS_BIGENDIANintegers are big-endian HAVE_SELECTselect() was found HAVE_STRUCT_PASSWD_PW_ GECOS struct passwd has the pw_gecos field.

13-Jul-15Advanced Programming Spring System-dependent tests  Some things can’t be checked automatically  Things that only work as root  Details of system object formats  For these, autoconf provides system- dependent checks  Check the system type of either the build or the host system  Standard GNU naming system  i686-unknown-linux-gnu  sparc-sun-solaris  Use shell pattern matching on these names

13-Jul-15Advanced Programming Spring Custom tests  Sometimes you need to check for things that autoconf doesn’t already have tests for  You can write custom tests:  AC_TRY_CPP, AC_TRY_COMPILE, AC_TRY_LINK, AC_TRY_RUN  Try to preprocess / compile / link / run a specific fragment of C code.  Specify actions to take if test succeeds or fails.

13-Jul-15Advanced Programming Spring Results of custom tests  Custom tests need to be able to output their results  AC_DEFINE  Define a C preprocessor symbol in config.h  AC_SUBST  Substitute a variable pattern into Makefile.in  AC_CACHE_CHECK  Cache a variable in config.cache for future configure runs  AC_MSG_CHECKING / AC_MSG_RESULT  Output messages telling the user that something’s being checked

13-Jul-15Advanced Programming Spring Subtleties of custom tests  Autoconf actually works by using the m4 macro processor to create a shell script  So you can embed your own shell (/bin/sh) code in your custom tests  HOWEVER:  You can’t just write bash code and expect everything to work!  Since the point of the./configure script is to run anywhere, you need to write shell code that can run on any Unix system’s shell.  Lowest-common-denominator scripting

13-Jul-15Advanced Programming Spring Custom libraries of tests  If you need to execute your own tests, you can write autoconf functions  AC_DEFUN defines new functions  Custom functions can be embedded into a custom file  aclocal.m4: project-specific custom functions  acsite.m4: system-wide custom functions

13-Jul-15Advanced Programming Spring Other parts of the GNU build environment  automake  Automates creation of Makefile.in.  Automatically supports make clean, make install, building outside the source directory, creating.tar.gz distributions, etc.  Good for simple projects; not very flexible for complex projects  libtool  Creating shared libraries, and dynamically-loadable-libraries, is wildly different on all the platforms that support them  Libtool is a shell script that encapsulates the knowledge of how to do this, how to set load paths automatically, and so forth.