From 415596b7f0c8c48c45100784481374a42730e220 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Mon, 6 Jun 2022 16:45:07 +0200 Subject: [PATCH] C tools: move includes to subdir, Makefile --- c/Makefile | 87 ++++++++++++++++++++++++++++++++++++++++ c/{ => include}/bits.h | 0 c/{ => include}/debug.h | 0 c/{ => include}/list.h | 0 c/{ => include}/pool.h | 0 c/{ => include}/rwonce.h | 0 6 files changed, 87 insertions(+) create mode 100644 c/Makefile rename c/{ => include}/bits.h (100%) rename c/{ => include}/debug.h (100%) rename c/{ => include}/list.h (100%) rename c/{ => include}/pool.h (100%) rename c/{ => include}/rwonce.h (100%) diff --git a/c/Makefile b/c/Makefile new file mode 100644 index 0000000..caca146 --- /dev/null +++ b/c/Makefile @@ -0,0 +1,87 @@ +# Tools Makefile +# +# Copyright (C) 2022 Bruno Raoult ("br") +# Licensed under the GNU General Public License v3.0 or later. +# Some rights reserved. See COPYING. +# +# You should have received a copy of the GNU General Public License along with this +# program. If not, see . +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +SHELL := /bin/bash +CC := gcc + +CFLAGS += -std=gnu99 +CFLAGS += -O2 +CFLAGS += -g +CFLAGS += -Wall +CFLAGS += -Wextra +CFLAGS += -march=native +CFLAGS += -Wmissing-declarations +CFLAGS += -Wno-unused-result + +# for gprof +#CFLAGS += -pg + +# Next one may be useful for valgrind (some invalid instructions) +# CFLAGS += -mno-tbm + +CFLAGS += -DDEBUG_DEBUG # activate general debug (debug.c) +CFLAGS += -DDEBUG_POOL # memory pools management + +INCDIR := ./include +LIBDIR := ./lib +OBJDIR := ./obj + +LIBNAME := br_$(shell uname -m) +LIB := lib$(LIBNAME) +SLIB := $(LIBDIR)/$(LIB).a +DLIB := $(LIBDIR)/$(LIB).so +LIBSRC := $(wildcard *.c) +LIBOBJ := $(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(LIBSRC))) +LDFLAGS := -L$(LIBDIR) +LDLIB := -l$(LIB) + +export LD_LIBRARY_PATH = $(LIBDIR) +#export PATH := .:$(PATH) + +.PHONY: all libs clean dirs + +all: libs + +libs: dirs $(DLIB) $(SLIB) + +dirs: $(LIBDIR) $(OBJDIR) + +$(LIBDIR) $(OBJDIR): + @echo creating $@ directory. + @mkdir $@ + +clean: + @echo deleting $(OBJDIR) and $(LIBDIR) directories. + @$(RM) -rf $(LIBDIR) $(OBJDIR) + +$(SLIB): $(LIBOBJ) + @echo building $@ static library. + @$(AR) $(ARFLAGS) -o $@ $^ + +$(DLIB): CFLAGS += -fPIC +$(DLIB): LDFLAGS += -shared +$(DLIB): $(LIBOBJ) + @echo building $@ shared library. + @$(CC) $(LDFLAGS) $^ -o $@ + +.c: + @echo compiling $< + @$(CC) $(CFLAGS) $(LDFLAGS) -I $(INCDIR) $< $(LDLIB) -o $@ + +#.c.o: +$(OBJDIR)/%.o: %.c + @echo compiling $<. + @$(CC) -c $(CFLAGS) $(LDFLAGS) -I $(INCDIR) -o $@ $< + +.c.s: + @echo generating $@ + @$(CC) -S -fverbose-asm $(CFLAGS) -I $(INCDIR) $< -o $@ diff --git a/c/bits.h b/c/include/bits.h similarity index 100% rename from c/bits.h rename to c/include/bits.h diff --git a/c/debug.h b/c/include/debug.h similarity index 100% rename from c/debug.h rename to c/include/debug.h diff --git a/c/list.h b/c/include/list.h similarity index 100% rename from c/list.h rename to c/include/list.h diff --git a/c/pool.h b/c/include/pool.h similarity index 100% rename from c/pool.h rename to c/include/pool.h diff --git a/c/rwonce.h b/c/include/rwonce.h similarity index 100% rename from c/rwonce.h rename to c/include/rwonce.h