Skip to content

Commit

Permalink
Improve build system
Browse files Browse the repository at this point in the history
* Add DESTDIR support. Closes issue #39
* Install directories separately from files.
	install command on primitive platforms like BSD does not
	support the -D flag, so destination directories must be
	created separately. Fixes issues #36 and #49
* Add installdirs target.
	In addition to the above, installdirs target conforms to
	GNU makefile conventions.
* Make CFLAGS and LDFLAGS overridable in the Makefile.
	This is done the same way as with DESTDIR, using make CFLAGS=-w,
	which will override CFLAGS for this one build. CFLAGS variable in
	the Config.mk now contains only the optional flags, the warnings,
	and the cflags variable that Makefile uses appends CFLAGS so
	that it can override hardcoded flags in Config.mk. Note that
	configure does not look at CFLAGS environment variable; this is
	only for running make. This closes issue #43
* Check for pkg-config not being installed and don't call it then.
	I didn't check for empty output of which when I wrote this last.
	Should detect no pkg-config properly now and fall back to
	default subs. Fixes issues #35 and #41
  • Loading branch information
msharov committed Apr 8, 2021
1 parent a243e2b commit 268ef84
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.o
.o
config.h
Config.mk
config.status
43 changes: 21 additions & 22 deletions Config.mk.in
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
################ Package information #################################

NAME := @PKG_NAME@
VERSION := @PKG_VERSION@

#DEBUG := 1
name := @pkg_name@

################ Programs ############################################

CC := @CC@
MSGFMT := @MSGFMT@
INSTALL := @INSTALL@

INSTALLEXE := ${INSTALL} -D -p -m 755 -s
INSTALLSCR := ${INSTALL} -D -p -m 755
INSTALLDATA := ${INSTALL} -D -p -m 644
INSTALL_DATA := ${INSTALL} -m 644
INSTALL_PROGRAM := ${INSTALL} -m 755

################ Destination #########################################

PREFIX := @prefix@
BINDIR := @bindir@
LOCALEPATH := @localedir@
MANPATH := @mandir@
BUILDDIR := @builddir@/${NAME}
PKGDIR := @pkgdir@
prefix := @prefix@
bindir := @bindir@
datadir := @datadir@
mandir := @mandir@
man1dir := @man1dir@
localedir := @localedir@
TMPDIR := @TMPDIR@
builddir := @builddir@/${name}
O := .o/

################ Compiler options ####################################

CFLAGS := -Wall -Wextra -Wredundant-decls -Wshadow \
-std=c11 -I/usr/include/libxml2
LDFLAGS := -liconv -lintl -lxml2 -lncurses -lz
ifdef DEBUG
CFLAGS += -O0 -ggdb3
LDFLAGS += -g -rdynamic
#debug := 1
libs := @pkg_libs@ -liconv -lintl
ifdef debug
cflags := -O0 -ggdb3
ldflags := -g -rdynamic
else
CFLAGS += -Os -g0 -DNDEBUG=1
LDFLAGS += -s
cflags := -Os -g0 -DNDEBUG=1
ldflags := -s
endif
CFLAGS := -Wall -Wextra -Wredundant-decls -Wshadow
cflags += -std=c11 @pkg_cflags@ ${CFLAGS}
ldflags += @pkg_ldflags@ ${LDFLAGS}
135 changes: 51 additions & 84 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,141 +1,108 @@
include Config.mk
-include Config.mk

################ Source files ##########################################

EXE := $O${NAME}
SRCS := $(wildcard *.c)
OBJS := $(addprefix $O,$(SRCS:.c=.o))
DEPS := ${OBJS:.o=.d}
CONFS := Config.mk config.h
ONAME := $(notdir $(abspath $O))
exe := $O${name}
srcs := $(wildcard *.c)
objs := $(addprefix $O,$(srcs:.c=.o))
deps := ${objs:.o=.d}
confs := Config.mk config.h
oname := $(notdir $(abspath $O))

