You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.3 KiB
122 lines
3.3 KiB
2 years ago
|
# Generic C and C++ Makefile project template
|
||
|
# Contains targets for `release', `debug', and `clean'.
|
||
|
PROJECT=readpass
|
||
|
AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
|
||
|
DESCRIPTION=Securely reads a password, asymetrically encrypts it, and then outputs it for another process that posesses the private key to decrypt and use.
|
||
|
VERSION=0.0.0
|
||
|
|
||
|
SRC = src
|
||
|
|
||
|
SRC_C = $(shell find $(SRC)/ -type f -name \*.c)
|
||
|
SRC_CXX = $(shell find -O2 $(SRC)/ -type f -name \*.cpp -or -name \*.cxx)
|
||
|
|
||
|
INCLUDE=include
|
||
|
|
||
|
# Link to these libraries dynamicalls
|
||
|
SHARED_LIBS=
|
||
|
# Link to these libraries statically
|
||
|
STATIC_LIBS=
|
||
|
|
||
|
override __COMMA=,
|
||
|
override __VERSION_SPLIT:= $(subst ., ,$(VERSION))
|
||
|
override __VERSION_REVISION:=$(word 3,$(__VERSION_SPLIT)) 0
|
||
|
override __VERSION_SPLIT:= MAJOR:$(word 1,$(__VERSION_SPLIT)) MINOR:$(word 2,$(__VERSION_SPLIT)) BUGFIX:$(word 1,$(subst r, ,$(__VERSION_REVISION))) REVISION:$(word 2,$(subst r, ,$(__VERSION_REVISION))) REVISION_STRING:$(word 3,$(__VERSION_SPLIT))
|
||
|
|
||
|
COMMON_FLAGS?= -W -Wall
|
||
|
COMMON_FLAGS+= -pipe -Wstrict-aliasing -fno-strict-aliasing $(addprefix -I,$(INCLUDE))
|
||
|
COMMON_FLAGS+= $(addprefix -D_VERSION_,$(subst :,=,$(__VERSION_SPLIT))) '-D_VERSION="$(VERSION)"'
|
||
|
|
||
|
# Target arch. Set to blank for generic
|
||
|
ARCH?=native
|
||
|
# Enable OpenMP and loop parallelisation? (dyn-links to openmp)
|
||
|
PARALLEL?=yes
|
||
|
|
||
|
OPT_FLAGS?= -fgraphite \
|
||
|
-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \
|
||
|
-fno-stack-check
|
||
|
|
||
|
ifneq ($(ARCH),)
|
||
|
OPT_FLAGS+= $(addprefix -march=,$(ARCH))
|
||
|
endif
|
||
|
|
||
|
ifeq ($(PARALLEL),yes)
|
||
|
OPT_FLAGS+= -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4
|
||
|
endif
|
||
|
|
||
|
CXX_OPT_FLAGS?= $(OPT_FLAGS) -felide-constructors
|
||
|
|
||
|
CSTD?=gnu2x
|
||
|
CXXSTD?=gnu++23
|
||
|
|
||
|
CFLAGS += $(COMMON_FLAGS) --std=$(CSTD)
|
||
|
CXXFLAGS += $(COMMON_FLAGS) --std=$(CXXSTD)
|
||
|
LDFLAGS += $(addsuffix .a,$(addprefix -l:lib,$(STATIC_LIBS))) $(addprefix -l,$(SHARED_LIBS))
|
||
|
|
||
|
|
||
|
STRIP=strip
|
||
|
|
||
|
RELEASE_COMMON_FLAGS+= -fno-bounds-check
|
||
|
DEBUG_COMMON_FLAGS+= -ggdb -gz -fanalyzer -ftrapv -fbounds-check
|
||
|
|
||
|
ifneq ($(TARGET_SPEC_FLAGS),no)
|
||
|
RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS)
|
||
|
RELEASE_CXXFLAGS?= -O3 -flto $(CXX_OPT_FLAGS)
|
||
|
RELEASE_LDFLAGS?= -Wl,-O3 -Wl,-flto -fuse-linker-plugin
|
||
|
|
||
|
DEBUG_CFLAGS?= -Og
|
||
|
DEBUG_CXXFLAGS?= -Og
|
||
|
|
||
|
DEBUG_LDFLAGS?=
|
||
|
endif
|
||
|
|
||
|
DEBUG_CFLAGS+=-DDEBUG $(DEBUG_COMMON_FLAGS)
|
||
|
DEBUG_CXXFLAGS+=-DDEBUG $(DEBUG_COMMON_FLAGS) -fasynchronous-unwind-tables
|
||
|
|
||
|
RELEASE_CFLAGS+=-DRELEASE $(RELEASE_COMMON_FLAGS)
|
||
|
RELEASE_CXXFLAGS+=-DRELEASE $(RELEASE_COMMON_FLAGS)
|
||
|
|
||
|
# Objects
|
||
|
|
||
|
OBJ_C = $(addprefix obj/c/,$(SRC_C:.c=.o))
|
||
|
OBJ_CXX = $(addprefix obj/cxx/,$(SRC_CXX:.cpp=.o))
|
||
|
OBJ = $(OBJ_C) $(OBJ_CXX)
|
||
|
|
||
|
# Phonies
|
||
|
|
||
|
.PHONY: release
|
||
|
release: | dirs $(PROJECT)-release
|
||
|
|
||
|
.PHONY: debug
|
||
|
debug: | dirs $(PROJECT)-debug
|
||
|
|
||
|
# Targets
|
||
|
|
||
|
dirs:
|
||
|
@mkdir -p $(addprefix obj/c{$(__COMMA)xx}/,$(shell find $(SRC)/ -type d))
|
||
|
|
||
|
obj/c/%.o: %.c
|
||
|
$(CC) -c $< $(CFLAGS) -o $@
|
||
|
|
||
|
obj/cxx/%.o: %.cpp
|
||
|
$(CXX) -c $< $(CXXFLAGS) -o $@
|
||
|
|
||
|
$(PROJECT)-release: CFLAGS+= $(RELEASE_CFLAGS)
|
||
|
$(PROJECT)-release: CXXFLAGS += $(RELEASE_CXXFLAGS)
|
||
|
$(PROJECT)-release: LDFLAGS += $(RELEASE_LDFLAGS)
|
||
|
$(PROJECT)-release: $(OBJ)
|
||
|
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
||
|
$(STRIP) $@
|
||
|
|
||
|
$(PROJECT)-debug: CFLAGS+= $(DEBUG_CFLAGS)
|
||
|
$(PROJECT)-debug: CXXFLAGS += $(DEBUG_CXXFLAGS)
|
||
|
$(PROJECT)-debug: LDFLAGS += $(DEBUG_LDFLAGS)
|
||
|
$(PROJECT)-debug: $(OBJ)
|
||
|
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
||
|
|
||
|
clean-rebuild:
|
||
|
rm -rf obj
|
||
|
|
||
|
clean: clean-rebuild
|
||
|
rm -f $(PROJECT)-{release,debug,pgo}
|
||
|
|