DOC PREVIEW
CMU CS 15441 - Makefiles, Unix, and Project 1 Q&A

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Makefiles, Unix, and Project 1 Q&A15-441: Recitation 2September 12, 2007OverviewToday, I will try to teach you three things.You may also learn something about:•gcc•make and Makefiles•How to use Unix effectivelyProject 1 Q&AD.R.Y.Rule 1: Don’t Repeat YourselfD.R.Y.Rule 1: Don’t Repeat Yourself(except for emphasis)Compiling a Program: gccCompile a source file into a binary% gcc source.c lib.c –o binaryCompile a source file into a .o file% gcc –c source.c% gcc –c lib.cCompile .o files into a binary% gcc lib.o source.o –o binaryMore advanced gccCompile a source file with debugging hooks% gcc –g source.c –o binary% gdb binaryActivate all warnings, treat warnings as errors% gcc –Wall –Werror …Compile with optimizations; speeds up binary% gcc –O2 …Set a predefined macro (same as #define DEBUG)% gcc –DDEBUG …Use cases% gcc –g –Wall –Werror –c source.c –o source.o% gcc –g –Wall –Werror –c lib.c –o lib.o% gcc –g –Wall –Werror lib.o source.o –o binaryBut…Don’t Repeat YourselfMakefiles: Simplify% gcc –g –Wall –Werror –c source.c –o source.o% gcc –g –Wall –Werror –c lib.c –o lib.o% gcc –g –Wall –Werror lib.o source.o –o binarySimplify and modularize…CC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binaryMakefiles: Simplifytarget: dependency1 dependency2Unix command (start line with a TAB)Unix command…% gcc lib.o source.o –o binarybinary: lib.o source.ogcc lib.o source.o –o binarybinary: lib.o source.ogcc -g -Wall lib.o source.o –o binarylib.o: lib.cgcc -g -Wall –c lib.c -o lib.osource.o: source.cgcc -g -Wall –c source.c –o source.oclean:rm *.o *~ binarybinary: lib.o source.ogcc -g -Wall lib.o source.o –o binarylib.o: lib.cgcc -g -Wall –c lib.c -o lib.osource.o: source.cgcc -g -Wall –c source.c –o source.oclean:rm *.o *~ binaryCC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binary$(OUTPUT): lib.o source.o$(CC) $(CFLAGS) lib.o source.o –o $(OUTPUT) lib.o: lib.c$(CC) $(CFLAGS) –c lib.c -o lib.osource.o: source.c$(CC) $(CFLAGS) –c source.c –o source.oclean:rm *.o *~ $(OUTPUT)CC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binary$(OUTPUT): lib.o source.o$(CC) $(CFLAGS) lib.o source.o –o $(OUTPUT) lib.o: lib.c$(CC) $(CFLAGS) –c lib.c -o lib.osource.o: source.c$(CC) $(CFLAGS) –c source.c –o source.oclean:rm *.o *~ $(OUTPUT)CC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binaryOBJFILES = lib.o source.o$(OUTPUT): $(OBJFILES)$(CC) $(CFLAGS) $(OBJFILES) –o $(OUTPUT) lib.o: lib.c$(CC) $(CFLAGS) –c lib.c -o lib.osource.o: source.c$(CC) $(CFLAGS) –c source.c –o source.oclean:rm *.o *~ $(OUTPUT)CC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binaryOBJFILES = lib.o source.o$(OUTPUT): $(OBJFILES)$(CC) $(CFLAGS) $(OBJFILES) –o $(OUTPUT) lib.o: lib.c$(CC) $(CFLAGS) –c lib.c -o lib.osource.o: source.c$(CC) $(CFLAGS) –c source.c –o source.oclean:rm *.o *~ $(OUTPUT)CC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binaryOBJFILES = lib.o source.o$(OUTPUT): $(OBJFILES)$(CC) $(CFLAGS) $(OBJFILES) –o $(OUTPUT) %.o: %.c# $< = the source: %.c# $@ = the target: %.o$(CC) $(CFLAGS) –c $< -o $@clean:rm *.o *~ $(OUTPUT)Using a Makefile% make% make cleanM-x compileThat’s it!More about MakefilesRule 2: Use the Google.Google: “make tutorial”Google: “makefile example”Google: “makefile template”Simple Scripting% ./server 6667 &% cat testfile.01 | ./testscript.py% cat testfile.02 | ./testscript.py% killall -9 serverSimple Scripting#/bin/shecho “Starting server on port 6667.”./server 6667 &SERVERPID = $!echo “Running test files.”cat testfile.01 | ./testscript.pycat testfile.02 | ./testscript.pyecho “Killing server process.”kill $(SERVERPID)#/bin/shTESTFILES=testfile.01 testfile.02 testfile.03echo “Starting server on port 6667.”./server 6667 &SERVERPID = $!for testfile in $(TESTFILES); doecho “Running test file ‘$testfile’”cat $testfile | ./testscript.pyfiecho “Killing server process.”kill $(SERVERPID)CC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binaryOBJFILES = lib.o source.oall: $(OUTPUT)$(OUTPUT): $(OBJFILES)$(CC) $(CFLAGS) $(OBJFILES) –o $(OUTPUT) %.o: %.c$(CC) $(CFLAGS) –c %< -o %@clean:rm *.o *~ $(OUTPUT)CC = gccCFLAGS = -g –Wall –WerrorOUTPUT = binaryOBJFILES = lib.o source.oall: $(OUTPUT) test$(OUTPUT): $(OBJFILES)$(CC) $(CFLAGS) $(OBJFILES) –o $(OUTPUT) %.o: %.c$(CC) $(CFLAGS) –c %@ -o %<test: $(OUTPUT)sh ./testscript.shclean:rm *.o *~ $(OUTPUT)UnixDebugging: gdb, valgrindScripting: Perl, Python, RubyWe will cover these in later recitations…Editors: vi, emacs, ed, whateverTools: sed, awk, grep, find, wget, tarInstalling Unix packagesUnixUnix Philosophy:Do one thing, and do it well.Rule 3:Learn one thing at a time, and learn it well.How do I……find all instances of “func_name”:% grep –r “func_name”…replace all instances of bad_func_name to good_func_name:% sed –e “s/bad_func_name/good_func_name/g”\source.c > source.c.newHow do I……find a file named “source.c”:% find . –name “source.c”…download a .tar.gz file from the Internet:% wget http://address/to/file.tar.gz…untar and unzip the tarball:% tar xzvf file.tar.gzHow do I……install a package from source:% wget http://address/to/file.tar.gz% tar xzvf file.tar.gz% cd file% less README (always important!)% ./configure% make && make installIn General…Use the keyboard.(Touching the mouse is a cache miss.)Project 1Checkpoint 1: Any problems?Checkpoint 2: Be ready for it soon!Due date: It will come faster than you


View Full Document

CMU CS 15441 - Makefiles, Unix, and Project 1 Q&A

Documents in this Course
lecture

lecture

34 pages

lecture

lecture

38 pages

lecture

lecture

18 pages

lecture

lecture

28 pages

lecture

lecture

11 pages

Lecture

Lecture

64 pages

lecture

lecture

10 pages

lecture

lecture

19 pages

Lecture 6

Lecture 6

43 pages

Exam

Exam

14 pages

lecture

lecture

38 pages

Debugging

Debugging

23 pages

lecture

lecture

60 pages

review

review

27 pages

lecture

lecture

12 pages

The Web

The Web

28 pages

Lecture

Lecture

40 pages

lecture

lecture

42 pages

lecture

lecture

9 pages

lecture

lecture

10 pages

lecture

lecture

49 pages

lecture

lecture

26 pages

Project

Project

5 pages

lecture

lecture

40 pages

lecture

lecture

9 pages

lecture

lecture

41 pages

lecture

lecture

32 pages

lecture

lecture

36 pages

lecture

lecture

34 pages

lecture

lecture

45 pages

lecture

lecture

26 pages

lecture

lecture

6 pages

lecture

lecture

51 pages

Project

Project

16 pages

lecture

lecture

44 pages

lecture

lecture

13 pages

lecture

lecture

42 pages

lecture

lecture

36 pages

Project

Project

13 pages

Project

Project

33 pages

lecture

lecture

43 pages

lecture

lecture

49 pages

Load more
Download Makefiles, Unix, and Project 1 Q&A
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Makefiles, Unix, and Project 1 Q&A and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Makefiles, Unix, and Project 1 Q&A 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?