Skip to content

Instantly share code, notes, and snippets.

@x2c3z4
Forked from basharam/Makefile
Created September 17, 2020 07:02
Show Gist options
  • Save x2c3z4/377b11701e913de6406bda610817af1a to your computer and use it in GitHub Desktop.
Save x2c3z4/377b11701e913de6406bda610817af1a to your computer and use it in GitHub Desktop.
Makefile template for Static library.
# Makefile template for Static library.
# 1. Compile every *.cpp in the folder
# 2. All obj files under obj folder
# 3. static library .a at lib folder
# 4. run 'make dirmake' before calling 'make'
CC = g++
OUT_FILE_NAME = libNAME.a
CFLAGS= -fPIC -O0 -g -Wall -c -fpermissive
INC = -I../Import
OBJ_DIR=./obj
OUT_DIR=./lib
# Enumerating of every *.cpp as *.o and using that as dependency.
# filter list of .c files in a directory.
# FILES =dump_l.c \
# kter.c \
#
# $(OUT_FILE_NAME): $(patsubst %.c,$(OBJ_DIR)/%.o,$(wildcard $(FILES)))
# Enumerating of every *.cpp as *.o and using that as dependency
$(OUT_FILE_NAME): $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(wildcard *.cpp))
ar -r -o $(OUT_DIR)/$@ $^
#Compiling every *.cpp to *.o
$(OBJ_DIR)/%.o: %.cpp dirmake
$(CC) -c $(INC) $(CFLAGS) -o $@ $<
dirmake:
@mkdir -p $(OUT_DIR)
@mkdir -p $(OBJ_DIR)
clean:
rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/$(OUT_FILE_NAME) Makefile.bak
rebuild: clean build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment