Total Hit Counter

To make Ready Your System To compile any package


To make Ready Your System To compile any package


Make

Make is a utility to maintain groups of programs. Upon execution of make(1)make read the rule file, "Makefile", and updates a target if it depends on prerequisite files that have been modified since the target was last modified, or if the target does not exist. The execution of these updates may occur concurrently.
The rule file syntax is the following.
target: [ prerequisites ... ]
 [TAB]  command1
 [TAB]  -command2 # ignore errors
 [TAB]  @command3 # suppress echoing
Here " [TAB] " is a TAB code. Each line is interpreted by the shell after make variable substitution. Use "\" at the end of a line to continue the script. Use "$$" to enter "$" for environment values for a shell script.
Implicit rules for the target and prerequisites can be written, for example, by the following.
%.o: %.c header.h
Here, the target contains the character "%" (exactly one of them). The "%" can match any nonempty substring in the actual target filenames. The prerequisites likewise use "%" to show how their names relate to the actual target name.
Table 12.10. List of make automatic variables
automatic variablevalue
$@target
$<first prerequisite
$?all newer prerequisites
$^all prerequisites
$*"%" matched stem in the target pattern

Table 12.11. List of make variable expansions
variable expansiondescription
foo1 := barone-time expansion
foo2 = barrecursive expansion
foo3 += barappend

Run "make -p -f/dev/null" to see automatic internal rules.

12.3. C

You can set up proper environment to compile programs written in the C programming language by the following.
# apt-get install glibc-doc manpages-dev libc6-dev gcc build-essential
The libc6-dev package, i.e., GNU C Library, provides C standard library which is collection of header files and library routines used by the C programming language.
See references for C as the following.
  • "info libc" (C library function reference)
  • gcc(1) and "info gcc"
  • each_C_library_function_name(3)
  • Kernighan & Ritchie, "The C Programming Language", 2nd edition (Prentice Hall)

12.3.1. Simple C program (gcc)

A simple example "example.c" can compiled with a library "libm" into an executable "run_example" by the following.
$ cat > example.c << EOF
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(int argc, char **argv, char **envp){
        double x;
        char y[11];
        x=sqrt(argc+7.5);
        strncpy(y, argv[0], 10); /* prevent buffer overflow */
        y[10] = '\0'; /* fill to make sure string ends with '\0' */
        printf("%5i, %5.3f, %10s, %10s\n", argc, x, y, argv[1]);
        return 0;
}
EOF
$ gcc -Wall -g -o run_example example.c -lm
$ ./run_example
        1, 2.915, ./run_exam,     (null)
$ ./run_example 1234567890qwerty
        2, 3.082, ./run_exam, 1234567890qwerty
Here, "-lm" is needed to link library "/usr/lib/libm.so" from the libc6 package for sqrt(3). The actual library is in "/lib/" with filename "libm.so.6", which is a symlink to "libm-2.7.so".
Look at the last parameter in the output text. There are more than 10 characters even though "%10s" is specified.
The use of pointer memory operation functions without boundary checks, such as sprintf(3) and strcpy(3), is deprecated to prevent buffer overflow exploits that leverage the above overrun effects. Instead, use snprintf(3) and strncpy(3).

No comments: