From: Mazet Laurent Date: Fri, 16 May 2025 17:17:53 +0000 (+0200) Subject: add rules to make library and installs X-Git-Tag: v1.0~20 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=4051b5fa89f88637f1007732c753c37aecb29177;p=morep.git add rules to make library and installs --- diff --git a/makefile b/makefile index 04e0dba..3253e37 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,9 @@ + # Default flags +AR ?= ar CC ?= gcc +RANLIB ?= ranlib #INCLUDES = -I../debug -D__MEMORY_ALLOCATION__ INCLUDES += -DVERBOSE_COLOR=1 @@ -19,6 +22,7 @@ CFLAGS += $(OFLAGS) $(INCLUDES) $(OPTIONS) LDFLAGS += -g $(LDOPTS) $(OPTIONS) LDOPT = linker +AROPT = archive MV = mv ifneq (, $(findstring linux, $(MAKE_HOST))) # Linux @@ -27,20 +31,33 @@ else ifneq (, $(findstring mingw, $(MAKE_HOST))) CFLAGS += -DWIN32 #LDLIBS += -lws2_32 LDOPT = winlnk +AROPT = else ifneq (, $(findstring cygwin, $(MAKE_HOST))) -CFLAGS += -DWIN32 # Windows CygWin +CFLAGS += -DWIN32 LDOPT = winlnk +AROPT = else ifneq (, $(findstring msdos, $(MAKE_HOST))) # MSDOS LDOPT = doslnk +AROPT = MV = move endif +ifeq ($(DESTDIR),) +DESTDIR = /usr/local +endif + +BINDIR = $(DESTDIR)/bin +INCDIR = $(DESTDIR)/include/ +LIBDIR = $(DESTDIR)/lib + # Targets ALLEXE = $(shell for f in *.c; do grep -q '/\*\s*$(LDOPT):' $$f && echo $${f/.c}; done) +ALLDLL = $(shell for f in *.c; do grep -q '/\*\s*$(AROPT):' $$f && echo lib$${f/.c}; done) + SHELL = bash #MAKE = mingw32-make @@ -54,9 +71,7 @@ PASS = echo -e "\033[1;32m$(strip $(1))\033[0;0m" WARN = echo -e "\033[1;33m$(strip $(1))\033[0;0m" FAIL = echo -e "\033[1;31m$(strip $(1))\033[0;0m" -MKDIR = mkdir -p $(1) && chmod a+rx,go-w $(1) - -INSTALL = test -d `dirname $(2)` || $(call MKDIR, `dirname $(2)`) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2) +INSTALL = test -d $(2) || mkdir -p $(2) && cp -pa $(1) $(2) && chmod a+rX,go-w $(2) $(addprefix $(2)/,$(1)) VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, FAILED); test; } @@ -95,10 +110,13 @@ gcovs: wipe gprofs: $(MAKE) $(addprefix gprof_,$(ALLEXE)) +lib: depends + [ "$(ALLDLL)" ] || { $(call FAIL,no exec to proceed); test; } && $(MAKE) $(ALLDLL:%=%.a) + purge: clean $(call TITLE, "Purging") touch purge - rm -f purge $(ALLEXE:%=%.exe) + rm -f purge $(ALLEXE:%=%.exe) $(ALLDLL:%=%.a) $(call PASS, SUCCESS) valgrinds: @@ -194,6 +212,31 @@ valgrind_%: %.exe $(CC) $(LDFLAGS) $< $(shell $(call GETCOMMENTS,$(LDOPT), ${<:.o=.c})) $(LDLIBS) -o $@ $(call PASS, SUCCESS) +lib%.a: %.o %.d + $(call TITLE, "Building $@") + $(AR) qc $@ $< $(shell $(call GETCOMMENTS,$(AROPT), ${<:.o=.c})) + $(RANLIB) $@ + $(call PASS, SUCCESS) + +## install rules + +install_lib%: lib%.a + $(call TITLE, "Install $<") + $(call INSTALL, $(shell $(call GETCOMMENTS,include, `echo $< | sed 's/^lib//;s/\.a$$/.c/'`)), $(INCDIR)/`echo $< | sed 's/^lib//;s/\.a$$//'`) + $(call INSTALL, $<, $(LIBDIR)) + $(call PASS, SUCCESS) + +install_%: %.exe + $(call TITLE, "Install $<") + $(call INSTALL, $<, $(BINDIR)) + $(call PASS, SUCCESS) + +install_lib: + make $(addprefix install_,$(ALLDLL)) + +install_exe: + make $(addprefix install_,$(ALLEXE)) + ## Phony .PHONY: all analyze clean count depends documentation gcovs purge tests diff --git a/morep.c b/morep.c index fac0823..75454ce 100644 --- a/morep.c +++ b/morep.c @@ -4,6 +4,9 @@ Copyright Thales 20250319 */ +/* include: def.h parse.h pdu_bypass.h pdu_channel.h pdu_clear_data.h pdu_encrypted_data.h pdu_key.h pdu_prng_param.h pdu_raw_data.h pdu_status.h verbose.h */ +/* archive: parse.o pdu_bypass.o pdu_channel.o pdu_clear_data.o pdu_encrypted_data.o pdu_key.o pdu_prng_param.o pdu_raw_data.o pdu_status.o */ + #include #include #include