Created
December 24, 2019 00:09
-
-
Save ohmree/3b2a68034ca400ce064b646a9f1c57c9 to your computer and use it in GitHub Desktop.
Updated makefile
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
SRCS = main.c test.c | |
OBJS = $(SRCS:.c=.o) | |
EXENAME = test | |
CFLAGS = -Wall -Wpedantic -Wextra | |
all: debug | |
debug: CPPFLAGS += -DDEBUG | |
debug: CFLAGS += -Og -ggdb | |
debug: OUTDIR = out/debug | |
debug: EXE = $(OUTDIR)/$(EXENAME) | |
debug: prep | |
debug: executable | |
release: CPPFLAGS += -DNDEBUG | |
release: CFLAGS += -Os | |
release: LDFLAGS += -flto | |
release: OUTDIR = out/release | |
release: EXE = $(OUTDIR)/$(EXENAME) | |
release: prep | |
release: executable | |
# If you leave out the forward slash, the entire pattern on line 30 gets skipped. | |
OBJS := $(addprefix $(OUTDIR)/,$(OBJS)) | |
executable: $(OBJS) | |
@echo "Compiling executable $(EXENAME):" | |
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(EXE) | |
$(OUTDIR)/%.o: %.c | |
@echo "Compiling $@ from $<" | |
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< -o $@ | |
prep: | |
@mkdir -p $(OUTDIR) | |
clean: | |
@rm -f out/debug/*.o 2&>/dev/null || true | |
@rm -f out/debug/$(EXENAME) 2&>/dev/null || true | |
@rm -f out/release/*.o 2&>/dev/null || true | |
@rm -f out/release/$(EXENAME) 2&>/dev/null || true | |
remake: clean all |
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
$ make | |
Compiling /main.o from main.c | |
cc -c -DDEBUG -Wall -Wpedantic -Wextra -Og -ggdb main.c -o /main.o | |
Assembler messages: | |
Fatal error: can't create /main.o: Permission denied | |
make: *** [Makefile:32: /main.o] Error 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment