prog: prog.o gcc prog.o -o prog prog.o: prog.c gcc -Wall -c prog.c |
make |
make
to read the file name as the
makefile, type:
make -f |
make target1 target2 target3 |
|
CSOURCES = prog.c btree.c OBJECTS = $(CSOURCES:.c=.o) prog: $(OBJECTS) gcc $? -o $@ btree.o: btree.c btree.h gcc -c $< -o $@ prog.o: prog.c btree.h gcc -c $< -o $@ clean: rm -rf btree.o prog.o prog |
bison -d x.y
' will make both x.tab.c
and x.tab.h
%.tab.c %.tab.h: %.y bison -d $< |
%.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ |
x: y.o z.o |
prog: prog.o btree.o btree.o: btree.h prog.o: btree.h clean: rm -rf btree.o prog.o prog |
CSOURCES = btree.c prog.c OBJECTS = $(CSOURCES:.c=.o) TARGET = btree CPPFLAGS = CFLAGS = -Wall -pedantic $(TARGET): $(OBJECTS) btree.o: btree.h prog.o: btree.h clean: rm -rf $(OBJECTS) $(TARGET) |
gcc -Wall -pedantic -c -o btree.o btree.c gcc -Wall -pedantic -c -o prog.o prog.c gcc btree.o prog.o -o btree |
CSOURCES = photo.c OBJECTS = $(CSOURCES:.c=.o) TARGET = $(CSOURCES:.c=) CPPFLAGS = CFLAGS = -Wall -pedantic LDFLAGS = -lglut $(TARGET): $(OBJECTS) clean: rm -rf $(OBJECTS) $(TARGET) |
CSOURCES = photo.c OBJECTS = $(CSOURCES:.c=.o) TARGET = $(CSOURCES:.c=) CPPFLAGS = CFLAGS = -Wall -pedantic LDFLAGS = -lglut32 -lopengl32 $(TARGET): $(OBJECTS) gcc $(OBJECTS) $(LDFLAGS) -o $@ clean: rm -rf $(OBJECTS) $(TARGET) |
CSOURCES = cp_photo.c OBJECTS = $(CSOURCES:.c=.obj) TARGET = $(CSOURCES:.c=.exe) CPPFLAGS = CFLAGS = -nologo -I. CPPFLAGS = LDFLAGS = -nologo -subsystem:console glut32.lib opengl32.lib $(TARGET): $(OBJECTS) link $(OBJECTS) $(LDFLAGS) -Out:$@ %.obj : %.c cl $(CFLAGS) -c $< clean: rm -rf $(OBJECTS) $(TARGET) |
ifeq ($(OS), Windows) CSOURCES = cp_photo.c OBJECTS = $(CSOURCES:.c=.obj) TARGET = $(CSOURCES:.c=.exe) CFLAGS = -nologo -I. LDFLAGS = -nologo -subsystem:console glut32.lib opengl32.lib else CSOURCES = photo.c OBJECTS = $(CSOURCES:.c=.o) TARGET = $(CSOURCES:.c=) CFLAGS = -Wall -pedantic ifeq ($(OSTYPE), linux) LDFLAGS = -lglut else LDFLAGS = -lglut32 -lopengl32 endif endif CPPFLAGS = $(TARGET): $(OBJECTS) ifeq ($(OS), Windows) link $(OBJECTS) $(LDFLAGS) -Out:$@ %.obj : %.c cl $(CFLAGS) -c $< else gcc $(OBJECTS) $(LDFLAGS) -o $@ endif clean: rm -rf $(OBJECTS) $(TARGET) |