################ Compilation ###########################################

.SUFFIXES:
.PHONY: all run

all: ${EXE}
all: ${exe}

run: ${EXE}
@${EXE}
run: ${exe}
@${exe}

${EXE}: ${OBJS}
${exe}: ${objs}
@echo "Linking $@ ..."
@${CC} -o $@ $^ ${LDFLAGS}
@${CC} ${ldflags} -o $@ $^ ${libs}

${EXE}-static: ${SRCS}
${CC} -s -static -o $@ ${CFLAGS} ${SRCS} ${LDFLAGS}
${exe}-static: ${srcs}
@echo "Statically linking $@ ..."
@${CC} ${cflags} ${ldflags} -s -static -o $@ $^

$O%.o: %.c
@echo " Compiling $< ..."
@${CC} ${CFLAGS} -MMD -MT "$(<:.c=.s) $@" -o $@ -c $<
@${CC} ${cflags} -MMD -MT "$(<:.c=.s) $@" -o $@ -c $<

%.s: %.c
@echo " Compiling $< to assembly ..."
@${CC} ${CFLAGS} -S -o $@ -c $<
@${CC} ${cflags} -S -o $@ -c $<

include man/Module.mk
include po/Module.mk

################ Installation ##########################################
ifdef BINDIR

.PHONY: install uninstall install-bin uninstall-bin
ifdef bindir
.PHONY: install installdirs uninstall uninstall-bin

EXEI := ${BINDIR}/$(notdir ${EXE})
O2SI := ${BINDIR}/opml2snow
S2OI := ${BINDIR}/snow2opml
exed := ${DESTDIR}${bindir}
exei := ${exed}/$(notdir ${exe})
o2si := ${exed}/opml2snow
s2oi := ${exed}/snow2opml

install: install-bin
install-bin: ${EXEI} ${O2SI} ${S2OI}

${EXEI}: ${EXE}
${exed}:
@echo "Creating $@ ..."
@${INSTALL} -d $@
${exei}: ${exe} | ${exed}
@echo "Installing $@ ..."
@${INSTALLEXE} $< $@
${O2SI}: opml2snow
@${INSTALL_PROGRAM} $< $@
${o2si}: opml2snow | ${exed}
@echo "Installing $@ ..."
@${INSTALLSCR} $< $@
${S2OI}: ${O2SI}
@${INSTALL_PROGRAM} $< $@
${s2oi}: ${o2si} | ${exed}
@echo "Installing $@ ..."
@(cd ${BINDIR}; rm -f $@; ln -s $(notdir $<) $(notdir $@))
@(cd ${exed}; rm -f $@; ln -s $(notdir $<) $(notdir $@))

installdirs: ${exed}
install: ${exei} ${o2si} ${s2oi}
uninstall: uninstall-bin
uninstall-bin:
@if [ -f ${EXEI} ]; then\
echo "Uninstalling ${EXEI} ...";\
rm -f ${EXEI} ${O2SI} ${S2OI};\
@if [ -f ${exei} ]; then\
echo "Removing ${exei} ...";\
rm -f ${exei} ${o2si} ${s2oi};\
fi

endif

################ Maintenance ###########################################

.PHONY: clean distclean maintainer-clean dist dist-binary
.PHONY: clean distclean maintainer-clean

clean:
@if [ -h ${ONAME} ]; then\
rm -f ${EXE} ${EXE}-static ${OBJS} ${DEPS} $O.d ${ONAME};\
rmdir ${BUILDDIR};\
@if [ -d ${builddir} ]; then\
rm -f ${exe} ${exe}-static ${objs} ${deps} $O.d;\
rmdir ${builddir};\
fi

distclean: clean
@rm -f ${CONFS} config.status
@rm -f ${oname} ${confs} config.status

maintainer-clean: distclean

