1
|
- Richard C. Davis
UW CSE – 11/17/2006
- Lecture 19 – Build Scripting
|
2
|
- HW6 went out, project directories set up
- It was late, sorry
- Hopefully, it will be short
- Societal Implications on Monday
- Do the reading
- Send in your summary
|
3
|
- Complaints of policy violations
- The Gilligan's Island Rule
- Please observe it
- It's for your benefit
- It strikes a balance between
- Need to collaborate
- Need to evaluate students individually
- Congrats to all who are walking the line
|
4
|
- Gilligan's Island Rule Do's and Don'ts
- Do discuss specifics of homework
- Do arrange times with friends for discussions
- Do bring your own code into discussions
- Do ignore the rule when talking to partner
- Don't modify turn-in for 30 minutes after discussion
- Don't discuss homework in the labs
- Don't keep written records from discussions
|
5
|
- Tools for working on larger projects
|
6
|
- Build Scripting
- Steps in building an executable
- The need for scripting
- Execute repetitive commands
- Avoid repeating unnecessary build steps
- Recompilation Management
|
7
|
|
8
|
|
9
|
|
10
|
- Many files, many steps
- And they keep piling up
- Steps for generating documentation
- Steps for running tests
- Steps for generating source files (not in 303)
- Need help to manage steps
- So you can give a whole project to others
- So you can avoid repeating steps
- Big projects can take many hours to build
- What if you want to change one line in one file?
|
11
|
- gcc -Wall heaptest.c heap.c allocreclist.c
- How have you dealt with this?
- Retype it every time
- Use up-arrow or history
- Shame! (You have to
re-type it after logout)
- Use alias or bash script
- Use a Makefile
|
12
|
- Dependency DAG avoids unnecessary work
- To create target T you need
- Sources s1, s1,… sn
- Command c that creates T from sources
- If T is newer than every source, don't run c
- Recursive building:
- A source s may be a target with it's own dependencies
- In this case, T is dependent on s's sources as well
- Cycles are problematic in theory, but can be handled
- (DAG =3D Directed Acyclic Graph)
|
13
|
- Compiling .c /.cpp creates .o
- Target: .o file
- Sources:
- .c /.cpp file
- All .h files included by .c /.cpp file
- Plus all .h files included by those .h files …
- This is why careful header design is important!
- Creating an executable (linking)
- Target: executable file
- Sources: All .o files
|
14
|
|
15
|
- Imagine a script that handles this
- Inputs:
- A dependency DAG (targets, sources, commands)
- A current target to build
- Actions
- Determine which sources are out of date
- Build sources (in order) if necessary
- This is what build tools do!
- Many exist: make, ant, most IDEs
|
16
|
- target: sources
-
command
- Syntax Gotchas
- The colon after the target is required
- Command lines musts start with TAB
- Can have multiple command lines for each target
- Multi-line command? End previous line with \
- Which shell language for commands?
- Whatever set in SHELL environment variable
|
17
|
- Use gcc and g++ with the same options
- To compile without linking: -c
- To specify file name of output: -o filename
- To link: run on .o files instead of .c/.cpp files
- g++ -o programName class1.o class2.o
|
18
|
- heaptest: heaptest.o heap.o allocreclist.o
- gcc=
-o
heaptest heaptest.o heap.o allocreclist.o
- heaptest.o: heaptest.c heap.h
- gcc -Wall -o
heaptest.o -c heaptest.c
- heap.o: heap.c heap.h allocreclist.h
- gcc -Wall -o h=
eap.o
-c heap.c
- allocreclist.o: allocreclist.c allocreclist.h
- gcc -Wall -o
allocreclist.o -c allocreclist.c
|
19
|
- At the prompt
- -bash-3.1$ make -f makefileName targetName
- Defaults
- If no -f: use a file named Makefile
- If no target specified: use the first one
|
20
|
- Summary
- scripting + dependency analysis =3D make
- Not language or tool specific
- Rest of lecture: better Makefiles
- Short and modular
- Easy to reuse (different flags, platforms, etc.)
- Useful for many tasks
- Automatically maintained dependencies
- Trick most of us use: Copy Makefiles!!!
|
21
|
- CC =3D gcc
- CFLAGS =3D -Wall
- OBJECTS =3D heap.o heaptest.o allocreclist.o
- heaptest: $(OBJECTS)
-
gcc -o heaptest $(OBJECTS)
- heap.o: heap.c heap.h allocreclist.h
-
$(CC) $(CFLAGS)-o heap.o -c heap.c
- Why do this?
- Easier to change build options for everything
- Easier to reuse Makefiles
|
22
|
- clean:
-
rm $(OBJECTS) heaptest
- Why "clean"?
- Convention: Way to "start over"
- Type make clean to clear away all objects
- Type make after that to start build from scratch
- Note: no target, so it will always run command
|
23
|
- Consider using these
- $@ for target
- $^ for all sources
- $< for left-most source
- heaptest: $(OBJECTS)
-
$(CC) $(CFLAGS) -o $@ $^
- heap.o: heap.c heap.h allocreclist.h
-
$(CC) $(CFLAGS) -o $@ -c $<
|
24
|
- Manual tracking of dependencies is a pain
- Forget a dependency?
- Introduce subtle bugs
- Get confusing build errors if you're lucky!
- Generating dependencies automatically
- Use gcc -M (or -MM or -MG)
- Use an IDE that does this for you
- This is beyond the scope of this class
|
25
|
- Always script complicated build tasks
- make can handle building in any language
- Lots of tricks for keeping Makefiles neat
- Lots of conventions in Makefiles
- Learn about dependency generation
- Not in this class, but VERY handy
- If you use an IDE, this is handled for you
|
26
|
- Digital Rights Management
|