CSC161 2010F, Class 30: Make, Revisited Overview: * About Make. * Your Questions. * A Collaborative Makefile. Admin: * NO LAB TODAY! * I hope you had a great break. * Who saw "The Social Network" and its evil portrayal of CS? * Returned: HW5, Exam 1. * Sorry for the delay. * That's all I'm grading until HW6 and Exam2. * I got more responses for today's reading. Thanks. Some of you asked enough questions that I probably did not need everyone's. * Reading for Tuesday: K&R 5.1 and 5.2. * Are there questions on Assignment 6? Assignment 6 * For the Fibonacci sequence, can we use the general formula? * Sure, if you think it works correctly. * You should try to avoid computing the sequence recursively * Bring more questions tomorrow! Make * A long-standing and widely-used Unix tool for managing "builds" * You describe the steps necessary to create something (an application, a document, whatever) * You describe dependencies * Make figures out the ordering * One person can describe the structure of building, others can create the parts involved in the building * Makefiles includes: * Variable definitions * Rules TARGET: PREREQUISITES INSTRUCTIONS * Comments * A few other notational conveniences * In most Unix projects, you will see that Makefiles include the following targets: * default: Whatever is most important (could be a list of options) * all: all the programs/documents/whatever * test: test the programs * install: put the program/documents where they belong (not in this class) * clean: Clean up after yourself * package: Build the tarball * Four kinds of variables used in Makefiles * Ones the user designs herself * Ones expected by the system that the user might decide to customize * CFLAGS * LDLIBS * ... * Ones provided as part of the standard make packagew $(CC) - our C compiler $(COMPILE.c) - our C compiler with flags * Automatic variables: Ones that make your life easier $@ - the target $< - the first prerequisite $^ - all the prereqs $? - prereqs that are newer than the target $* - is the prefix of the target Your Questions * Is make basically a new language we need to learn? * Yes, but it's fairly simple (or at least what you will use) C-related questions * I need some review of what .o files are for. * Partially compiled C files * Three step compiling process * Preprocess (from .c to .cpp) * Translate to object code (from .cpp to .o) * Link together .o files to the executable * Basically, .o files are expensive to produce, but not so expensive to link, so we try not to rebuild them if not necesssary * I don't know what -I DIRECTORY does, exactly. * Tells the compiler where to look for #include "foo.h" * Generally, I don't understand most of this stuff about libraries. Why are they necessary? * Saves computing time to build, encourages reuse * For now, we jsut use .o files as our libraries * Can we talk a bit more about CFLAGS and similar things? * Instructions to the C compiler. * -Wall - warn me about stupid code * -g - set up for the debugger * -O - make it run fast, but maybe not look so much like the original * -I dirs - where to look for include files * -lm - Use the Math library * I'll teach you other important ones as they come along * -lex (not correct) - Use lex library Linux-related questions * What is a 'jar'? - A collection of compiled Java programs * Is a lexer a program that is assumed to be built for the implementation of this program, or is it some automatic file that is generated, or what? * A library that says "When I see this pattern, do this thing" * What does flex do? * Builds the C code from a simple syntax * What does this mean: First, we setup our experiment by creating an empty yacc source file and registering with RCSusing ci (that is, we want a version-controlled yacc source file) * Not all translation is easy - Yacc is a tool for doing "parsing" * Version-control - A sensible way to keep lots of versions of a file around so that multiple people can work on it * What is bison and what does it do? * The successor to yacc. It builds parsers. * Does the suffix .y signify anything specific? * It's a yacc/bison file * What is an 'awk' filter? * A cool text processing language Make * I still don't quite understand $(...) * How you say "Include the value of this variable" * I noticed that the text used a "rm" command in the makefile - does this mean we can use any valid terminal command in our makefile rules? * Yes, that's the idea * I'm a little bit confused about phony targets, though. Because they don't represent files, are phony targets kind of like functions? * Basically, meta-instructions * I was wondering if you might be able to show us how to use wildcards in our makefiles. * How does this work? prog: *.c $(CC) -o $@ $^