Skip to content

Instantly share code, notes, and snippets.

@ahuglajbclajep
Last active April 6, 2018 00:51
Show Gist options
  • Save ahuglajbclajep/953c36c9ea1afb783645217a56965f95 to your computer and use it in GitHub Desktop.
Save ahuglajbclajep/953c36c9ea1afb783645217a56965f95 to your computer and use it in GitHub Desktop.
Makefileのテンプレート
CC = gcc
CFLAGS = -std=c99 -O2
LDFLAGS = -lm
LIBS =
INCLUDE = -I$(SRC_DIR)
APP_NAME = App_Name
SRC_DIR = src
OBJ_DIR = build
SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
$(OBJ_DIR)/$(APP_NAME): $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(INCLUDE) -MMD -MP -o $@ -c $<
all: clean $(OBJ_DIR)/$(APP_NAME)
run:
@make
@cd $(OBJ_DIR) && ./$(APP_NAME)
clean:
$(RM) $(OBJ) $(OBJ:.o=.d) $(OBJ_DIR)/$(APP_NAME)
-include $(OBJ:.o=.d)
.PHONY: all run clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment