home /
secrets /
makefile
makefile
###
### Determine OS.
###
ifeq ($(OS), Windows_NT) #NB: Windows is not supported
OSNAME = WINDOWS
else ifeq ($(shell uname),Darwin)
OSNAME = MAC
else
OSNAME = LINUX
endif
###
### Files.
###
SRC_PATH = src
SOURCES := $(wildcard $(SRC_PATH)/*.c) $(wildcard $(SRC_PATH)/*/*.c)
OBJECT_PATH = objects
OBJECTS := $(patsubst $(SRC_PATH)/%.c, $(OBJECT_PATH)/%.o, $(SOURCES))
###
### Compiler.
###
CC = gcc
###
### Compiler flags.
###
CFLAGS = -O3 -std=c99 -march=native
CFLAGS += -Wformat=2 -Wall -Wextra -Wpedantic -Wconversion -Wundef -Wshadow
ifeq ($(OSNAME), LINUX)
CFLAGS += -D_XOPEN_SOURCE=700
endif
###
### Linked library flags.
###
ifeq ($(OSNAME), LINUX)
LDLIBS = -lbsd
endif
###
### Executable.
###
secrets : $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
$(OBJECT_PATH)/%.o: $(SRC_PATH)/%.c
$(CC) $(CFLAGS) -I$(SRC_PATH) -c $< -o $@
all: secrets
###
### Cleaning build.
###
ifeq ($(OSNAME), WINDOWS)
CLEAN_COMMAND = del /s secrets.exe $(OBJECT_PATH)\*.o
else
CLEAN_COMMAND = rm secrets $(OBJECT_PATH)/*.o $(OBJECT_PATH)/*/*.o
endif
clean:
$(CLEAN_COMMAND)
.PHONY: clean