From 938a605d5a1ac39b63cf8b84a64d584b6126c296 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 9 Jul 2024 16:27:32 +0200 Subject: [PATCH] fix Makefile --- README.md | 13 +++++- src/cbook/makefile.d | 97 ++++++++++++++++++++++++++++---------------- 2 files changed, 73 insertions(+), 37 deletions(-) mode change 100644 => 100755 src/cbook/makefile.d diff --git a/README.md b/README.md index c3890ec..8d57259 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ PL/1 data files to CSV conversion utility. ## Synopsis - `cbook --help` +- `cbook --book BOOK.PLI (IN.DATA (OUT.CSV))` +- `cbook --b BOOK.PLI (IN.DATA (OUT.CSV))` ## Description @@ -14,7 +16,16 @@ Works with EBCDIC data and PL/1 books. ## Options -- **--help** (or **-h**): information about the syntax +- **-h** / **--help**: this help message +- **-o** / **--output-flat**: output is one line per field +- **-m** / **--output-ms**: output is Microsoft CSV (default) +- **-c** / **--output-csv**: output is CSV +- **-d** / **--debug**: add a lot of DEBUG information +- **-i** / **--ignore-errors**: ignore errors and continue +- **-r** / **--raw-ebcdic**: consider input to be raw EBCDIC +- **BOOK.PLI**: a data description include book (in PL/1) +- **IN.DATA**: the text/binary input file, defaults to stdin +- **OUT.CSV**: the CSV output file, defaults to stdout ## Compilation diff --git a/src/cbook/makefile.d b/src/cbook/makefile.d old mode 100644 new mode 100755 index 88fbb17..ec49432 --- a/src/cbook/makefile.d +++ b/src/cbook/makefile.d @@ -1,34 +1,74 @@ -# Note: 99+ required for for-loop initial declaration (CentOS 6) +# +# Makefile for C projets +# > NAME : the name of the main program (if programs, make a single .d file +# per program, link them up in Makfile and use a $ssrcdir) +# > srcdir : the source directory +# > ssrcdir: the sub-sources directory (defaults to $srcdir) +# > dstdir: the destination directory (defaults to $srcdir/bin) +# +# Environment variables: +# > PREFIX: where to (un)install (defaults to /usr/local) +# > DEBUG: define it to build with all debug symbols +# +NAME = cbook +srcdir = $(NAME) +ssrcdir = $(srcdir) + +# Note: c99+ required for for-loop initial declaration (not default in CentOS 6) +# Note: gnu99 can be required for some projects (i.e.: libcutils-net) +CFLAGS += -Wall -pedantic -I./ -std=c99 +CXXFLAGS += -Wall -pedantic -I./ +PREFIX = /usr/local + +# Required libraries if any: +# LDFLAGS += -lcheck -NAME = cbook -NAMES = $(NAME) -srcdir = $(NAME) +# Required *locally compiled* libraries if any: +LIBS = cutils + +################################################################################ ifeq ($(dstdir),) dstdir = $(srcdir)/bin endif -CFLAGS += -Wall -pedantic -I./ -std=c99 -CXXFLAGS += -Wall -pedantic -I./ -# LDFLAGS += -lcheck -PREFIX = /usr/local - ifdef DEBUG CFLAGS += -ggdb -O0 CXXFLAGS += -ggdb -O0 endif -.PHONY: all build install uninstall clean mrpropre mrpropre \ - $(NAMES) deps test run run-test run-test-more +# Default target +.PHONY: all deps +all: + +# locally compiled libs: +ifneq ($(LIBS),) +LDFLAGS += -L$(dstdir) +LDFLAGS += $(foreach lib,$(LIBS),-l$(lib)) +endif +deps: + $(foreach lib,$(LIBS),$(MAKE) --no-print-directory \ + -C $(lib)/ $(lib) dstdir=$(dstdir)) + +.PHONY: build rebuild install uninstall clean mrpropre mrpropre \ + $(NAME) test run run-test run-test-more -SOURCES=$(wildcard $(srcdir)/*.c) +SOURCES=$(wildcard $(ssrcdir)/*.c) OBJECTS=$(SOURCES:%.c=%.o) +DEPENDS =$(SOURCES:%.c=%.d) + +# Autogenerate dependencies from code +-include $(DEPENDS) +%.o: %.c + $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ # Main targets all: build -build: $(NAMES) +build: $(NAME) + +rebuild: clean build $(NAME): deps $(dstdir)/$(NAME) @@ -39,36 +79,21 @@ run: test run-test run-test-more: @echo you are in the sources of the program, look at the tests instead -################ -# Dependencies # -################ -## Libs (if needed) -deps: - $(MAKE) --no-print-directory -C cutils/ cutils -DEPS=$(dstdir)/libcutils.o - -## Headers -DEPENDS=$(SOURCES:%.c=%.d) --include $(DEPENDS) -%.o: %.c - $(CC) $(CFLAGS) -MMD -MP -c $< -o $@ -################ - -$(dstdir)/$(NAME): $(DEPS) $(OBJECTS) +$(dstdir)/$(NAME): $(OBJECTS) mkdir -p $(dstdir) - # note: -r = --relocatable, but former also works with Clang - $(CC) $(CFLAGS) $(LDFLAGS) $(DEPS) $(OBJECTS) -o $@ - -debug: - $(MAKE) -f $(srcdir)/makefile.d DEBUG=1 + # note: LDFLAGS *must* be near the end + $(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS) clean: + $(foreach lib,$(LIBS),$(MAKE) --no-print-directory \ + -C $(lib)/ $@ dstdir=$(dstdir)) rm -f $(OBJECTS) rm -f $(DEPENDS) - rm -f $(DEPS) mrproper: mrpropre mrpropre: clean + $(foreach lib,$(LIBS),$(MAKE) --no-print-directory \ + -C $(lib)/ $@ dstdir=$(dstdir)) rm -f $(dstdir)/$(NAME) rmdir $(dstdir) 2>/dev/null || true @@ -76,7 +101,7 @@ install: build mkdir -p "$(PREFIX)/bin" cp "$(dstdir)/$(NAME)" "$(PREFIX)/bin/" -uninstall: build +uninstall: rm "$(PREFIX)/bin/$(NAME)" rmdir "$(PREFIX)/bin" 2>/dev/null -- 2.27.0