skov-example-projects/helloworld-c-make/Makefile

42 lines
700 B
Makefile
Raw Normal View History

2024-08-02 15:07:55 +01:00
EXECUTABLE = helloworld-c-make
INSTALL_PREFIX = /usr/local
CFLAGS = -std=c17 -Wall -Wextra -pedantic -pedantic-errors -O2
LFLAGS =
LD=gcc
CC=gcc
SOURCE_FILES = \
src/main.c
OBJECT_FILES = $(patsubst src/%.c, build/%.o, $(SOURCE_FILES))
HEADER_FILES = $(shell find src/ -name *.h)
all: build/$(EXECUTABLE) build/compile_flags.txt
install: build/$(EXECUTABLE)
cp build/$(EXECUTABLE) $(INSTALL_PREFIX)/bin/$(EXECUTABLE)
build/$(EXECUTABLE): $(OBJECT_FILES)
$(LD) -o $@ $(LFLAGS) $^
build/%.o: src/%.c $(HEADER_FILES) build-folder
$(CC) -c -o $@ $(CFLAGS) $<
build-folder:
mkdir -p build/
clean:
$(RM) build/
build/compile_flags.txt:
echo -xc $(CFLAGS) \
| tr ' ' '\n' \
> $@