Skip to content

Instantly share code, notes, and snippets.

@tpu01yzx
Created November 19, 2021 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpu01yzx/c99c565c0602390f0fa75a753ed56d64 to your computer and use it in GitHub Desktop.
Save tpu01yzx/c99c565c0602390f0fa75a753ed56d64 to your computer and use it in GitHub Desktop.
Makefile template
#####################################################################
## file : test makefile for build current dir .c ##
## author : jernymy ##
## date-time : 05/06/2010 ##
#####################################################################
CC = gcc
CPP = g++
RM = rm -rf
## debug flag
DBG_ENABLE = 1
## source file path
SRC_PATH := .
## target exec file name
TARGET := test
## get all source files
SRCS += $(wildcard $(SRC_PATH)/*.c)
## all .o based on all .c
OBJS := $(SRCS:.c=.o)
## need libs, add at here
LIBS :=
## used headers file path
INCLUDE_PATH := .
## used include librarys file path
LIBRARY_PATH := /lib
## debug for debug info, when use gdb to debug
ifeq (1, ${DBG_ENABLE})
CFLAGS += -D_DEBUG -O0 -g -DDEBUG=1
endif
## get all include path
CFLAGS += $(foreach dir, $(INCLUDE_PATH), -I$(dir))
## get all library path
LDFLAGS += $(foreach lib, $(LIBRARY_PATH), -L$(lib))
## get all librarys
LDFLAGS += $(foreach lib, $(LIBS), -l$(lib))
all: clean build
build:
$(CC) -c $(CFLAGS) $(SRCS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LDFLAGS)
$(RM) $(OBJS)
clean:
$(RM) $(OBJS) $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment