diff --git a/Makefile b/Makefile index 93c412b..3c3f36f 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,18 @@ -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 +include config.mk -CFILES = $(wildcard *.c) -OBJS = $(CFILES:.c=.o) - -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) @@ -40,35 +20,47 @@ 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 + if [ "$(OLDINCLUDEDIR)" -a "$(OLDINCLUDEDIR)" != "$(INCLUDEDIR)" ] ; then\ + install -m 644 -D include/x86emu.h $(DESTDIR)$(OLDINCLUDEDIR)/x86emu.h ;\ + fi + +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 - diff --git a/README.md b/README.md index 9fe8839..d3b010c 100644 --- a/README.md +++ b/README.md @@ -390,6 +390,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. diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..105a7f0 --- /dev/null +++ b/config.mk @@ -0,0 +1,41 @@ +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 +OLDINCLUDEDIR ?= /usr/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) diff --git a/demo/Makefile b/demo/Makefile index 8b6d52f..aa34cfb 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -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 diff --git a/test/Makefile b/test/Makefile index 21635f9..b9c0f07 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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))))