Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve POSIX Make compatibility #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ xgettext
gettext
ngettext
envsubst
ldlibs
48 changes: 19 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@ else ifeq ($(LIBINTL), NONE)
HEADERS =
else
LIBSRC = libintl/libintl.c
HEADERS = libintl.h
HEADERS = include/libintl.h
endif
PROGSRC = $(sort $(wildcard src/*.c))

PARSEROBJS = src/poparser.o src/StringEscape.o
PROGOBJS = $(PROGSRC:.c=.o)
PROGOBJS = src/msgmerge.o src/msgfmt.o
LIBOBJS = $(LIBSRC:.c=.o)
OBJS = $(PROGOBJS) $(LIBOBJS)
OBJS = $(PARSEROBJS) $(PROGOBJS) $(LIBOBJS)

ALL_INCLUDES = $(HEADERS)
ifneq ($(LIBINTL), NONE)
ALL_LIBS=libintl.a
endif
ALL_TOOLS=msgfmt msgmerge xgettext autopoint
ALL_M4S=$(sort $(wildcard m4/*.m4))
ALL_DATA=$(sort $(wildcard data/*))

CFLAGS ?= -O0 -fPIC

Expand All @@ -42,52 +39,45 @@ INSTALL ?= ./install.sh

-include config.mak

LDLIBS:=$(shell echo "int main(){}" | $(CC) $(CFLAGS) $(LDFLAGS) -liconv -x c - >/dev/null 2>&1 && printf %s -liconv)

BUILDCFLAGS=$(CFLAGS)

all: $(ALL_LIBS) $(ALL_TOOLS)

install: $(ALL_LIBS:lib%=$(DESTDIR)$(libdir)/lib%) $(ALL_INCLUDES:%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:%=$(DESTDIR)$(bindir)/%) $(ALL_M4S:%=$(DESTDIR)$(datadir)/%) $(ALL_M4S:%=$(DESTDIR)$(acdir)/%) $(ALL_DATA:%=$(DESTDIR)$(datadir)/%)

clean:
rm -f $(ALL_LIBS)
rm -f $(OBJS)
rm -f $(ALL_TOOLS)
rm -f ldlibs

%.o: %.c
.c.o:
$(CC) $(BUILDCFLAGS) -c -o $@ $<

libintl.a: $(LIBOBJS)
rm -f $@
$(AR) rc $@ $(LIBOBJS)
$(RANLIB) $@

msgmerge: $(OBJS)
$(CC) -o $@ src/msgmerge.o $(PARSEROBJS) $(LDFLAGS) $(LDLIBS)
ldlibs:
echo "int main(){}" | $(CC) $(CFLAGS) $(LDFLAGS) -liconv -x c - >/dev/null 2>&1 && printf %s -liconv || true > ldlibs

msgfmt: $(OBJS)
$(CC) -o $@ src/msgfmt.o $(PARSEROBJS) $(LDFLAGS) $(LDLIBS)
msgmerge: src/msgmerge.o $(PARSEROBJS) ldlibs
$(CC) -o $@ src/msgmerge.o $(PARSEROBJS) $(LDFLAGS) `cat ldlibs`

msgfmt: src/msgfmt.o $(PARSEROBJS) ldlibs
$(CC) -o $@ src/msgfmt.o $(PARSEROBJS) $(LDFLAGS) `cat ldlibs`

xgettext:
cp src/xgettext.sh ./xgettext

autopoint: src/autopoint.in
cat $< | sed 's,@datadir@,$(datadir),' > $@

$(DESTDIR)$(libdir)/%.a: %.a
$(INSTALL) -D -m 755 $< $@

$(DESTDIR)$(includedir)/%.h: include/%.h
$(INSTALL) -D -m 644 $< $@

$(DESTDIR)$(bindir)/%: %
$(INSTALL) -D -m 755 $< $@

$(DESTDIR)$(datadir)/%: %
$(INSTALL) -D -m 644 $< $@

$(DESTDIR)$(acdir)/%: %
$(INSTALL) -D -l ../$(subst $(datarootdir)/,,$(datadir))/$< $(patsubst %m4/,%,$(dir $@))/$(notdir $@)
install: $(ALL_LIBS) $(ALL_INCLUDES) $(ALL_TOOLS)
$(INSTALL) -D -m 755 $(ALL_LIBS) $(DESTDIR)$(libdir)/
$(INSTALL) -D -m 644 $(ALL_INCLUDES) $(DESTDIR)$(includedir)/
$(INSTALL) -D -m 755 $(ALL_TOOLS) $(DESTDIR)$(bindir)/
$(INSTALL) -D -m 644 m4/*.m4 $(DESTDIR)$(datadir)/m4/
$(INSTALL) -D -m 644 data/* $(DESTDIR)$(datadir)/data/
for i in m4/*.m4 ; do $(INSTALL) -D -l $(datadir)/$$i $(DESTDIR)$(acdir)/$${i#m4/}; done

.PHONY: all clean install
88 changes: 60 additions & 28 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,46 @@
# file atomically in the new location, rather than overwriting
# existing files.
#
# Enhanced by Haelwenn (lanodan) Monnier to support multiple src arguments

progname="$0"

usage() {
printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
printf "usage: %s [-D] [-l] [-m mode] src... dest\n" "$progname" 1>&2
exit 1
}

install() {
src="$1"
dst="$2"
tmp="$3"

umask 077

test -d "$dst" && {
printf "%s: Destination file '%s' is a directory\n" "$progname" "$dst" 1>&2
exit 1
}
test -d "$src" && {
printf "%s: Source file '%s' is a directory\n" "$progname" "$src" 1>&2
exit 1
}

set -C
set -e

trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP

if test "$symlink" ; then
ln -s "$src" "$tmp"
else
cat < "$src" > "$tmp"
chmod "$mode" "$tmp"
fi

mv -f "$tmp" "$dst"
}

mkdirp=
symlink=
mode=755
Expand All @@ -27,41 +61,39 @@ esac
done
shift $(($OPTIND - 1))

test "$#" -eq 2 || usage
src=$1
dst=$2
tmp="$dst.tmp.$$"
test 1 -lt "$#" || usage

case "$dst" in
*/) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
esac
for dst in "$@" ; do :; done

dir=
test 2 -lt "$#" && dir="${dst}/"

set -C
set -e

if test "$mkdirp" ; then
umask 022
case "$2" in
*/*) mkdir -p "${dst%/*}" ;;
esac
fi
while test 1 -lt "$#"; do
src="$1"
dst="$2"
shift

trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
if test -n "$dir"; then
dst="${dir}${src#*/}"
else
case "$dst" in
*/) dst="${dst}${src#*/}" ;;
esac
fi

umask 077
if test "$mkdirp" ; then
umask 022
case "$dst" in
*/*) mkdir -p "${dst%/*}" ;;
esac
fi

if test "$symlink" ; then
ln -s "$1" "$tmp"
else
cat < "$1" > "$tmp"
chmod "$mode" "$tmp"
fi
tmp="$dst.tmp.$$.$#"

mv -f "$tmp" "$2"
test -d "$2" && {
rm -f "$2/$tmp"
printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
exit 1
}
install "${src:?}" "${dst:?}" "${tmp:?}"
done

exit 0