Lecture Nine Perl CGI and Make 2112022 COEN

  • Slides: 13
Download presentation
Lecture Nine Perl, CGI, and Make 2/11/2022 COEN 276 Winter 98 John Xiao 1

Lecture Nine Perl, CGI, and Make 2/11/2022 COEN 276 Winter 98 John Xiao 1

make • A tool for maintaining programming projects • It allows the users to

make • A tool for maintaining programming projects • It allows the users to specify dependencies among different source and binary files • make [-isrntqpd] [-f file] [macro-definition] [targets] 2/11/2022 COEN 276 Winter 98 John Xiao 2

make Options: -i ignore error code returned by a command -s silent mode -r

make Options: -i ignore error code returned by a command -s silent mode -r suppress built-in rules -n no execute mode -t touch target file -q question before change -p printout macro definitions and target descriptions -d debug mode -f alernative make file name 2/11/2022 COEN 276 Winter 98 John Xiao 3

make – Makefile: prog: x. o y. o z. o cc -o prog x.

make – Makefile: prog: x. o y. o z. o cc -o prog x. o y. o z. o -lm x. o: x. c def. h cc -c x. c y. o: y. c def. h cc -c y. c z. o: z. c cc -c z. c 2/11/2022 COEN 276 Winter 98 John Xiao 4

make • make does depth-first search on the dependency graph x. c x. o

make • make does depth-first search on the dependency graph x. c x. o prog y. o z. o def. h y. c z. c 2/11/2022 COEN 276 Winter 98 John Xiao 5

Makefile Format • makefile contains explicit dependency lines: target 1 [target 2 …]: [dependency

Makefile Format • makefile contains explicit dependency lines: target 1 [target 2 …]: [dependency …] [; commands] [#commnets] target 1 [target 2 …]: [dependency …] [<tab> commands] [#comments] – only command lines start with a tab character – no other lines should start with a tab. 2/11/2022 COEN 276 Winter 98 John Xiao 6

Makefile Details • commands are bourne shell commands • a set of built-in rules

Makefile Details • commands are bourne shell commands • a set of built-in rules are used by make, e. g. : . c. o: $(CC) $(CFLAGS) -c $< if. o depends on. c and f. c is newer, compile f. c • Each command is executed by a different subshell. 2/11/2022 COEN 276 Winter 98 John Xiao 7

make Macro • Syntax: Name=String E. g. LIB=/users 3/foo/lib • Predefined Macros for C

make Macro • Syntax: Name=String E. g. LIB=/users 3/foo/lib • Predefined Macros for C CC=cc AS=as CFLAGS= -O -g LOADLIBS= 2/11/2022 COEN 276 Winter 98 John Xiao 8

make Macro • Built-in Macro (evaluated each time make reads a dependency line) $*

make Macro • Built-in Macro (evaluated each time make reads a dependency line) $* - the basename (suffix removed) of the current target test. o : test. h cc -c $*. c # cc -c test. c $@ - the full target name $? - the list of dependencies that are newer than the target libops: ineract. o shed. o gen. o ar r $@ $? # put any. o files newers than libops into libops $$ - the $ sign. 2/11/2022 COEN 276 Winter 98 John Xiao 9

make -- Suffix Rules make uses some conventions to simplify the makefille. Example: prog:

make -- Suffix Rules make uses some conventions to simplify the makefille. Example: prog: x. o y. o z. o cc -c …. Create target based on suffix rules: Eg. x. c. If x. c is newer than x. o, x. c is compiled. 2/11/2022 COEN 276 Winter 98 John Xiao 10

make -- Suffix Rules Predefined Suffix rules : . SUFFIXES: . o. c. s.

make -- Suffix Rules Predefined Suffix rules : . SUFFIXES: . o. c. s. c. o: $(CC) $(FLAGS) -c $<. s. o: $(AS) $(ASFLAGS) -o $@ $< – $< evaluates to whatever the dependecies triggered the rule. $* is similar to $< except that the suffix is removed. 2/11/2022 COEN 276 Winter 98 John Xiao 11

Makefile Example • Usage: make app make clean • Content: MYPROG=/usr/local/myprog INCLUDE=$(MYPROG)/include BIN=$(MYPROG)/bin LIB=$(MYPROG)/lib

Makefile Example • Usage: make app make clean • Content: MYPROG=/usr/local/myprog INCLUDE=$(MYPROG)/include BIN=$(MYPROG)/bin LIB=$(MYPROG)/lib CFLAGS= -g -I$(INCLUDE) HEADERS=interface. h dbms. h SOURCE =driver. c interface. c dbms. c OBJECT=$(SOURCE: . c=. o) 2/11/2022 COEN 276 Winter 98 John Xiao 12

Makefile Example (cont. ) app: ($OBJECT) $(CC) -o app $(OBJECT) -L$(LIB) # @ suppress

Makefile Example (cont. ) app: ($OBJECT) $(CC) -o app $(OBJECT) -L$(LIB) # @ suppress the comman line printing # $$ to make a $-sign for the shell command print: @echo print source files @for file in $(SOURCE) do pr -n $$file; done clean: @rm -f *. o 2/11/2022 COEN 276 Winter 98 John Xiao 13