$O.d: ${BUILDDIR}/.d
@[ -h ${ONAME} ] || ln -sf ${BUILDDIR} ${ONAME}
$O.d: ${builddir}/.d
@[ -h ${oname} ] || ln -sf ${builddir} ${oname}
$O%/.d: $O.d
@[ -d $(dir $@) ] || mkdir $(dir $@)
@touch $@
${BUILDDIR}/.d: Makefile
${builddir}/.d: Makefile
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
@touch $@

Config.mk: Config.mk.in
config.h: config.h.in
${OBJS}: Makefile ${CONFS} $O.d
${CONFS}: configure
config.h: config.h.in | Config.mk
${objs}: Makefile ${confs} | $O.d
${confs}: configure
@if [ -x config.status ]; then echo "Reconfiguring ...";\
./config.status;\
else echo "Running configure ...";\
./configure;\
fi

-include ${DEPS}

################ Dist ##################################################

.PHONY: dist dist-binary

DISTDIR := ${NAME}-${VERSION}
DISTFILES := AUTHOR COPYING CREDITS Changelog README README.de README.patching opml2snow \
Makefile configure doc po scripts ${SRCS} $(wildcard *.h) config.h

dist: clean
./configure
mkdir ${DISTDIR}
cp -R ${DISTFILES} ${DISTDIR}
tar -czf ${DISTDIR}.tar.gz ${DISTDIR}
rm -rf ${DISTDIR}

dist-binary: clean ${EXE}-static
DISTDIR=${NAME}-i386-${VERSION}
mkdir ${DISTDIR}
mkdir ${DISTDIR}/man
mkdir ${DISTDIR}/man/de
mkdir ${DISTDIR}/man/nl
mkdir ${DISTDIR}/man/fr
mkdir ${DISTDIR}/man/it
mkdir ${DISTDIR}/man/ru_RU.KOI8-R
mkdir ${DISTDIR}/po
cp AUTHOR COPYING CREDITS Changelog README README.de scripts/INSTALL.binary opml2snow ${DISTDIR}
cp ${EXE}-static ${DISTDIR}/${NAME}
cp doc/man/de/${NAME}.1 ${DISTDIR}/man/de
cp doc/man/nl/${NAME}.1 ${DISTDIR}/man/nl
cp doc/man/fr/${NAME}.1 ${DISTDIR}/man/fr
cp doc/man/it/${NAME}.1 ${DISTDIR}/man/it
cp doc/man/ru_RU.KOI8-R/${NAME}.1 ${DISTDIR}/man/ru_RU.KOI8-R
cp doc/man/${NAME}.1 ${DISTDIR}/man
cp po/*.mo ${DISTDIR}/po
cp scripts/install.sh ${DISTDIR}
tar -cjf ${DISTDIR}.i386.tar.bz2 ${DISTDIR}
rm -rf ${DISTDIR}
-include ${deps}
10 changes: 5 additions & 5 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
#pragma once

// Define to the one symbol short name of this package
#define @PKG_UNAME@_NAME "@PKG_NAME@"
#define @pkg_uname@_NAME "@pkg_name@"
// Define to the version of this package
#define @PKG_UNAME@_VERSION "@PKG_VERSION@"
#define @pkg_uname@_VERSION "@pkg_version@"
// Define to the version string of this package
#define @PKG_UNAME@_VERSTRING "@PKG_VERSTR@"
#define @pkg_uname@_VERSTRING "@pkg_verstr@"
// Define to the address where bug reports for this package should be sent
#define @PKG_UNAME@_BUGREPORT "@PKG_BUGREPORT@"
#define @pkg_uname@_BUGREPORT "@pkg_bugreport@"

// Define to the value of LOCALEPATH environment variable
#define LOCALEPATH "@localedir@"
#define LOCALEPATH "@localepath@"

// Snownews configuration files directory, starts with %s for $HOME
#define SNOWNEWS_CONFIG_DIR "%s/.snownews/"
Expand Down
Loading

0 comments on commit 268ef84

Please sign in to comment.