Skip to content

Commit

Permalink
Merge pull request #8 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
1.2.1: Static library building in the Makefile
  • Loading branch information
AngheloAlf authored Sep 26, 2022
2 parents 4653029 + 079c2b6 commit 70426d5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 deletions.
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ ASAN ?= 0
EXPERIMENTAL ?= 0

CC := clang
AR := ar
IINC := -I include
CSTD := -std=c11
CFLAGS :=
LDFLAGS :=
CFLAGS := -fPIC
LDFLAGS := -Lbuild -lrabbitizer
WARNINGS := -Wall -Wextra -Wpedantic
# WARNINGS := -Wall -Wextra -Wpedantic -Wpadded
WARNINGS += -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=vla -Werror=switch -Werror=implicit-fallthrough -Werror=unused-function -Werror=unused-parameter -Werror=shadow
Expand Down Expand Up @@ -43,14 +44,19 @@ H_FILES := $(foreach dir,$(IINC),$(wildcard $(dir)/**/*.h))
O_FILES := $(foreach f,$(C_FILES:.c=.o),build/$f)
DEP_FILES := $(O_FILES:%.o=%.d)

STATIC_LIB := build/librabbitizer.a
DYNAMIC_LIB := build/librabbitizer.so

# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))


#### Main Targets ###

all: tests
all: static tests

static: $(STATIC_LIB)
dynamic: $(DYNAMIC_LIB)

clean:
$(RM) -rf build
Expand All @@ -73,8 +79,14 @@ tests: build/test.elf build/rsptest.elf build/r5900test.elf build/registersTrack

#### Various Recipes ####

build/%.elf: %.c $(O_FILES)
$(CC) -MMD $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS) $(LDFLAGS) -o $@ $^
build/%.elf: %.c | $(STATIC_LIB)
$(CC) -MMD $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS) -o $@ $^ $(LDFLAGS)

build/%.a: $(O_FILES)
$(AR) rcs $@ $^

build/%.so: $(O_FILES)
$(CC) -shared -o $@ $^

build/%.o: %.c
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
Expand Down
23 changes: 23 additions & 0 deletions include/common/RabbitizerVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */

#ifndef RABBITIZER_VERSION_H
#define RABBITIZER_VERSION_H

#include "Utils.h"

// Header version
#define RAB_VERSION_MAJOR 1
#define RAB_VERSION_MINOR 2
#define RAB_VERSION_PATCH 1

#define RAB_VERSION_STR RAB_STRINGIFY(RAB_VERSION_MAJOR) "." RAB_STRINGIFY(RAB_VERSION_MINOR) "." RAB_STRINGIFY(RAB_VERSION_PATCH)

// Compiled library version
extern const int RabVersion_Major;
extern const int RabVersion_Minor;
extern const int RabVersion_Patch;

extern const char RabVersion_Str[];

#endif
2 changes: 2 additions & 0 deletions include/common/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof((arr)[0]))

#define RAB_STRINGIFY(x) #x

#define MASK(v, w) ((v) & ((1 << (w)) - 1))

/*
Expand Down
24 changes: 24 additions & 0 deletions include/rabbitizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */

#ifndef RABBITIZER_H
#define RABBITIZER_H

#include "common/Utils.h"
#include "common/RabbitizerVersion.h"
#include "common/RabbitizerConfig.h"

#include "instructions/RabbitizerOperandType.h"
#include "instructions/RabbitizerInstrId.h"
#include "instructions/RabbitizerInstrSuffix.h"
#include "instructions/RabbitizerInstrDescriptor.h"
#include "instructions/RabbitizerRegister.h"
#include "instructions/RabbitizerInstruction.h"
#include "instructions/RabbitizerInstructionRsp.h"
#include "instructions/RabbitizerInstructionR5900.h"

#include "analysis/RabbitizerTrackedRegisterState.h"
#include "analysis/RabbitizerLoPairingInfo.h"
#include "analysis/RabbitizerRegistersTracker.h"

#endif
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

[metadata]
name = rabbitizer
version = 1.2.0
# Version should be synced with include/common/RabbitizerVersion.h
version = 1.2.1
author = Decompollaborate
license = MIT
description = MIPS instruction decoder
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900.c", "src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900_ProcessUniqueId.c",
"src/instructions/RabbitizerInstrDescriptor.c", "src/instructions/RabbitizerInstrId.c", "src/instructions/RabbitizerRegister.c", "src/instructions/RabbitizerInstrSuffix.c",
"src/analysis/RabbitizerTrackedRegisterState.c", "src/analysis/RabbitizerRegistersTracker.c", "src/analysis/RabbitizerLoPairingInfo.c",
"src/common/Utils.c", "src/common/RabbitizerConfig.c"],
"src/common/Utils.c", "src/common/RabbitizerVersion.c", "src/common/RabbitizerConfig.c"],
include_dirs=["include", "rabbitizer"],
extra_compile_args = [
"-std=c11",
Expand Down
10 changes: 10 additions & 0 deletions src/common/RabbitizerVersion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */

#include "common/RabbitizerVersion.h"

const int RabVersion_Major = RAB_VERSION_MAJOR;
const int RabVersion_Minor = RAB_VERSION_MINOR;
const int RabVersion_Patch = RAB_VERSION_PATCH;

const char RabVersion_Str[] = RAB_VERSION_STR;

0 comments on commit 70426d5

Please sign in to comment.