|
|
@ -1,29 +1,39 @@
|
|
|
|
# Generic C and C++ Makefile project template
|
|
|
|
# pipec - Piping IPC
|
|
|
|
# Contains targets for `release', `debug', and `clean'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROJECT=rng
|
|
|
|
PROJECT=rngxx
|
|
|
|
AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
|
|
|
|
AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
|
|
|
|
|
|
|
|
|
|
|
|
SRC_C = $(wildcard src/*.c) $(wildcard src/rng/*.c)
|
|
|
|
VERSION_MAJOR=0
|
|
|
|
SRC_CXX = $(wildcard src/*.cpp) $(wildcard src/rng/*.cpp)
|
|
|
|
VERSION_MINOR=0
|
|
|
|
|
|
|
|
VERSION=$(VERSION_MAJOR).$(VERSION_MINOR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ifeq ($(PREFIX),)
|
|
|
|
|
|
|
|
PREFIX := /usr/local
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SRC_C = $(wildcard src/*.c)
|
|
|
|
|
|
|
|
SRC_CXX = $(wildcard src/*.cpp)
|
|
|
|
|
|
|
|
|
|
|
|
INCLUDE=include
|
|
|
|
INCLUDE=include
|
|
|
|
COMMON_FLAGS+= -W -Wall -pedantic -fno-strict-aliasing $(addprefix -I,$(INCLUDE))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OPT_FLAGS?= -march=native -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \
|
|
|
|
COMMON_FLAGS= -W -Wall -Wextra -Wstrict-aliasing -fno-strict-aliasing "-D_VERSION=$(VERSION)" $(addprefix -I,$(INCLUDE))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_CPU?=native
|
|
|
|
|
|
|
|
OPT_FLAGS?= $(addprefix -march=,$(TARGET_CPU)) -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \
|
|
|
|
-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \
|
|
|
|
-floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \
|
|
|
|
-fno-stack-check
|
|
|
|
-fno-stack-check
|
|
|
|
|
|
|
|
|
|
|
|
CXX_OPT_FLAGS?= $(OPT_FLAGS) -felide-constructors
|
|
|
|
CXX_OPT_FLAGS?= $(OPT_FLAGS)
|
|
|
|
|
|
|
|
|
|
|
|
CFLAGS += $(COMMON_FLAGS) --std=gnu17
|
|
|
|
# Static analyzer currently generates false positives for C++, enable it only for C
|
|
|
|
CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20
|
|
|
|
CFLAGS += $(COMMON_FLAGS) --std=gnu17 -fanalyzer
|
|
|
|
|
|
|
|
CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 -felide-constructors
|
|
|
|
LDFLAGS +=
|
|
|
|
LDFLAGS +=
|
|
|
|
|
|
|
|
|
|
|
|
STRIP=strip
|
|
|
|
STRIP=strip
|
|
|
|
|
|
|
|
|
|
|
|
RELEASE_COMMON_FLAGS+= # -Werror
|
|
|
|
RELEASE_COMMON_FLAGS+= -Werror
|
|
|
|
DEBUG_COMMON_FLAGS+=
|
|
|
|
DEBUG_COMMON_FLAGS+= -fanalyzer
|
|
|
|
|
|
|
|
|
|
|
|
ifneq ($(TARGET_SPEC_FLAGS),no)
|
|
|
|
ifneq ($(TARGET_SPEC_FLAGS),no)
|
|
|
|
RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS)
|
|
|
|
RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS)
|
|
|
@ -50,10 +60,33 @@ OBJ = $(OBJ_C) $(OBJ_CXX)
|
|
|
|
# Phonies
|
|
|
|
# Phonies
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: release
|
|
|
|
.PHONY: release
|
|
|
|
release: | dirs $(PROJECT)-release
|
|
|
|
release: | dirs
|
|
|
|
|
|
|
|
$(MAKE) lib$(PROJECT).a
|
|
|
|
|
|
|
|
@$(MAKE) clean-rebuild >> /dev/null
|
|
|
|
|
|
|
|
@$(MAKE) dirs >> /dev/null
|
|
|
|
|
|
|
|
$(MAKE) lib$(PROJECT).so
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: debug
|
|
|
|
.PHONY: debug
|
|
|
|
debug: | dirs $(PROJECT)-debug
|
|
|
|
debug: | dirs
|
|
|
|
|
|
|
|
$(MAKE) lib$(PROJECT)-debug.a
|
|
|
|
|
|
|
|
@$(MAKE) clean-rebuild >> /dev/null
|
|
|
|
|
|
|
|
@$(MAKE) dirs >> /dev/null
|
|
|
|
|
|
|
|
$(MAKE) lib$(PROJECT)-debug.so
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Rebuild both release and debug targets from scratch
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
|
|
|
|
all: | clean
|
|
|
|
|
|
|
|
@$(MAKE) release
|
|
|
|
|
|
|
|
@$(MAKE) clean-rebuild
|
|
|
|
|
|
|
|
@$(MAKE) debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: install
|
|
|
|
|
|
|
|
.PHONY: uninstall
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
|
|
|
|
test:
|
|
|
|
|
|
|
|
@rm -f $(PROJECT)-test
|
|
|
|
|
|
|
|
@$(MAKE) $(PROJECT)-test
|
|
|
|
|
|
|
|
|
|
|
|
# Targets
|
|
|
|
# Targets
|
|
|
|
|
|
|
|
|
|
|
@ -66,22 +99,65 @@ obj/c/%.o: %.c
|
|
|
|
obj/cxx/%.o: %.cpp
|
|
|
|
obj/cxx/%.o: %.cpp
|
|
|
|
$(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
$(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
|
|
|
|
|
|
|
|
$(PROJECT)-release: CFLAGS+= $(RELEASE_CFLAGS)
|
|
|
|
lib$(PROJECT)-release.a: CFLAGS+= $(RELEASE_CFLAGS)
|
|
|
|
$(PROJECT)-release: CXXFLAGS += $(RELEASE_CXXFLAGS)
|
|
|
|
lib$(PROJECT)-release.a: CXXFLAGS += $(RELEASE_CXXFLAGS)
|
|
|
|
$(PROJECT)-release: LDFLAGS += $(RELEASE_LDFLAGS)
|
|
|
|
lib$(PROJECT)-release.a: LDFLAGS += $(RELEASE_LDFLAGS)
|
|
|
|
$(PROJECT)-release: $(OBJ)
|
|
|
|
lib$(PROJECT)-release.a: $(OBJ)
|
|
|
|
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
ar rcs $@ $^
|
|
|
|
|
|
|
|
ranlib $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib$(PROJECT)-debug.a: CFLAGS+= $(DEBUG_CFLAGS)
|
|
|
|
|
|
|
|
lib$(PROJECT)-debug.a: CXXFLAGS += $(DEBUG_CXXFLAGS)
|
|
|
|
|
|
|
|
lib$(PROJECT)-debug.a: LDFLAGS += $(DEBUG_LDFLAGS)
|
|
|
|
|
|
|
|
lib$(PROJECT)-debug.a: $(OBJ)
|
|
|
|
|
|
|
|
ar rcs $@ $^
|
|
|
|
|
|
|
|
ranlib $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib$(PROJECT)-release.so: CFLAGS+= $(RELEASE_CFLAGS) -fPIC
|
|
|
|
|
|
|
|
lib$(PROJECT)-release.so: CXXFLAGS += $(RELEASE_CXXFLAGS) -fPIC
|
|
|
|
|
|
|
|
lib$(PROJECT)-release.so: LDFLAGS += $(RELEASE_LDFLAGS)
|
|
|
|
|
|
|
|
lib$(PROJECT)-release.so: $(OBJ)
|
|
|
|
|
|
|
|
$(CXX) -shared $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
$(STRIP) $@
|
|
|
|
$(STRIP) $@
|
|
|
|
|
|
|
|
|
|
|
|
$(PROJECT)-debug: CFLAGS+= $(DEBUG_CFLAGS)
|
|
|
|
lib$(PROJECT)-debug.so: CFLAGS+= $(DEBUG_CFLAGS) -fPIC
|
|
|
|
$(PROJECT)-debug: CXXFLAGS += $(DEBUG_CXXFLAGS)
|
|
|
|
lib$(PROJECT)-debug.so: CXXFLAGS += $(DEBUG_CXXFLAGS) -fPIC
|
|
|
|
$(PROJECT)-debug: LDFLAGS += $(DEBUG_LDFLAGS)
|
|
|
|
lib$(PROJECT)-debug.so: LDFLAGS += $(DEBUG_LDFLAGS)
|
|
|
|
$(PROJECT)-debug: $(OBJ)
|
|
|
|
lib$(PROJECT)-debug.so: $(OBJ)
|
|
|
|
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
$(CXX) -shared $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib$(PROJECT).a: lib$(PROJECT)-release.a
|
|
|
|
|
|
|
|
ln -f $< $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib$(PROJECT).so: LDFLAGS+= -Wl,-soname,lib$(PROJECT).so.$(VERSION_MAJOR)
|
|
|
|
|
|
|
|
lib$(PROJECT).so: lib$(PROJECT)-release.so
|
|
|
|
|
|
|
|
ln -f $< $@.$(VERSION)
|
|
|
|
|
|
|
|
ln -sf $@.$(VERSION) $@.$(VERSION_MAJOR)
|
|
|
|
|
|
|
|
ln -sf $@.$(VERSION_MAJOR) $@
|
|
|
|
|
|
|
|
|
|
|
|
clean-rebuild:
|
|
|
|
clean-rebuild:
|
|
|
|
rm -rf obj
|
|
|
|
rm -rf obj
|
|
|
|
|
|
|
|
|
|
|
|
clean: clean-rebuild
|
|
|
|
clean: clean-rebuild
|
|
|
|
rm -f $(PROJECT)-{release,debug,pgo}
|
|
|
|
rm -f lib$(PROJECT){,-{release,debug,pgo}}.{a,so{,.*}}
|
|
|
|
|
|
|
|
rm -f $(PROJECT)-test
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
install:
|
|
|
|
|
|
|
|
install -d $(DESTDIR)$(PREFIX)/lib/
|
|
|
|
|
|
|
|
install -m 644 lib$(PROJECT).a $(DESTDIR)$(PREFIX)/lib/
|
|
|
|
|
|
|
|
install -s -m 755 lib$(PROJECT).so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/
|
|
|
|
|
|
|
|
ln -sf lib$(PROJECT).so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/lib$(PROJECT).so.$(VERSION_MAJOR)
|
|
|
|
|
|
|
|
ln -sf lib$(PROJECT).so.$(VERSION_MAJOR) $(DESTDIR)$(PREFIX)/lib/lib$(PROJECT).so
|
|
|
|
|
|
|
|
install -d $(DESTDIR)$(PREFIX)/include/
|
|
|
|
|
|
|
|
install -m 644 $(wildcard $(INCLUDE)/*.*) $(DESTDIR)$(PREFIX)/include/
|
|
|
|
|
|
|
|
install -d $(DESTDIR)$(PREFIX)/include/$(PROJECT)/
|
|
|
|
|
|
|
|
install -m 644 $(wildcard $(INCLUDE)/$(PROJECT)/*.*) $(DESTDIR)$(PREFIX)/include/$(PROJECT)/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uninstall:
|
|
|
|
|
|
|
|
-rm $(DESTDIR)$(PREFIX)/lib/lib$(PROJECT).{a,so{,.*}}
|
|
|
|
|
|
|
|
cd $(INCLUDE) && find . -type f | xargs -I {} rm "$(DESTDIR)$(PREFIX)/include/{}"
|
|
|
|
|
|
|
|
-rmdir $(DESTDIR)$(PREFIX)/include/$(PROJECT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(PROJECT)-test: lib$(PROJECT).so
|
|
|
|
|
|
|
|
$(CXX) $(CXXFLAGS) src/test/*.cpp -o $@ -l:$< -lfmt -Wl,-flto -Wl,-O3 $(LDFLAGS)
|
|
|
|
|
|
|
|
-valgrind ./$@
|
|
|
|