4
4

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 5 years have passed since last update.

GNU Makefileテンプレート

Last updated at Posted at 2015-10-07

はじめに

忘れがちなGNU makeのmakefileの書き方を記載します。
バージョンはGNU Make 3.81です。

テンプレート

markdownで記載するとなぜか半角スペースに変換されてしまっていますが
makefile内のインデントはタブ文字です。

makefile
CFLAGS=-I. -g -Wall -Werror
INCS=test.h
OBJS=test.o
LIBS=#-lpthread -lm
TARGET=test

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

$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

clean:
	rm -rf $(TARGET) *.o
test.h
# define STRING "Hello World!\n"
test.c
# include "test.h"
# include <stdio.h>

int main(int argc, char*argv[])
{
    printf(STRING);
    return 0;
}
4
4
0

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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?