הלינקייה: מגזין חודשי למפתחים

רוצה לשמוע על כל האירועים, המדריכים, הקורסים והמאמרים שנכתבו החודש ?
הלינקייה הינו מגזין חופשי בעברית שמשאיר אותך בעניינים.
בלי ספאם. בלי שטויות. פעם בחודש אצלך בתיבה.

Targets

#############
# In make, we can specify the same
# target more than once. Makes takes all
# the dependencies into account when building
# a dependency tree for the project
#############
 
students: john jack jane
 
john jack jane: introducing
 
introducing:
        @echo "Hello Class"
 
jack:
        @echo "Jack, he is a banker"
 
jane:
        @echo "And Jane, she is a clerk"
 
john:
        @echo "John can sing well"
 
########################################
# Automatic make variables are useful when 
# we need to further reduce repetition. 
# Make provides us with access to its working data
# and this saves us both typing and mistakes
# $@ is the current target, $^ is the file list of
# all the prerequisites, and $< is the first prerequisite
 
objects = source1.o source2.o source3.o
target = runme
RM = rm -f
 
$(target): $(objects)
	@echo "Building Executable $@"
	@cc $^ -o $@
 
source1.o: source1.c header1.h
	@cc -c $<
 
source2.o: source2.c header2.h
	@cc -c $<
 
source3.o: source3.c header1.h header2.h
	@cc -c $<
 
clean:
	@echo "Cleaning Up"
	@$(RM) $(target) $(objects)
##########################################
# The .PHONY keyword is a special target. GNU make
# has several of those, and we'll talk about them
# during the course. 
# A special target has other targets as prerequisites
# and defines a special meaning on those targets.
#
# The .PHONY target means any target marked as a prerequisite
# will ALWAYS be considered as 'out-of-date', even if there is
# a file with the same name. 
# Marking a target as .PHONY is very important for targets that
# should get executed every time, such as the clean
 
objects = source1.o source2.o source3.o
target = runme
RM = rm -f
 
.PHONY: clean
 
$(target): $(objects)
	@echo "Building Executable $@"
	@cc $^ -o $@
 
source1.o: source1.c header1.h
	@cc -c $<
 
source2.o: source2.c header2.h
	@cc -c $<
 
source3.o: source3.c header1.h header2.h
	@cc -c $<
 
clean:
	@echo "Cleaning Up"
	@$(RM) $(target) $(objects)
 
######################################
# Here we have another example for a PHONY target
# This one calculates available space on device before creating
# the bigfile.bin 
# make-bigfile is marked phony because it is not dependant on
# files and timestamps, but rather on available drive space
 
.PHONY: make-bifile all
 
all: make-bigfile
 
make-bigfile: df
        dd bs=1024 count=10 if=/dev/random of=bigfile.bin
 
.PHONY: df
 
df:
        df -k . | awk 'NR == 2 { printf( "%d available\n", $$4 ) }'
.PHONY: cleanall cleanobj cleandiff
 
cleanall : cleanobj cleandiff
        rm program
 
cleanobj :
        rm *.o
 
cleandiff :
        rm *.diff
course: