Created
November 26, 2015 20:27
-
-
Save roma-guru/d190429242dfafa65b58 to your computer and use it in GitHub Desktop.
Makefile examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SRC=hello.c main.c | |
OBJ=$(SRC:.c=.o) # replaces the .c from SRC with .o | |
EXE=hello | |
CC=gcc | |
CFLAGS=-Wall -O3 | |
LDFLAGS= | |
RM=rm | |
%.o: %.c # combined w/ next line will compile recently changed .c files | |
$(CC) $(CFLAGS) -o $@ -c $< | |
.PHONY : all # .PHONY ignores files named all | |
all: $(EXE) # all is dependent on $(EXE) to be complete | |
$(EXE): $(OBJ) # $(EXE) is dependent on all of the files in $(OBJ) to exist | |
$(CC) $(OBJ) $(LDFLAGS) -o $@ | |
.PHONY : clean # .PHONY ignores files named clean | |
clean: | |
-$(RM) $(OBJ) core # '-' causes errors not to exit the process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SRC=hello.c main.c | |
OBJ=$(SRC:.c=.o) # replaces the .c from SRC with .o | |
EXE=hello.exe | |
CC=gcc | |
CFLAGS=-Wall -O3 | |
LDFLAGS=-mwindows | |
RM=rm | |
%.o: %.c # combined w/ next line will compile recently changed .c files | |
$(CC) $(CFLAGS) -o $@ -c $< | |
.PHONY : all # .PHONY ignores files named all | |
all: $(EXE) # all is dependent on $(EXE) to be complete | |
$(EXE): $(OBJ) # $(EXE) is dependent on all of the files in $(OBJ) to exist | |
$(CC) $(OBJ) $(LDFLAGS) -o $@ | |
.PHONY : clean # .PHONY ignores files named clean | |
clean: | |
-$(RM) $(OBJ) core # '-' causes errors not to exit the process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment