From 752c669234d38ec8e0dedff7df6290a14782f9f0 Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Tue, 17 Mar 2026 10:04:50 +0100 Subject: [PATCH 1/8] Makefile: Explicitly build objects in subdirs --- Makefile | 7 ++----- build_ripOLE | 4 ---- build_tnef | 3 --- 3 files changed, 2 insertions(+), 12 deletions(-) delete mode 100755 build_ripOLE delete mode 100755 build_tnef diff --git a/Makefile b/Makefile index 9299dfd..7e813e1 100644 --- a/Makefile +++ b/Makefile @@ -45,11 +45,8 @@ debug: default buildcodes.h: ./generate-buildcodes.sh -ripOLE/ole.o: - ./build_ripOLE - -tnef/tnef.o: - ./build_tnef +${RIPOLE_OBJS} tnef/tnef.o: + ${MAKE} -C ${@D} ${@F} .c.o: ${CC} ${CFLAGS} $(COMPONENTS) -c $*.c diff --git a/build_ripOLE b/build_ripOLE deleted file mode 100755 index 8b61c60..0000000 --- a/build_ripOLE +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cd ripOLE -make clean -make diff --git a/build_tnef b/build_tnef deleted file mode 100755 index b10f7ea..0000000 --- a/build_tnef +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -cd tnef -make From 17ab29193d55e7d499079d12a8633c79456f6b41 Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Mon, 16 Mar 2026 13:43:19 +0100 Subject: [PATCH 2/8] Makefile: Add automake-compatible installation rules --- Makefile | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7e813e1..2168560 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ # # 0.1.13: Added -I. -LOCATION=/usr/local VERSION=0.1.15 # VERSION changes #--------------------- @@ -72,12 +71,19 @@ ripmime: ${OFILES} ripmime.c buildcodes.h riptest: ${OFILES} ${CC} ${CFLAGS} riptest.c ${OFILES} -o riptest -install: ${OBJ} - strip ripmime - install -d ${LOCATION}/bin/ - install -m 755 ripmime ${LOCATION}/bin/ - install -d ${LOCATION}/man/ - install -m 644 ripmime.1 ${LOCATION}/man/man1 +DESTDIR = +prefix = /usr/local + exec_prefix = ${prefix} + bindir = ${exec_prefix}/bin + datarootdir = ${prefix}/share + mandir = ${datarootdir}/man + +.PHONY: install install-exec install-man +install: install-exec install-man +install-exec: ${OBJ} + install -m555 -s -Dt ${DESTDIR}${bindir} ${OBJ} +install-man: + install -m444 -Dt ${DESTDIR}${mandir}/man1 ripmime.1 ffget_test: ffget_mmap_test.c ffget_mmap.[ch] logger.o ffget_mmap.o ${CC} ${CFLAGS} ffget_mmap_test.c logger.o ffget_mmap.o -o ffgt From f062f976164eb84e0005f99fa4b2a6d1c4e5f0c8 Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Tue, 17 Mar 2026 06:57:04 +0100 Subject: [PATCH 3/8] Makefile: Respect CFLAGS --- Makefile | 2 +- ripOLE/Makefile | 2 +- tnef/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 2168560..301aec8 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ VERSION=0.1.15 # use our recommended settings. #CFLAGS ?= -Wall -g -O2 -Werror $(CPU_OPTS) #CFLAGS=-Wall -g -O2 -Wundef -Wshadow -Wsign-compare -I. -CFLAGS=-Wall -I. -O2 +CFLAGS ?= -Wall -Wextra -O2 # OLE decoding is still considered to be 'beta' mode - so it # disabled in the stable release of ripMIME for now diff --git a/ripOLE/Makefile b/ripOLE/Makefile index 6276e04..ab1a912 100644 --- a/ripOLE/Makefile +++ b/ripOLE/Makefile @@ -1,6 +1,6 @@ OBJS= ole.o olestream-unwrap.o bytedecoders.o logger.o pldstr.o bt-int.o -CFLAGS=-Wall -g -O2 -I. +CFLAGS ?= -Wall -Wextra -O2 .c.o: diff --git a/tnef/Makefile b/tnef/Makefile index a527c55..871b1af 100644 --- a/tnef/Makefile +++ b/tnef/Makefile @@ -5,7 +5,7 @@ # default is big endian. You can do -D__TNEF_BYTE_ORDER 1234 for little # endian PLATFORM=-D___TNEF_BYTE_ORDER=4321 -CFLAGS=-Wall -g -O2 -I. +CFLAGS ?= -Wall -Wextra -O2 default: config.h tnef.h tnef.c $(CC) $(CFLAGS) $(PLATFORM) -c tnef.c From e4b2d646df01cb39b14fa3baafa30e9f82a55e36 Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Tue, 17 Mar 2026 08:04:26 +0100 Subject: [PATCH 4/8] Makefile: Improve shared library build & installation - Full library file name in ${solib}. - Target-specific LDFLAGS in ${$@-LDFLAGS}. - Sources in ${$@-objs}. - Added ${libdir}, and rules: install-static and install-shared. - Two-tiered variables so the user can override without affecting mandatory flags. E.g. CFLAGS -> CFLAGS-y --- Makefile | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 301aec8..b24e4a9 100644 --- a/Makefile +++ b/Makefile @@ -45,16 +45,28 @@ buildcodes.h: ./generate-buildcodes.sh ${RIPOLE_OBJS} tnef/tnef.o: - ${MAKE} -C ${@D} ${@F} + ${MAKE} -C ${@D} ${@F} CFLAGS="${CFLAGS} ${CFLAGS-y}" .c.o: - ${CC} ${CFLAGS} $(COMPONENTS) -c $*.c + ${CC} ${CFLAGS-y} ${COMPONENTS} -c $*.c + +CFLAGS-y = ${CFLAGS} +LDFLAGS-y = ${LDFLAGS} all: ${OBJ} +solib := libripmime.so.1.4.0 +solib-soname != awk -vlib=${solib} -vsuffix="\\.so\\.[0-9]+" \ + 'BEGIN{match(lib,suffix);print substr(lib,1,RSTART+RLENGTH-1)}' +solib-basename != awk -vlib=${solib} -vsuffix="\\.so" \ + 'BEGIN{match(lib,suffix);print substr(lib,1,RSTART+RLENGTH-1)}' + +${solib}-LDFLAGS := -shared -Wl,-soname,${solib-soname} +${solib}-objs := ${OFILES} ripmime-api.o +solib: ${solib} +${solib}: ${${solib}-objs} + ${CC} ${$@-LDFLAGS} ${LDFLAGS-y} ${CFLAGS-y} -o $@ ${$@-objs} ${LIBS} -solib: ${OFILES} ripmime-api.o - gcc --shared -Wl,-soname,libripmime.so.1 ${OFILES} ripmime-api.o -o libripmime.so.1.4.0 -lc libripmime: ${OFILES} ripmime-api.o ar ruvs libripmime.a ${OFILES} ripmime-api.o @@ -65,20 +77,32 @@ ripl: ripmime.a sco: ${OFILES} ${CC} ${CFLAGS} ripmime.c ${OFILES} -o ripmime -lsocket -ripmime: ${OFILES} ripmime.c buildcodes.h - ${CC} ${CFLAGS} $(COMPONENTS) ripmime.c ${OFILES} -o ripmime ${LIBS} +ripmime.o: buildcodes.h +ripmime: ${OFILES} ripmime.o + ${CC} ${LDFLAGS-y} ${CFLAGS-y} ${COMPONENTS} $@.o -o $@ ${OFILES} ${LIBS} riptest: ${OFILES} - ${CC} ${CFLAGS} riptest.c ${OFILES} -o riptest + ${CC} ${LDFLAGS-y} ${CFLAGS-y} $@.c ${OFILES} -o $@ DESTDIR = prefix = /usr/local exec_prefix = ${prefix} bindir = ${exec_prefix}/bin + libdir = ${exec_prefix}/lib datarootdir = ${prefix}/share mandir = ${datarootdir}/man .PHONY: install install-exec install-man +.PHONY: install-static install-shared install-headers + +install-static: libripmime.a + install -m444 -Dt ${DESTDIR}${libdir} libripmime.a + +install-shared: ${solib} + install -m555 -Dt ${DESTDIR}${libdir} ${solib} + ln -sf ${solib} ${DESTDIR}${libdir}/${solib-soname} + ln -sf ${solib} ${DESTDIR}${libdir}/${solib-basename} + install: install-exec install-man install-exec: ${OBJ} install -m555 -s -Dt ${DESTDIR}${bindir} ${OBJ} @@ -86,8 +110,7 @@ install-man: install -m444 -Dt ${DESTDIR}${mandir}/man1 ripmime.1 ffget_test: ffget_mmap_test.c ffget_mmap.[ch] logger.o ffget_mmap.o - ${CC} ${CFLAGS} ffget_mmap_test.c logger.o ffget_mmap.o -o ffgt - + ${CC} ${LDFLAGS-y} ${CFLAGS-y} ffget_mmap_test.c logger.o ffget_mmap.o -o ffgt clean: rm -f *.o *core ${OBJ} buildcodes.h From b04c4f64f31aeb794cc8fd43a726e32a18262a2b Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Tue, 17 Mar 2026 08:44:58 +0100 Subject: [PATCH 5/8] Makefile: Clean up targets - Merge all and default - No .o should be a dependency of a phony target - Simplify sco - Mark phony targets - Split clean target - MIMEH*: Split properly into phony and real target, add cleaning --- Makefile | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index b24e4a9..f67d561 100644 --- a/Makefile +++ b/Makefile @@ -35,15 +35,19 @@ RIPOLE_OBJS= ripOLE/ole.o ripOLE/olestream-unwrap.o ripOLE/bytedecoders.o ripOL #RIPOLE_OBJS= OFILES= strstack.o mime.o ffget.o MIME_headers.o tnef/tnef.o rawget.o pldstr.o logger.o libmime-decoders.o boundary-stack.o uuencode.o filename-filters.o $(RIPOLE_OBJS) - -default: tnef/tnef.o ripmime ripOLE/ole.o - +all: ripmime debug: CFLAGS=-Wall -ggdb -DDEBUG -I. -O0 -debug: default +debug: all +sco: LIBS += -lsocket +sco: ripmime +.PHONY: all debug sco buildcodes.h: ./generate-buildcodes.sh +clean:: + rm -f buildcodes.h + ${RIPOLE_OBJS} tnef/tnef.o: ${MAKE} -C ${@D} ${@F} CFLAGS="${CFLAGS} ${CFLAGS-y}" @@ -53,7 +57,6 @@ ${RIPOLE_OBJS} tnef/tnef.o: CFLAGS-y = ${CFLAGS} LDFLAGS-y = ${LDFLAGS} -all: ${OBJ} solib := libripmime.so.1.4.0 solib-soname != awk -vlib=${solib} -vsuffix="\\.so\\.[0-9]+" \ 'BEGIN{match(lib,suffix);print substr(lib,1,RSTART+RLENGTH-1)}' @@ -67,15 +70,19 @@ solib: ${solib} ${solib}: ${${solib}-objs} ${CC} ${$@-LDFLAGS} ${LDFLAGS-y} ${CFLAGS-y} -o $@ ${$@-objs} ${LIBS} +clean:: + rm -f ${solib} -libripmime: ${OFILES} ripmime-api.o - ar ruvs libripmime.a ${OFILES} ripmime-api.o +ARFLAGS = ruvs +libripmime.a: ${OFILES} ripmime-api.o + ${AR} ${ARFLAGS} $@ ${OFILES} ripmime-api.o + +clean:: + rm -f libripmime.a ripl: ripmime.a ${CC} ${CFLAGS} ripmime.c ripmime.a -o ripmime -sco: ${OFILES} - ${CC} ${CFLAGS} ripmime.c ${OFILES} -o ripmime -lsocket ripmime.o: buildcodes.h ripmime: ${OFILES} ripmime.o @@ -84,6 +91,9 @@ ripmime: ${OFILES} ripmime.o riptest: ${OFILES} ${CC} ${LDFLAGS-y} ${CFLAGS-y} $@.c ${OFILES} -o $@ +clean:: + rm -f ripmime riptest + DESTDIR = prefix = /usr/local exec_prefix = ${prefix} @@ -112,10 +122,16 @@ install-man: ffget_test: ffget_mmap_test.c ffget_mmap.[ch] logger.o ffget_mmap.o ${CC} ${LDFLAGS-y} ${CFLAGS-y} ffget_mmap_test.c logger.o ffget_mmap.o -o ffgt -clean: - rm -f *.o *core ${OBJ} buildcodes.h +.PHONY: clean +clean:: + rm -f *.o *core rm -f tnef/*.o rm -f ripOLE/*.o ripOLE/ripole -MIMEH: MIME_headers.o strlower.o - ${CC} ${CFLAGS} MIMEH_test.c MIME_headers.o strlower.o -o MIMEH_test +.PHONY: MIMEH +MIMEH: MIMEH_test +MIMEH_test-objs = MIMEH_test.o MIME_headers.o strlower.o +MIMEH_test: ${MIMEH_test-objs} + ${CC} ${LDFLAGS-y} ${CFLAGS-y} ${$@-objs} -o $@ +clean:: + rm -f MIMEH_test From cb1de93e1216fe33c4fed2e4c15dfb6251d6013f Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Tue, 17 Mar 2026 08:59:34 +0100 Subject: [PATCH 6/8] Makefile: Implement configuration saving This way, changing a configuration variable is persistent; no need to specify them every time. The .config file is included twice so that only user-specified variables get updated. This is compatible with GNU make 4.4+ and NetBSD make and derivatives. Also added a distclean target to clean the .config file. --- .gitignore | 1 + Makefile | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fada2a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.config diff --git a/Makefile b/Makefile index f67d561..45a65b1 100644 --- a/Makefile +++ b/Makefile @@ -135,3 +135,31 @@ MIMEH_test: ${MIMEH_test-objs} ${CC} ${LDFLAGS-y} ${CFLAGS-y} ${$@-objs} -o $@ clean:: rm -f MIMEH_test + +# Macro to extract a quoted & unexpanded variable +quote = '$(subst ','\'',$(value $1))' + +# Save and restore configuration variables +-include .config +_ != { \ + echo 'AR = '${AR:Q}$(call quote,AR); \ + echo 'ARFLAGS = '${ARFLAGS:Q}$(call quote,ARFLAGS); \ + echo 'CC = '${CC:Q}$(call quote,CC); \ + echo 'CFLAGS = '${CFLAGS:Q}$(call quote,CFLAGS); \ + echo 'LDFLAGS = '${LDFLAGS:Q}$(call quote,LDFLAGS); \ + echo 'LIBS = '${LIBS:Q}$(call quote,LIBS); \ + echo; \ + echo 'prefix = '${prefix:Q}$(call quote,prefix); \ + echo ' exec_prefix = '${exec_prefix:Q}$(call quote,exec_prefix); \ + echo ' bindir = '${bindir:Q}$(call quote,bindir); \ + echo ' libdir = '${libdir:Q}$(call quote,libdir); \ + echo ' datarootdir = '${datarootdir:Q}$(call quote,datarootdir); \ + echo ' mandir = '${mandir:Q}$(call quote,mandir); \ + } > .config +include .config + +# FIXME: variables (unintuitivelly) are expanded when saving in bmake + +.PHONY: distclean +distclean:: clean + rm -f .config From b9d923b4f547b7347886879a040cd6ab12c558ba Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Tue, 17 Mar 2026 09:07:02 +0100 Subject: [PATCH 7/8] Makefile: Enable building against the libraries The use-solib variable controls which one is used: - use-solib=y => dynamically linked libripmime - use-solib=n (default) => traditional build Added RPATH to support installing to non-standard directories, and -fPIC so the code is relocatable. I see no need to preserve building against the .o files directly. --- Makefile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 45a65b1..d247da7 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,9 @@ ${RIPOLE_OBJS} tnef/tnef.o: CFLAGS-y = ${CFLAGS} LDFLAGS-y = ${LDFLAGS} +LDFLAGS-y += -Wl,-rpath,${libdir} + +CFLAGS-${use-solib} += -fPIC solib := libripmime.so.1.4.0 solib-soname != awk -vlib=${solib} -vsuffix="\\.so\\.[0-9]+" \ @@ -80,13 +83,14 @@ libripmime.a: ${OFILES} ripmime-api.o clean:: rm -f libripmime.a -ripl: ripmime.a - ${CC} ${CFLAGS} ripmime.c ripmime.a -o ripmime - +use-solib = n +-lib := ${use-solib:y=${solib}} ${use-solib:n=libripmime.a} +-lib := ${-lib:y=} +-lib := ${-lib:n=} ripmime.o: buildcodes.h -ripmime: ${OFILES} ripmime.o - ${CC} ${LDFLAGS-y} ${CFLAGS-y} ${COMPONENTS} $@.o -o $@ ${OFILES} ${LIBS} +ripmime: ${-lib} ripmime.o buildcodes.h + ${CC} ${LDFLAGS-y} ${CFLAGS-y} ${COMPONENTS} $@.o -o $@ ${-lib} ${LIBS} riptest: ${OFILES} ${CC} ${LDFLAGS-y} ${CFLAGS-y} $@.c ${OFILES} -o $@ @@ -155,6 +159,8 @@ _ != { \ echo ' libdir = '${libdir:Q}$(call quote,libdir); \ echo ' datarootdir = '${datarootdir:Q}$(call quote,datarootdir); \ echo ' mandir = '${mandir:Q}$(call quote,mandir); \ + echo; \ + echo 'use-solib = '${use-solib:Q}$(call quote,use-solib); \ } > .config include .config From 1797e7451584fc67a44ea0ff0eeae217a2185175 Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Tue, 17 Mar 2026 09:08:17 +0100 Subject: [PATCH 8/8] Makefile: Conditionally add solib to the install target --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index d247da7..8a56f96 100644 --- a/Makefile +++ b/Makefile @@ -112,6 +112,7 @@ prefix = /usr/local install-static: libripmime.a install -m444 -Dt ${DESTDIR}${libdir} libripmime.a +install-exec${use-solib:y=}: install-shared install-shared: ${solib} install -m555 -Dt ${DESTDIR}${libdir} ${solib} ln -sf ${solib} ${DESTDIR}${libdir}/${solib-soname}