- 论坛徽章:
- 3
|
linux-s3hu:/tmp/ddd/test1 # cat >1.c
#include "1.h"
#include <stdio.h>
int main()
{
printf("TEST=%d\n",TEST);
return 0;
}
linux-s3hu:/tmp/ddd/test1 # cat >1.h
#ifndef _1_H_
#define _1_H_
#define TEST 0
#endif
linux-s3hu:/tmp/ddd/test1 # cat >Makefile
SRC = $(wildcard *.c)
OBJ = $(SRC:%.c=%.o)
.PHONY:all clean
all:a.out
a.out (OBJ)
gcc $^ -o $@
clean:
$(RM) $(OBJ) a.out
linux-s3hu:/tmp/ddd/test1 # make
cc -c -o 1.o 1.c
gcc 1.o -o a.out
linux-s3hu:/tmp/ddd/test1 # ./a.out
TEST=0
linux-s3hu:/tmp/ddd/test1 # vi 1.h
linux-s3hu:/tmp/ddd/test1 # cat 1.h
#ifndef _1_H_
#define _1_H_
#define TEST 1/*here*/
#endif
linux-s3hu:/tmp/ddd/test1 # make
make: Nothing to be done for `all'.
linux-s3hu:/tmp/ddd/test1 # ./a.out
TEST=0
linux-s3hu:/tmp/ddd/test1 # vi Makefile
linux-s3hu:/tmp/ddd/test1 # cat Makefile
SRC = $(wildcard *.c)
OBJ = $(SRC:%.c=%.o)
#############
CFLAGS = -MMD
#############
.PHONY:all clean
all:a.out
a.out (OBJ)
gcc $^ -o $@
clean:
$(RM) $(OBJ) a.out
#############
-include $(SRC:%.c=%.d)
#############
linux-s3hu:/tmp/ddd/test1 # vi 1.h
linux-s3hu:/tmp/ddd/test1 # cat 1.h
#ifndef _1_H_
#define _1_H_
#define TEST 0
#endif
linux-s3hu:/tmp/ddd/test1 # make clean
rm -f 1.o a.out
linux-s3hu:/tmp/ddd/test1 # make
cc -MMD -c -o 1.o 1.c
gcc 1.o -o a.out
linux-s3hu:/tmp/ddd/test1 # ./a.out
TEST=0
linux-s3hu:/tmp/ddd/test1 # vi 1.h
linux-s3hu:/tmp/ddd/test1 # cat 1.h
#ifndef _1_H_
#define _1_H_
#define TEST 1/*here*/
#endif
linux-s3hu:/tmp/ddd/test1 # make
cc -MMD -c -o 1.o 1.c
gcc 1.o -o a.out
linux-s3hu:/tmp/ddd/test1 # ./a.out
TEST=1
|
|