Added makefile with install target

Fortune for tracemac's current commit: Great blessing − 大吉
master
Avril 3 years ago
parent e59c3bb618
commit 5e7df7a9ef
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -0,0 +1,163 @@
# libtracem - trace and macros
PROJECT=tracem
AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
VERSION_MAJOR=0
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
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 \
-fno-stack-check
CXX_OPT_FLAGS?= $(OPT_FLAGS)
# Static analyzer currently generates false positives for C++, enable it only for C
CFLAGS += $(COMMON_FLAGS) --std=gnu17 -fanalyzer
CXXFLAGS += $(COMMON_FLAGS) --std=gnu++20 -felide-constructors
LDFLAGS +=
STRIP=strip
RELEASE_COMMON_FLAGS+= -Werror
DEBUG_COMMON_FLAGS+= -fanalyzer
ifneq ($(TARGET_SPEC_FLAGS),no)
RELEASE_CFLAGS?= -O3 -flto $(OPT_FLAGS)
RELEASE_CXXFLAGS?= -O3 -flto $(CXX_OPT_FLAGS)
RELEASE_LDFLAGS?= -Wl,-O3 -Wl,-flto
DEBUG_CFLAGS?= -O0 -g
DEBUG_CXXFLAGS?=-O0 -g
DEBUG_LDFLAGS?=
endif
DEBUG_CFLAGS+=-DDEBUG $(DEBUG_COMMON_FLAGS)
DEBUG_CXXFLAGS+=-DDEBUG $(DEBUG_COMMON_FLAGS)
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
$(MAKE) lib$(PROJECT).a
@$(MAKE) clean-rebuild >> /dev/null
@$(MAKE) dirs >> /dev/null
#$(MAKE) lib$(PROJECT).so
.PHONY: 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
dirs:
@mkdir -p obj/c{,xx}/src
obj/c/%.o: %.c
$(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS)
obj/cxx/%.o: %.cpp
$(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS)
lib$(PROJECT)-release.a: CFLAGS+= $(RELEASE_CFLAGS)
lib$(PROJECT)-release.a: CXXFLAGS += $(RELEASE_CXXFLAGS)
lib$(PROJECT)-release.a: LDFLAGS += $(RELEASE_LDFLAGS)
lib$(PROJECT)-release.a: $(OBJ)
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) $@
#lib$(PROJECT)-debug.so: CFLAGS+= $(DEBUG_CFLAGS) -fPIC
#lib$(PROJECT)-debug.so: CXXFLAGS += $(DEBUG_CXXFLAGS) -fPIC
#lib$(PROJECT)-debug.so: LDFLAGS += $(DEBUG_LDFLAGS)
#lib$(PROJECT)-debug.so: $(OBJ)
# $(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:
rm -rf obj
clean: clean-rebuild
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
$(CC) $(CFLAGS) src/test/*.c -o $@ -l:$< -Wl,-flto -Wl,-O3 $(LDFLAGS)
-valgrind ./$@

@ -5,6 +5,11 @@
#ifndef _MACROS_H #ifndef _MACROS_H
#define _MACROS_H #define _MACROS_H
#ifdef __cplusplus
#define _Static_assert static_assert
extern "C" {
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -134,7 +139,7 @@ _mixin void _drain_val(void* x, ...) { IGNORE(x); } // This compiles to no-op on
// Allocation macros // Allocation macros
#define box(t) aligned_alloc(_Alignof(t), sizeof(t)) #define box(t) ((t*)aligned_alloc(_Alignof(t), sizeof(t)))
#define box_value(v) ({ let _box = box(var(v)); *_box = (v); _box; }) #define box_value(v) ({ let _box = box(var(v)); *_box = (v); _box; })
#define unbox_value(v) ({ let _v = (v); let _res = *_v; free(_v); _res; }) #define unbox_value(v) ({ let _v = (v); let _res = *_v; free(_v); _res; })
#define stackalloc(t) __builtin_alloca_with_align(sizeof(t), _Alignof(t)) #define stackalloc(t) __builtin_alloca_with_align(sizeof(t), _Alignof(t))
@ -282,4 +287,9 @@ _Static_assert( (VERSION_COMP(VERSION(1,2,3,4), VER_COMP_MIN) >> VER_COMP_MIN) =
#define PTR_ASSIGN(ptr, val) ( (ptr) ? (*(ptr) = (val), (ptr)) : (ptr) ) #define PTR_ASSIGN(ptr, val) ( (ptr) ? (*(ptr) = (val), (ptr)) : (ptr) )
#define PTR_ASSIGNv(ptr, val) ({ let _ptr = (ptr); let _val = (val); PTR_ASSIGN(_ptr, _val); }) #define PTR_ASSIGNv(ptr, val) ({ let _ptr = (ptr); let _val = (val); PTR_ASSIGN(_ptr, _val); })
#ifdef __cplusplus
#undef _Static_assert
}
#endif
#endif /* _MACROS_H */ #endif /* _MACROS_H */

@ -5,10 +5,11 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <trace.h> #include <trace.h>
#include <macros.h> #include <tracem/macros.h>
#include <ints.h> #include <tracem/ints.h>
static _Atomic enum trace_level _t_level = _TRACE_LEVEL_DEFAULT; static _Atomic enum trace_level _t_level = _TRACE_LEVEL_DEFAULT;

Loading…
Cancel
Save