13. Permissions, part2. Multifile compiling
Look at /usr/local/share/13_Permissions2/ on sugon server
- Describe what's there (filesystem objects and their attributes)
Gain access to the /usr/local/share/13_Permissions2/catalog/
- Describe what's there (a file probably)
- Read what's in the file
Multifile build and Make
Make on sugon server a directory named 13_Permissions2 (yes, this is bogus name, but nevertheless) and cd to it. All code shall reside here.
- (repeat) build sequence:
.c → (preprocessor / cc -E) → .c
.c → (translator / cc -S) → .s
.s → (assembler / cc -c) → .o
.o → (linker / cc or ld …) → binary
Many files: first all → .o, then link all *.o
⇒ extra *.o files (so called generates)
Write a simple two-file C program.
Make
manual (LR)
Simplified documentation in russian
Write a Makefile for the (1.) program
Provide clean: target to remove generates
Use $^ and $@ notation when defining rules
Use sqrt() function (do not forget -lm when linking)
H/W
Write a function countbytes(FILE *fp, int a, int b) that receives opened binary FILE *fp as the first argument and a pair of '0…255' integers a and b as the second and the third arguments. The function counts how many bytes a<=byte<=b are in the input file.
In second file write main() that parses three agruments (input file name and two integers), opens the file, calls countbytes(), closes the file and outputs countbytes() return value.
Create a Makefile for:
building countbytes program
- building 3 test input files
zeroes with 1000 zeroes
words with 1000 bytes from the start of /usr/share/dict/words file (or another english words long file)
random with 1000 random bytes
- running 5 tests against these files:
- searching 0 0 in zeros (program should print 1000)
- searching 10 100 in zeros (program should print 0)
searching 65 120 in words (program should print something)
- searching 200 220 in words (program should print 0)
searching 10 100 in random (program should print something)
clearing all the mess (all generates, including *.o, test files and prorram itself)