Skip to content
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
65 changes: 27 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,74 +1,63 @@
ARCH := $(shell uname -m)
ifneq ($(filter i386 i486 i586 i686, $(ARCH)),)
ARCH := i386
endif

GIT2LOG := $(shell if [ -x ./git2log ] ; then echo ./git2log --update ; else echo true ; fi)
GITDEPS := $(shell [ -d .git ] && echo .git/HEAD .git/refs/heads .git/refs/tags)
VERSION := $(shell $(GIT2LOG) --version VERSION ; cat VERSION)
BRANCH := $(shell [ -d .git ] && git branch | perl -ne 'print $$_ if s/^\*\s*//')
PREFIX := libx86emu-$(VERSION)

MAJOR_VERSION := $(shell $(GIT2LOG) --version VERSION ; cut -d . -f 1 VERSION)

CC = gcc
CFLAGS = -g -O2 -fPIC -fvisibility=hidden -fomit-frame-pointer -Wall
LDFLAGS =

LIBDIR = /usr/lib$(shell ldd /bin/sh | grep -q /lib64/ && echo 64)
LIBX86 = libx86emu

CFILES = $(wildcard *.c)
OBJS = $(CFILES:.c=.o)
include config.mk

LIB_NAME = $(LIBX86).so.$(VERSION)
LIB_SONAME = $(LIBX86).so.$(MAJOR_VERSION)

.PHONY: all shared install test demo clean
.PHONY: all shared install uninstall test demo clean distclean

%.o: %.c
$(CC) -c $(CFLAGS) $<
$(CC) -c $(ALL_CFLAGS) $<

all: changelog shared

ifdef LIBX86EMU_VERSION
changelog: ;
else
changelog: $(GITDEPS)
$(GIT2LOG) --changelog changelog
endif

shared: $(LIB_NAME)

install: shared
install -D $(LIB_NAME) $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
ln -snf $(LIB_NAME) $(DESTDIR)$(LIBDIR)/$(LIB_SONAME)
ln -snf $(LIB_SONAME) $(DESTDIR)$(LIBDIR)/$(LIBX86).so
install -m 644 -D include/x86emu.h $(DESTDIR)/usr/include/x86emu.h
install -m 644 -D include/x86emu.h $(DESTDIR)$(INCLUDEDIR)/x86emu.h

uninstall:
rm -f $(DESTDIR)$(LIBDIR)/$(LIB_NAME)
rm -f $(DESTDIR)$(LIBDIR)/$(LIB_SONAME)
rm -f $(DESTDIR)$(LIBDIR)/$(LIBX86).so
rm -f $(DESTDIR)$(INCLUDEDIR)/x86emu.h
rm -f $(DESTDIR)$(OLDINCLUDEDIR)/x86emu.h

$(LIB_NAME): .depend $(OBJS)
$(CC) -shared -Wl,-soname,$(LIB_SONAME) $(OBJS) -o $(LIB_NAME) $(LDFLAGS)
$(CC) -shared -Wl,-soname,$(LIB_SONAME) $(ALL_CFLAGS) $(OBJS) -o $(LIB_NAME) $(LDFLAGS)
@ln -snf $(LIB_NAME) $(LIB_SONAME)
@ln -snf $(LIB_SONAME) $(LIBX86).so

test:
make -C test
$(MAKE) -C test

demo:
make -C demo
$(MAKE) -C demo

archive: changelog
@if [ ! -d .git ] ; then echo no git repo ; false ; fi
mkdir -p package
git archive --prefix=$(PREFIX)/ $(BRANCH) > package/$(PREFIX).tar
tar -r -f package/$(PREFIX).tar --mode=0664 --owner=root --group=root --mtime="`git show -s --format=%ci`" --transform='s:^:$(PREFIX)/:' VERSION changelog
xz -f package/$(PREFIX).tar
git archive --prefix=$(ARCHIVE_PREFIX)/ $(BRANCH) > package/$(ARCHIVE_PREFIX).tar
tar -r -f package/$(ARCHIVE_PREFIX).tar --mode=0664 --owner=root --group=root --mtime="`git show -s --format=%ci`" --transform='s:^:$(ARCHIVE_PREFIX)/:' VERSION changelog
xz -f package/$(ARCHIVE_PREFIX).tar

clean:
make -C test clean
make -C demo clean
$(MAKE) -C test clean
$(MAKE) -C demo clean
rm -f *.o *~ include/*~ *.so.* *.so .depend
rm -rf package

distclean: clean
rm -f VERSION changelog

ifneq "$(MAKECMDGOALS)" "clean"
.depend: $(CFILES)
@$(CC) -MG -MM $(CFLAGS) $(CFILES) >$@
@$(CC) -MG -MM $(ALL_CFLAGS) $(CFILES) >$@
-include .depend
endif

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ Reset memory access stats. See `x86emu_reset_access_stats()`.

To build, simply run `make`. Install with `make install`.

The `LIBX86EMU_VERSION` flag should be used if libx86emu isn't being compiled in a git repository
(e.g. when compiling from release archive). For example, compilation and installation of the version
3.2 form a release archive should look like this:
```shell
make LIBX86EMU_VERSION=3.2
sudo make install LIBX86EMU_VERSION=3.2
```

Basically every new commit into the master branch of the repository will be auto-submitted
to all current SUSE products. No further action is needed except accepting the pull request.

Expand Down
40 changes: 40 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SHELL = /bin/sh
ARCH := $(shell uname -m)
ifneq ($(filter i386 i486 i586 i686, $(ARCH)),)
ARCH := i386
endif

ifdef LIBX86EMU_VERSION
VERSION := $(shell echo ${LIBX86EMU_VERSION} > VERSION; cat VERSION)
else
GIT2LOG := $(shell if [ -x ./git2log ] ; then echo ./git2log --update ; else echo true ; fi)
VERSION := $(shell $(GIT2LOG) --version VERSION ; cat VERSION)
endif
GITDEPS := $(shell [ -d .git ] && echo .git/HEAD .git/refs/heads .git/refs/tags)
BRANCH := $(shell [ -d .git ] && git branch | perl -ne 'print $$_ if s/^\*\s*//')
ARCHIVE_PREFIX := libx86emu-$(VERSION)

PREFIX ?= /usr/local
EXEC_PREFIX ?= $(PREFIX)
ifeq "$(ARCH)" "x86_64"
LIBDIR ?= $(EXEC_PREFIX)/lib64
else
LIBDIR ?= $(EXEC_PREFIX)/lib
endif
INCLUDEDIR ?= $(PREFIX)/include

MAJOR_VERSION := $(shell cut -d . -f 1 VERSION)

CC ?= gcc
CFLAGS ?= -g -O2 -Wall -fomit-frame-pointer
ALL_CFLAGS = -fPIC -fvisibility=hidden $(CFLAGS)

export CC CFLAGS ARCH

LIBX86 = libx86emu

CFILES = $(wildcard *.c)
OBJS = $(CFILES:.c=.o)

LIB_NAME = $(LIBX86).so.$(VERSION)
LIB_SONAME = $(LIBX86).so.$(MAJOR_VERSION)
5 changes: 3 additions & 2 deletions demo/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CC = gcc
CFLAGS = -g -Wall -fomit-frame-pointer -O2
SHELL = /bin/sh
CC ?= gcc
CFLAGS ?= -g -Wall -fomit-frame-pointer -O2

.PHONY: clean

Expand Down
6 changes: 3 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = gcc
CFLAGS = -g -Wall -fomit-frame-pointer -O2
LDFLAGS =
SHELL = /bin/sh
CC ?= gcc
CFLAGS ?= -g -Wall -fomit-frame-pointer -O2
TST_FILES = $(sort $(wildcard *.tst))
INIT_FILES = $(addsuffix .init,$(basename $(wildcard *.tst)))
RES_FILES = $(sort $(addsuffix .result,$(basename $(wildcard *.tst))))
Expand Down