Skip to content

Commit 8337565

Browse files
committed
* refactor project tree
* use single makefile on both platforms
1 parent a19a2fa commit 8337565

32 files changed

+150
-93
lines changed

Makefile

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1-
SRC := reloc.c reloc_add_aarch64.c insn.h stringx.s strlen_linux.s vma.cpp vma.h
1+
# Elven Relativism top makefile for Linux/aarch64 and macOS/arm64
2+
3+
UNAME := $(shell uname)
4+
UNAME_M := $(shell uname -m)
25
TARGET := elvenrel
6+
SOURCE := reloc.c reloc_add_aarch64.c insn.h
37
CFLAGS += -std=gnu11 -Ofast -DNDEBUG -DPAGE_SIZE=$(shell getconf PAGE_SIZE) -fno-stack-protector -fPIC
48
CXXFLAGS += -std=c++11 -Ofast -fno-exceptions -fno-rtti -DNDEBUG -DPAGE_SIZE=$(shell getconf PAGE_SIZE) -fno-stack-protector -fPIC
9+
10+
ifeq ($(UNAME), Linux)
11+
12+
ifneq ($(UNAME_M), aarch64)
13+
$(error unsupported arch)
14+
endif
15+
16+
# Update state for linux/aarch64
17+
SOURCE += stringx.s strlen_linux.s vma.cpp vma.h
518
LDFLAGS += -lelf
6-
ASFLAGS += --strip-local-absolute
7-
# Optional test objects built by target ALL
8-
REL := test_text.o \
9-
test_rodata.o \
10-
test_data.o \
11-
test_bss.o \
12-
test_cross_0.o \
13-
test_cross_1.o \
14-
test_bounce.o \
15-
test_bounce_neon.o \
16-
test_bounce_neon_aosoa.o \
17-
test_bounce_neon_aosoa_bg.o \
18-
test_bounce_data_aosoa_alt_0.o \
19-
test_bounce_data_aosoa_alt_1.o \
20-
test_bounce_data_aosoa_alt_2.o \
21-
test_bounce_data_aosoa_alt_3.o
22-
23-
OBJ := $(addsuffix .o, $(basename $(filter %.s %.c %.cpp, $(SRC))))
19+
TEST_SUBDIR := test_linux
20+
21+
else ifeq ($(UNAME), Darwin)
22+
23+
ifneq ($(UNAME_M), arm64)
24+
$(error unsupported arch)
25+
endif
26+
27+
# Update state for macos/arm64
28+
CFLAGS += -I/opt/homebrew/include
29+
LDFLAGS += /opt/homebrew/lib/libelf.a
30+
TEST_SUBDIR := test_macos
31+
32+
else # unsupported os
33+
$(error unsupposrted os)
34+
endif
35+
36+
OBJ := $(addsuffix .o, $(basename $(filter %.s %.c %.cpp, $(SOURCE))))
2437

2538
$(TARGET): $(OBJ)
2639
$(CC) $^ $(LDFLAGS) -o $(TARGET)
@@ -31,19 +44,9 @@ reloc_add_aarch64.o: reloc_add_aarch64.c insn.h
3144

3245
vma.o: vma.cpp vma.h char_ptr_arr.h
3346

34-
test_bounce.o: test_bounce.s
35-
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^
36-
37-
test_bounce_neon.o: test_bounce_neon.s
38-
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^
39-
40-
test_bounce_neon_aosoa.o: test_bounce_neon_aosoa.s
41-
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^
42-
43-
test_bounce_neon_aosoa_bg.o: test_bounce_neon_aosoa_bg.s
44-
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^
45-
46-
all: $(TARGET) $(REL)
47+
all: $(TARGET)
48+
$(MAKE) -C $(TEST_SUBDIR) all
4749

4850
clean:
49-
rm -f $(TARGET) $(OBJ) $(REL)
51+
rm -f $(TARGET) $(OBJ)
52+
$(MAKE) -C $(TEST_SUBDIR) clean

Makefile.macos

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,27 @@ Files used, with or without modifications, from external repositories:
2424
linux.org/ arch/arm64/kernel/module.c -> reloc_add_aarch64.c
2525
linux.org/ arch/arm64/lib/strlen.S -> strlen_linux.s
2626

27-
## Building: linux
27+
## Building
2828

2929
$ make all
3030

31-
## Building: macos
31+
## Building with own assembler
3232

33-
$ make -f Makefile.macos all
33+
For instance, if you have `gas` on macos and prefer to use that:
34+
35+
$ make AS=full-path-to-gas all
36+
37+
Building `gas` itself from source:
38+
39+
$ git clone git://sourceware.org/git/binutils-gdb.git && cd binutils-gdb
40+
$ cd bfd
41+
$ ./configure --target=aarch64-linux-gnu && make && cd -
42+
$ cd libiberty
43+
$ ./configure --target=aarch64-linux-gnu && make && cd -
44+
$ cd opcodes
45+
$ ./configure --target=aarch64-linux-gnu && make && cd -
46+
$ cd gas
47+
$ ./configure --target=aarch64-linux-gnu && make && cd -
3448

3549
## Usage
3650

test_bounce_neon_aosoa.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

test_linux/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ASFLAGS += --strip-local-absolute
2+
REL := test_text.o \
3+
test_rodata.o \
4+
test_data.o \
5+
test_bss.o \
6+
test_cross_0.o \
7+
test_cross_1.o \
8+
test_bounce.o \
9+
test_bounce_neon.o \
10+
test_bounce_neon_aosoa.o \
11+
test_bounce_neon_aosoa_bg.o \
12+
test_bounce_data_aosoa_alt_0.o \
13+
test_bounce_data_aosoa_alt_1.o \
14+
test_bounce_data_aosoa_alt_2.o \
15+
test_bounce_data_aosoa_alt_3.o
16+
17+
test_bounce.o: test_bounce.s
18+
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^
19+
20+
test_bounce_neon.o: test_bounce_neon.s
21+
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^
22+
23+
test_bounce_neon_aosoa.o: test_bounce_neon_aosoa.s
24+
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^
25+
26+
test_bounce_neon_aosoa_bg.o: test_bounce_neon_aosoa_bg.s
27+
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^
28+
29+
all: $(REL)
30+
31+
clean:
32+
rm -f $(REL)
File renamed without changes.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/bin/bash
2+
BUILD=..
23

3-
make all
4+
make -C ${BUILD} all
45

56
# Hide term cursor before loading REL; nuke all VMAs from common libraries and
67
# the process heap VMA, before passing control to _start; restore term cursor
78
# upon termination
89

910
tput civis
10-
./elvenrel test_bounce.o --filter /lib/aarch64-linux-gnu --filter [heap]
11+
${BUILD}/elvenrel test_bounce.o --filter /lib/aarch64-linux-gnu --filter [heap]
1112
tput cnorm

0 commit comments

Comments
 (0)