Cs3157-fall2002- lect22 1 advanced programming -- fall 2002 lecture #22 -- mon nov 25  web programming review  slides from Henning Schulzrinne, coms.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Introduction to Linux Recap Installing programs Introduction to Video Editing with Linux.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Lecture 11 Server Side Interaction
Operating-System Structures
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Server-Side vs. Client-Side Scripting Languages
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
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.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
1 CS6320 – Why Servlets? L. Grewe 2 What is a Servlet? Servlets are Java programs that can be run dynamically from a Web Server Servlets are Java programs.
Definitions, Definitions, Definitions Lead to Understanding.
Low level CASE: Source Code Management. Source Code Management  Also known as Configuration Management  Source Code Managers are tools that: –Archive.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
13-Jul-15Advanced Programming Spring 2002 autoconf Jonathan Lennox Department of Computer Science Columbia University.
Chapter 6: Hostile Code Guide to Computer Network Security.
Slide 1 of 9 Presenting 24x7 Scheduler The art of computer automation Press PageDown key or click to advance.
Quick Tour of the Web Technologies: The BIG picture LECTURE A bird’s eye view of the different web technologies that we shall explore and study.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
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.
F13 Forensic tool analysis Dr. John P. Abraham Professor UTPA.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Linux Operations and Administration
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 Intro to Linux - getting around HPC systems Himanshu Chhetri.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Software Engineering in Robotics Packaging and Deployment of Systems Henrik I. Christensen –
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
1 Apache. 2 Module - Apache ♦ Overview This module focuses on configuring and customizing Apache web server. Apache is a commonly used Hypertext Transfer.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Putting it all together Dynamic Data Base Access Norman White Stern School of Business.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 03: Web-App Architectures Professor Chen Li Department of Computer Science CS122B.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Debugging and Profiling With some help from Software Carpentry resources.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Data Display Debugger (DDD)
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Chapter 13 A & B Programming Languages and the.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Lecture 1 Page 1 CS 111 Summer 2013 Important OS Properties For real operating systems built and used by real people Differs depending on who you are talking.
Hank Childs, University of Oregon April 13 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Building programs LinuxChix-KE. What happens in your CPU? ● It executes a small set of instructions called "machine code" ● Each instruction is just a.
Developing Portable Applications ● Introduction GNU autotools – GNU toolchain ● Goals - cross-platform ● Supported platforms (POSIX compliant) ● GNU autotools.
CS 330 Class 7 Comments on Exam Programming plan for today:
WWW and HTTP King Fahd University of Petroleum & Minerals
Chapter 2: System Structures
Chapter 27 WWW and HTTP.
Appendix F C Programming Environment on UNIX Systems
Compiler vs linker The compiler translates one .c file into a .o file
SPL – PS1 Introduction to C++.
Presentation transcript:

cs3157-fall2002- lect22 1 advanced programming -- fall 2002 lecture #22 -- mon nov 25  web programming review  slides from Henning Schulzrinne, coms w3995 advanced programming, spring 2002  programming tools review  slides from Henning Schulzrinne, coms w3995 advanced programming, spring 2002  installation tools  autoconf  slides from Jonathan Lennox, coms w3995 advanced programming, spring 2002

cs3157-fall2002- lect22 2 www

cs3157-fall2002- lect22 3 www: web programming  Web services vs. "classical" web programming  Client vs. server programming  client: JavaScript, Java  HTML-centric vs. program-centric  HTML-centric: PHP, ASP  cgi, fast-cgi  (Java) servlet  data model: Java servlet, database

cs3157-fall2002- lect22 4 www: web services vs. web programming  web services = remote procedure call  methods and responses  generally, for machine consumption  web programming  generate HTML pages  for humans  often, database-driven

cs3157-fall2002- lect22 5 www: client vs. server programming  Execute code on client:  download Java applet  self-contained programming environment  JavaScript:  modify and get values from HTML ("document object model" – DOM)  Execute code on server  generate document  state maintenance (HTTP stateless)  login, shopping cart, preferences

