// sum3str.c: sum 3 hardcoded strings #include <stdio.h> #include <stdlib.h> int main() { char *r = "1"; char *s = "23"; char *t = "456"; int i, j, k; if ((sscanf(r, "%d", &i) == 1) && (sscanf(s, "%d", &j) == 1) && (sscanf(t, "%d", &k) == 1)) { printf("%d\n", i+j+k); } return EXIT_SUCCESS; } |
// sum3arg.c: sum 3 arguments from the command line #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int i, j, k; if ((argc == 4) && (sscanf(argv[1], "%d", &i) == 1) && (sscanf(argv[2], "%d", &j) == 1) && (sscanf(argv[3], "%d", &k) == 1)) { printf("%d\n", i+j+k); } return EXIT_SUCCESS; } |
target: list of dependent files command |
tab
The command gcc -Wall -Werror -o myprog myprog.c will be executed.
No action is taken. The following message will be generated.
make: `myprog' is up to date. |
CC=gcc CFLAGS=-Wall -Werror -O prog1: prog1.c prog1.h $(CC) $(CFLAGS) -o prog1 prog1.c prog2: prog2.c prog2.h $(CC) $(CFLAGS) -o prog2 prog2.c all: prog1 prog2 clean: rm -f prog1.o prog2.o prog1 prog2 core |
The user can 'force' a rule for a target to be executed by 'touching' one of its dependent files.
The commands for both targets prog1 and prog2 will be executed.
CC=gcc CFLAGS=-Wall -Werror -O prog1: prog1.c prog1.h $(CC) $(CFLAGS) -o $@ $< prog2: prog2.c prog2.h $(CC) $(CFLAGS) -o $@ $< all: prog1 prog2 clean: rm -f prog1.o prog2.o prog1 prog2 core |