Skip to content

Commit

Permalink
Standardize makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
mimicji committed Oct 31, 2020
1 parent 5a7ce25 commit f402584
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
43 changes: 23 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
PROG := read_trace

PROJ_HOME := .
IDIR_PEEKABOO := $(addprefix $(PROJ_HOME)/,libpeekaboo)
LDIR_PEEKABOO := $(addprefix $(PROJ_HOME)/,libpeekaboo)
STATIC_LIB_TARGET := $(addprefix $(LDIR_PEEKABOO)/,libpeekaboo.a)
LIBOBJ := $(addprefix $(LDIR_PEEKABOO)/,libpeekaboo.a)

RM ?= rm -f

LIBS = -lpeekaboo -lm
CC = gcc
OPT = -O2
WARNINGS =
CFLAGS = $(WARNINGS) $(OPT) -I$(IDIR_PEEKABOO) -L$(LDIR_PEEKABOO)
LDLIBS = -lpeekaboo -lm
OPT = -O3
WARNINGS = #-Wall -Wextra
CFLAGS = $(OPT) $(WARNINGS) -I$(IDIR_PEEKABOO) -L$(LDIR_PEEKABOO)

# Solaris provides a non-Posix shell at /usr/bin
ifneq ($(wildcard /usr/xpg4/bin),)
Expand All @@ -18,32 +20,33 @@ else
endif

# We only support binutils 2.29 or later for disasm with libopcodes.
HAVE_GAS := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c "GNU assembler")
HAVE_GAS := $(shell $(CC) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c "GNU assembler")
ifneq ($(HAVE_GAS),0)
GAS229_OR_LATER := $(shell $(CXX) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c -E "GNU assembler version (2\.29|2\.[3-9]|[3-9])")
GAS229_OR_LATER := $(shell $(CC) -xc -c /dev/null -Wa,-v -o/dev/null 2>&1 | $(GREP) -c -E "GNU assembler version (2\.29|2\.[3-9]|[3-9])")
ifneq ($(GAS229_OR_LATER),0)
CFLAGS += -DASM
LIBS += -lopcodes
LDLIBS += -lopcodes
endif # -DASM
else
$(info WARNING: Binutils-dev not found. Disassembling in the trace reader is disabled.)
$(info )
endif # HAVE_GAS

all: $(PROG)
all: $(PROG) | binutils_warning

debug: CFLAGS += -DDEBUG -g
debug: is_debug = debug
debug: all

debug: CFLAGS += -DDEBUG -g
debug: $(PROG)
read_trace: read_trace.o $(LIBOBJ)
$(CC) -o $@ $(strip $(CFLAGS) $^ $(LDLIBS))

read_trace: binutils_warning | read_trace.o $(STATIC_LIB_TARGET)
$(CC) read_trace.o $(STATIC_LIB_TARGET) -o read_trace $(CFLAGS) $(LIBS)
%.o: %.c
$(CC) $(strip $(CFLAGS) -c) $<

$(STATIC_LIB_TARGET):
(cd $(LDIR_PEEKABOO) && $(MAKE))
$(LIBOBJ):
(cd $(LDIR_PEEKABOO) && $(strip $(MAKE) $(findstring debug,$(is_debug))))

.PHONY: clean
clean:
rm -f *.o *.a *.gch $(PROG)
$(RM) *.o *.a *.gch $(PROG)
(cd $(LDIR_PEEKABOO) && $(MAKE) clean)

.PHONY: binutils_warning
Expand Down
36 changes: 18 additions & 18 deletions libpeekaboo/Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
TARGET = libpeekaboo.a
CC = gcc
OPT = -O2
OBJLIB = libpeekaboo.a
OPT = -O3
WARNINGS =
ARCH_DIR = ./arch
IDIR = .
LDIR = .
CFLAGS = $(WARNINGS) $(OPT) -I$(IDIR) -L$(LDIR)

all: $(TARGET)
RM ?= rm -f

libpeekaboo.a: libpeekaboo.o aarch64.o amd64.o x86.o
ar rcs $(TARGET) libpeekaboo.o aarch64.o amd64.o x86.o
ranlib libpeekaboo.a
ARCH_SRC = $(wildcard $(ARCH_DIR)/*.c)
ARCH_OBJ = $(patsubst %.c,%.o,$(ARCH_SRC))
OBJ = $(patsubst %.c,%.o,$(wildcard *.c))

libpeekaboo.o: libpeekaboo.c libpeekaboo.h
$(CC) -c libpeekaboo.c libpeekaboo.h $(CFLAGS)
all: $(OBJLIB)

aarch64.o: $(ARCH_DIR)/aarch64.c $(ARCH_DIR)/aarch64.h
$(CC) -c $(ARCH_DIR)/aarch64.c $(ARCH_DIR)/aarch64.h $(CFLAGS)
debug: CFLAGS += -DDEBUG -g
debug: all

amd64.o: $(ARCH_DIR)/amd64.c $(ARCH_DIR)/amd64.h
$(CC) -c $(ARCH_DIR)/amd64.c $(ARCH_DIR)/amd64.h $(CFLAGS)
$(OBJLIB): $(OBJ) $(ARCH_OBJ)
ar rcs $(OBJLIB) $^
ranlib libpeekaboo.a

x86.o: $(ARCH_DIR)/x86.c $(ARCH_DIR)/x86.h
$(CC) -c $(ARCH_DIR)/x86.c $(ARCH_DIR)/x86.h $(CFLAGS)
%.o: %.c
$(CC) $(strip $(CFLAGS) -c) $<

.PHONY: clean
$(ARCH_DIR)/%.o : $(ARCH_DIR)/%.c
$(CC) $(strip $(CFLAGS) -c) -o $(patsubst %.c,%.o,$@) $<

.PHONY: clean
clean:
rm -f *.o *.a *.gch $(ARCH_DIR)/*.o $(ARCH_DIR)/*.gch

$(RM) *.o *.a *.gch $(ARCH_DIR)/*.o $(ARCH_DIR)/*.gch
2 changes: 1 addition & 1 deletion read_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int disassemble_raw(const enum ARCH arch, const bool big_endian, uint8_t *input_
#endif


inline bool print_filter(peekaboo_insn_t *insn, size_t insn_idx, const size_t num_insn)
bool print_filter(peekaboo_insn_t *insn, size_t insn_idx, const size_t num_insn)
{
/*
if (insn_idx == num_insn)
Expand Down

0 comments on commit f402584

Please sign in to comment.