Created
May 28, 2018 06:41
-
-
Save brijeshb42/e241b1dc89d1801270f2adb08b2109ea to your computer and use it in GitHub Desktop.
Test Makefile
This file contains hidden or 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
CC=gcc | |
OPTIMIZATION?=-O2 | |
NODEPS:=clean | |
DEPENDENCY_TARGETS=libll libwebsockets | |
STD=-std=c99 -pedantic | |
WARN=-Wall -W -Wno-missing-field-initializers | |
OPT=$(OPTIMIZATION) | |
PREFIX?=.. | |
INSTALL_BIN=$(PREFIX)/bin | |
INSTALL=install | |
FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) | |
FINAL_LDFLAGS=$(LDFLAGS) $(DEBUG) | |
FINAL_LIBS=-lm -ldl | |
DEBUG=-g -ggdb | |
FINAL_DEPS+= -I$(PREFIX)/deps/libll -I$(PREFIX)/deps/libwebsockets/build/include | |
BIN_NAME=hello-main | |
BIN_OBJ=main.o hello.o | |
default: all | |
.make-prerequisites: | |
(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS)) | |
Makefile.dep: | |
$(CC) -MM *.c > Makefile.dep 2> /dev/null || true | |
.PHONY: Makefile.dep | |
.PHONY: all | |
.PHONY: .make-prerequisites | |
%.o: %.c .make-prerequisites | |
$(CC) $(FINAL_DEPS) -c $< | |
clean: | |
rm -rf Makefile.dep *.o $(BIN_NAME) $(INSTALL_BIN) Makefile.dep | |
distclean: clean | |
(cd ../deps && $(MAKE) clean) | |
$(BIN_NAME): $(BIN_OBJ) | |
@echo $(FINAL_LIBS) | |
$(CC) $(FINAL_CFLAGS) $(FINAL_DEPS) -o $@ $^ ../deps/libll/libll.a ../deps/libwebsockets/build/lib/libwebsockets.a $(FINAL_LIBS) | |
install: all | |
@mkdir -p $(INSTALL_BIN) | |
cp $(BIN_NAME) $(INSTALL_BIN) | |
rm $(BIN_NAME) | |
@echo "Installed the binary to $(INSTALL_BIN)/$(BIN_NAME)" | |
all: $(BIN_NAME) | |
@echo "Build Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment