acrn-hypervisor/tools/acrn-crashlog/usercrash/Makefile
Geoffroy Van Cutsem 7f2a7d47dd Tools Makefiles: enhancement to keep source code tree clean
Running 'make' will leave 3 files in the source code tree that
are not cleaned by a subsequent 'make clean'. These are:
* tools/acrn-crashlog/acrnprobe/include/version.h
* tools/acrn-crashlog/usercrash/include/version.h
* tools/acrn-manager/acrn_mngr.o
(as reported by 'git status' after 'make')

This patch changes the location of these files so they are
created in the target build directory and hence properly
cleaned when running 'make clean'

Other minor changes to the Makefiles include:
* Remove BASEDIR by the built-in CURDIR variable
* Add .PHONY targets

Signed-off-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
2018-06-05 10:22:24 +08:00

78 lines
2.5 KiB
Makefile

MAJOR_VERSION=1
MINOR_VERSION=0
VERSION_H = $(BUILDDIR)/include/usercrash/version.h
.PHONY: all check_obj
all: $(VERSION_H) check_obj usercrash_s usercrash_c debugger
INCLUDE += -I $(CURDIR)/include/
INCLUDE += -I $(BUILDDIR)/include/usercrash
LIBS = -levent -lpthread $(EXTRA_LIBS)
usercrash_s: $(BUILDDIR)/usercrash/obj/protocol.o \
$(BUILDDIR)/usercrash/obj/server.o \
$(BUILDDIR)/common/obj/log_sys.o
$(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ $(LIBS)
usercrash_c: $(BUILDDIR)/usercrash/obj/protocol.o \
$(BUILDDIR)/usercrash/obj/client.o \
$(BUILDDIR)/usercrash/obj/crash_dump.o \
$(BUILDDIR)/common/obj/log_sys.o \
$(BUILDDIR)/common/obj/cmdutils.o \
$(BUILDDIR)/common/obj/fsutils.o \
$(BUILDDIR)/common/obj/strutils.o
$(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ $(LIBS)
debugger: $(BUILDDIR)/usercrash/obj/debugger.o \
$(BUILDDIR)/usercrash/obj/crash_dump.o \
$(BUILDDIR)/common/obj/log_sys.o \
$(BUILDDIR)/common/obj/cmdutils.o \
$(BUILDDIR)/common/obj/fsutils.o \
$(BUILDDIR)/common/obj/strutils.o
$(CC) -g $(CFLAGS) $(INCLUDE) $^ -o $(BUILDDIR)/usercrash/bin/$@ $(LIBS)
$(BUILDDIR)/usercrash/obj/%.o:%.c
$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
$(VERSION_H):
@if [ ! -d $(BUILDDIR)/include/usercrash ]; then \
mkdir -p $(BUILDDIR)/include/usercrash ; \
fi
touch $(VERSION_H)
@COMMIT=`git log -1 --pretty=format:%h . 2>/dev/null`;\
DIRTY=`git diff --name-only $(CURDIR)`;\
if [ -n "$$DIRTY" ];then PATCH="$$COMMIT-dirty";else PATCH="$$COMMIT";fi;\
TIME=`date "+%Y-%m-%d %H:%M:%S"`;\
cat $(CURDIR)/../license_header > $(VERSION_H);\
echo "#define UC_MAJOR_VERSION $(MAJOR_VERSION)" >> $(VERSION_H);\
echo "#define UC_MINOR_VERSION $(MINOR_VERSION)" >> $(VERSION_H);\
echo "#define UC_BUILD_VERSION "\""$$PATCH"\""" >> $(VERSION_H);\
echo "#define UC_BUILD_TIME "\""$$TIME"\""" >> $(VERSION_H);\
echo "#define UC_BUILD_USER "\""$(USER)"\""" >> $(VERSION_H)
check_obj:
@if [ ! -d $(BUILDDIR)/usercrash/bin ]; then \
mkdir -p $(BUILDDIR)/usercrash/bin ; \
fi
@if [ ! -d $(BUILDDIR)/usercrash/obj ]; then \
mkdir -p $(BUILDDIR)/usercrash/obj ; \
fi
.PHONY: clean
clean:
@echo "Clean objects and binaries"
@if [ -e $(VERSION_H) ]; then \
$(RM) -f $(VERSION_H); \
fi
@if [ -d $(BUILDDIR)/usercrash/obj ]; then \
find $(BUILDDIR)/usercrash/obj -name "*.o" -exec $(RM) {} \; 2>&1 || exit 0; \
fi
@if [ -d $(BUILDDIR)/usercrash/bin ]; then \
$(RM) -r $(BUILDDIR)/usercrash/bin ; \
fi
@if [ -d $(BUILDDIR)/usercrash/obj ]; then \
$(RM) -r $(BUILDDIR)/usercrash/obj ; \
fi