1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

c言語用Makefileテンプレート

Last updated at Posted at 2020-10-02

背景

c言語で簡単なアプリを作るときに毎回同じようなMakefileを使っているが、その度に大体同じ内容をしらべており、面倒なのでテンプレートファイルを残す。
もっと良い書き方があればコメントください。

Makefile

CC = gcc
CFLAGS = -g3 -MMD -O0
# LDFLAGS =
TARGET = sample # need to change
SRCS = $(wildcard *.c)
OBJS = $(SRCS:%.c=%.o)
DEPS = $(SRCS:%.c=%.d)
RM = rm -f

.PHONY: all
all: $(TARGET)

$(TARGET): $(OBJS)
        $(CC) $^ -o $@ $(LDFLAGS)

%.o: %.c
        $(CC) $< -c $(CFLAGS)

.PHONY: clean
clean:
        $(RM) $(TARGET) $(OBJS) $(DEPS)

-include *.d

あとはMakefileと同じディレクトリにソースファイルを配置する。

1
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?