cs3157-fall2002- lect22 6 www: taxonomy embedded in HTMLseparate serve r SSI (server-side include), ASP (active server pages), PHP (hypertext preprocessor), JSP (java server page), CFM (cold fusion markup language) server API (NSAPI - - netscape server application programmer interface), CGI (common gateway interface), servlets (applet that runs on a server) clientJavaScriptJava applets, plug-ins

cs3157-fall2002- lect22 7 www: web state  State:  stateless  state completely stored on client  state referenced by client, stored on server (most common)  Mechanisms:  hidden form fields  URL parameters  cookies (HTTP headers)

cs3157-fall2002- lect22 8 www: web as remote procedure call (RPC)  request = HTTP GET, PUT  response (result): headers + body  object identifier ~ URL  typed data (XML) vs. HTML  ranges from constant  mostly constant  completely on-demand

cs3157-fall2002- lect22 9 www: server-side include (SSI) .shtml documents (or configured by default for all.html documents)  A type of HTML comment that directs the web server to dynamically generate data for the web page whenever it is requested.  include in HMTL comments:  limited scripting: if/else, include, exec, variables  primarily for conditional inclusion, boilerplate  security issues: #exec

cs3157-fall2002- lect22 10 www: SSI example = test.shtml last modified file size =

cs3157-fall2002- lect22 11 www: common gateway interface (cgi)  Earliest attempt at dynamic web content  language-independent  passes HTTP request information via  command line (ISINDEX) – rarely used  environment variables: system info + query string (GET)  request body (POST)  standard input  return HTML or XML via standard output  non-parsed headers (NPH) return complete response

cs3157-fall2002- lect22 12 www: cgi arguments  application/x-www-form-urlencoded format  space characters  "+"  escape (%xx) reserved characters  name=value pairs separated by &  GET: foo.cgi?name=John+Doe&gender=male&famil y=5&city=New+York&other=abc%0D%0Adef&ni ckname=J%26D  POST: include in body of message

cs3157-fall2002- lect22 13 www: cgi mechanics  either called.cgi in HTML directory or stored in cgi- bin  in CS, both / home/alice/html/foo.cgi or /home/alice/secure_html/foo.cgi work  executable (script file)  usually runs as user nobody  store secret data off the document tree!

1-Oct-15 programming tools

cs3157-fall2002- lect22 15 tools: what are they for?  Creating code modules (compiler)  Creating program from modules (linker)  Compiling groups of programs (dependencies)  Debugging and tracing code  Profiling and optimization  Documentation: derive from code  Coordination and “memory”  Testing  User installation  User feedback

cs3157-fall2002- lect22 16 tools: compiler  Convert source code to object modules .o: external references not yet resolved  gcc -c: compiles only (doesn't link)

cs3157-fall2002- lect22 17 tools: example (1) /* h.c */ #include int main() { char s[10] = "simon"; printf( "hello %s\n",s ); }

cs3157-fall2002- lect22 18 tools: example (2) unix$ gcc -g -c h.c -o h.o unix$ nm h.o T main U memset U printf unix$ gcc -g h.o -o h.x unix$ nm h.x a *ABS* t.nope ? _DYNAMIC c4 b _END_ c ? _GLOBAL_OFFSET_TABLE_ a8 ? _PROCEDURE_LINKAGE_TABLE_ ? _START_...

cs3157-fall2002- lect22 19 tools: linker  Combine.o and.so and/or.a into single a.out executable module .so/.dll: dynamically loaded at run-time unix$ ldd a.out libc.so.1 => /usr/lib/libc.so.1 libdl.so.1 => /usr/lib/libdl.so.1

cs3157-fall2002- lect22 20 tools: creating a static library  static library for linking: libsomething.a  create.o files: unix$ gcc –c helper.c  create library: unix$ ar rv libsomething.a *.o unix$ ranlib libsomething.a  use library: unix$ gcc –L/your/dir –lsomething

cs3157-fall2002- lect22 21 tools: creating a dynamic library  Details differ for each platform unix$ gcc –shared –fPIC –o libhelper.so *.o  usage is same as for static library  can also define LD_LIBRARY_PATH

cs3157-fall2002- lect22 22 tools: testing  Every module and functionality needs to have an (automated) test  Regression testing  change  test new functionality  then test old functionality to make sure it is backwards compatible  Easy for simple functions

cs3157-fall2002- lect22 23 tools: program tracing operating system kernel libraries user program user space kernel memory space printf() write()

cs3157-fall2002- lect22 24 tools: program tracing  Simple debugging: find out what system calls a program is using  truss on Solaris, strace on Linux  does not require access to source code  does not show stdio calls, but can use –u libc  -f: follow children  -p: attach to existing process (e.g., truss –p to see what process is doing when doing certain action)

cs3157-fall2002- lect22 25 truss example unix$ truss h.x execve(".//h.x", 0xEFFFFB38, 0xEFFFFB40) argc = 1 open("/usr/lib/libc.so", O_RDONLY) = 3 fstat(3, 0xEFFFF744) = 0 mmap(0x , 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xEF7B0000 mmap(0x , , PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xEF munmap(0xEF786000, 57344) = 0 mmap(0xEF794000, 33408, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, ) = 0xEF open("/dev/zero", O_RDONLY) = 4 mmap(0xEF79E000, 3524, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 4, 0) = 0xEF79E000 close(3) = 0 open("/usr/lib/libdl.so.1", O_RDONLY) = 3 fstat(3, 0xEFFFF744) = 0 mmap(0xEF7B0000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xEF7B0000 close(3) = 0 close(4) = 0 ioctl(1, TCGETA, 0xEFFFECE4) = 0 hello simon write(1, " h e l l o s i m o n\n", 12) = 12 lseek(0, 0, SEEK_CUR) = _exit(1)

cs3157-fall2002- lect22 26 tools: memory utilization -- top  Show top consumers of CPU and memory  updates periodically unix$ top load averages: 0.42, 0.22, :17: processes: 269 sleeping, 1 zombie, 3 stopped, 1 on cpu CPU states: 81.3% idle, 5.2% user, 13.4% kernel, 0.1% iowait, 0.0% swap Memory: 512M real, 98M free, 345M swap in use, 318M swap free PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND 144 root K 1728K sleep 33.3H 3.67% ypserv hgs K 2248K sleep 0: % tcsh hgs K 1352K cpu/0 0: % top 281 root K 2720K sleep 313: % amd kbutler M 8376K sleep 0: % lisp 1817 yjh K 7528K sleep 0: % emacs yjh K 7200K sleep 2: % emacs

cs3157-fall2002- lect22 27 tools: debugging  Interact with program while running  step-by-step execution  instruction  source line  procedure  inspect current state  call stack  global variables  local variables

cs3157-fall2002- lect22 28 Debugging  Requires compiler support:  generate mapping from PC to source line  symbol table for variable names  compile with -g option ( gcc -g )  unix debugger: gdb  useful for debugging core dumps: unix$ gdb h.x core … (gdb) where

cs3157-fall2002- lect22 29 tools: debugging example unix$ gdb h.x GNU gdb Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "sparc-sun-solaris2.5.1"... (gdb) break main Breakpoint 1 at 0x10750: file h.c, line 4. (gdb) run Starting program: /hmt/skol/u/3/e/eis2003/cs3157/h.x Breakpoint 1, main () at h.c:4 4 char s[10] = "simon"; (gdb)

cs3157-fall2002- lect22 30 tools: gdb hints  Make sure your source file is around and doesn’t get modified  Does not work (well) across threads

cs3157-fall2002- lect22 31 tools: gdb commands run argrun program call f(a,b)call function in program step Nstep N times into functions next Nstep N times over functions up Nselect stack frame that called current one down Nselect stack frame called by current one

cs3157-fall2002- lect22 32 tools: gdb break points break main.c:12set break point break fooset break at function clear main.c:12delete breakpoint info breakshow breakpoints delete 1delete break point 1 display xdisplay variable at each step

cs3157-fall2002- lect22 33 tools: graphical interface -- ddd (data display debugger)

cs3157-fall2002- lect22 34 tools: building programs  Programs consist of many modules  Dependencies:  if one file changes, one or more others need to change .c depends on.h -> re-compile .o depends on.c -> re-compile  executable depends on.o ’s -> link  library depends on.o -> archive  recursive!

cs3157-fall2002- lect22 35 tools: make  make maintains dependency graphs  based on modification times  Makefile as default name  make [–f makefile] [target]  if node newer than child, remake child target...: dependency command tab!

cs3157-fall2002- lect22 36 tools: make # makefile all: hello clean clean: rm –f *.o helper.o: helper.c OBJ = helper.o \ hello.o hello: $(OBJ) $(CC) $(CFLAGS) $(LDFLAGS) –o $(OBJ)

cs3157-fall2002- lect22 37 tools: make variables  implicit rules, e.g., a.c file into.o.c.o: $(CC) $(CFLAGS) $< of current target $?list of dependencies newer than target $<name of dependency file $*base name of current target $%for libraries, the name of member

cs3157-fall2002- lect22 38 tools: make depend depend: $(CFILES) $(HFILES) $(CC) $(CFLAGS) –M $(CFILES) >.state # works for GNU make and BSD make #if 0 include.state #endif #include “.state”

cs3157-fall2002- lect22 39 tools: make environment  Environment variables ( PATH, HOME, USER, etc.) are available as $(PATH), etc.  Also passed to commands invoked  Can create new variables (gmake): export FOOBAR = foobar

cs3157-fall2002- lect22 40 tools: user feedback – bug tracking  Automatically capture system crash information  non-technical users  privacy?  e.g., Netscape Talkback  User and developer bug tracking  make sure bugs get fixed  estimate how close to done

cs3157-fall2002- lect22 41 tools: bug tracking  Bugzilla

cs3157-fall2002- lect22 42 tools: development models  Integrated Development Environment (IDE)  integrate code editor, compiler, build environment, debugger  graphical tool  single or multiple languages  VisualStudio, JCreator, Forte, CodeWarrior,...  Unix model  individual tools, command-line

cs3157-fall2002- lect22 43 tools: source code management  problem: lots of people working on the same project  source code (C, Perl,...)  documentation  specification (protocol specs)  mostly on different areas  versions  released – maintenance only  stable – about to be released, production use  development, beta  different hardware and OS versions

cs3157-fall2002- lect22 44 tools: installation  Traditional:  tar (archive) file and gzip (compress)  *.tgz  *.tar.gz  "unzip", "untar"  then compile (make) or distribute binaries  often (should!) contains documentation, etc.  look for README, INSTALL, etc  Linux rpm  Solaris pkg  InstallShield

cs3157-fall2002- lect22 45 tools: *.tar.gz (1)  creating a tarred, gzipped file: unix$ tar cvf myfile.tar *  c = create  v = verify  f = file name unix$ gzip myfile.tar  creates myfile.tar.gz  compresses argument  or unix$ tar czvf myfile.tgz *  z = zip

cs3157-fall2002- lect22 46 tools: *.tar.gz (2)  using a tarred, gzipped file: unix$ gunzip myfile.tar.gz  creates myfile.tar  decompresses argument unix$ tar xvf myfile.tar *  x = extract  v = verify  f = file name  or unix$ tar xzvf myfile.tgz *  z = (un)zip

cs3157-fall2002- lect22 47 tools: rpm (1)  RedHat Linux package manager  Activities for an application:  Installation – on different architectures  Updates  Inventory: what’s installed  Un-install  Each Unix architecture seems to have one: Solaris pkg, RPM (

cs3157-fall2002- lect22 48 tools: rpm (2)  Package label, e.g., perl-5.001m-4:  software name  software version  package release  Package-wide information  date and time built  description of contents  total size of all files  grouping information  digital signature

cs3157-fall2002- lect22 49 tools: rpm (3)  Per-file information:  name of file and where to install it  file permissions  owner and group specification  MD5 checksum  file content

cs3157-fall2002- lect22 50 tools: using rpm  rpm –iinstall package, check for dependencies  rpm –eerase package  rpm –U upgrade package  rpm –qquery packages (e.g., -a = all)

cs3157-fall2002- lect22 51 tools: rpm -q unix$ rpm -q -i telnet Name : telnet Relocations: (not relocateable) Version : 0.17 Vendor: Red Hat, Inc. Release : 18.1 Build Date: Wed Aug 15 15:08: Install date: Fri Feb 8 16:50: Build Host: stripples.devel.redhat.com Group : Applications/Internet Source RPM: telnet src.rpm Size : License: BSD Packager : Red Hat, Inc. Summary : The client program for the telnet remote login protocol. Description : Telnet is a popular protocol for logging into remote systems over the Internet. The telnet package provides a command line telnet client. Install the telnet package if you want to telnet to remote machines. This version has support for IPv6.

cs3157-fall2002- lect22 52 tools: rpm info   but: current version (4.0) is a bit different

cs3157-fall2002- lect22 53 tools: doc++  documentation system for C/C++ and Java  generate LaTeX for printing and HTML for viewing  hierarchically structured documentation  automatic class graph generation (Java applets for HTML)  cross references  formatting (e.g., equations)

cs3157-fall2002- lect22 54 tools: doc++  Special comments: /** */, ///

cs3157-fall2002- lect22 55 tools: doc++ /** This is the famous "hello world" program, with more comments than H.W. 0 if no argc number of argv command-line */ #include int main(int argc, char *argv[]) { printf("Hello World!"); return 0; }

cs3157-fall2002- lect22 56 tools: doc++  docify to create minimal version  doc++ -d outdir hello.c

cs3157-fall2002- lect22 57 tools: other useful ones  configuration:  autoconf: configuration files  automake: make files  code generation:  indent (e.g., indent -kr -i2 hello.c ): automated indentation for C programs  lex, flex: lexical analyzers  yacc, bison: compiler generator

cs3157-fall2002- lect22 58 autoconf

cs3157-fall2002- lect22 59 autoconf: 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

cs3157-fall2002- lect22 60 autoconf: 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…

cs3157-fall2002- lect22 61 autoconf: 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

cs3157-fall2002- lect22 62 autoconf: 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

cs3157-fall2002- lect22 63 autoconf: 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.)

cs3157-fall2002- lect22 64 autoconf: solution is 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

cs3157-fall2002- lect22 65 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?”

cs3157-fall2002- lect22 66 autoconf: files used by developer. configure.in autoconf configure autoheader config.h.in aclocal.m4 acsite.m4

cs3157-fall2002- lect22 67 autoconf: files used by builder/installer. Makefile.in config.h.in configure Makefile config.h unix$./configure unix$./make config.cacheconfig.log config.status make

cs3157-fall2002- lect22 68 autoconf: 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

cs3157-fall2002- lect22 69 autoconf: 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

cs3157-fall2002- lect22 70 autoconf: 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

cs3157-fall2002- lect22 71 autoconf: 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)

cs3157-fall2002- lect22 72 autoconf: 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.)

cs3157-fall2002- lect22 73 autoconf: 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.

cs3157-fall2002- lect22 74 autoconf: 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

cs3157-fall2002- lect22 75 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’.

cs3157-fall2002- lect22 76 autoconf: 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

cs3157-fall2002- lect22 77 autoconf: output = Makefile  Some autoconf output is needed 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

cs3157-fall2002- lect22 78 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_BIGENDIA N integers are big- endian HAVE_SELECTselect() was found HAVE_STRUCT_PA SSWD_PW_GECOS struct passwd has the pw_gecos field.

cs3157-fall2002- lect22 79 autoconf: 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

cs3157-fall2002- lect22 80 autoconf: 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.

cs3157-fall2002- lect22 81 autoconf: 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

cs3157-fall2002- lect22 82 autoconf: 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

cs3157-fall2002- lect22 83 autoconf: 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

cs3157-fall2002- lect22 84 autoconf: 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.