Skip to content

Commit

Permalink
Cleanup build system and directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Mar 26, 2014
1 parent 6fc5bde commit 4312a92
Show file tree
Hide file tree
Showing 30 changed files with 315 additions and 163 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,4 @@
*.o *.o
*.so
cscope.out cscope.out
tags tags
out out
45 changes: 45 additions & 0 deletions config.mk
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,45 @@
# Latehooks (experimental)
LATEHOOKS ?= 1

# Debug build (logging + debug symbols)
DEBUG ?= 0

# Destination directory when installing (used for packaging)
DESTDIR ?= /

# Destination prefix when installing
PREFIX ?= /usr

# Target platform
PLATFORM ?= harmattan

# Set to 1 for verbose compile output
V ?= 0

# Default linker flags
LDFLAGS += -fPIC -pthread -ldl -lz -lpng -ljpeg


ifeq ($(LATEHOOKS),1)
CFLAGS += -DAPKENV_LATEHOOKS
endif

ifeq ($(DEBUG),1)
CFLAGS += -g -Wall -DLINKER_DEBUG=1 -DAPKENV_DEBUG -Wformat=0
else
CFLAGS += -O2 -DLINKER_DEBUG=0
endif

ifeq ($(V),1)
SILENTMSG := @true
SILENTCMD :=
else
SILENTMSG := @echo
SILENTCMD := @
endif


# Expose some makefile variables as C macros
CFLAGS += -DAPKENV_PREFIX=\"$(PREFIX)\"
CFLAGS += -DAPKENV_TARGET=\"$(TARGET)\"
CFLAGS += -DAPKENV_PLATFORM=\"$(PLATFORM)\"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 6 additions & 13 deletions linker/linker.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -610,21 +610,14 @@ static void dump(soinfo *si)


#define SOPATH_MAX 8 #define SOPATH_MAX 8


#if defined(PANDORA)
static const char *sopaths[SOPATH_MAX + 1] = {
"./vendor/lib",
"./system/lib",
"./lib",
};
#else
static const char *sopaths[SOPATH_MAX + 1] = { static const char *sopaths[SOPATH_MAX + 1] = {
"/vendor/lib", "/vendor/lib",
"/system/lib", "/system/lib",
"/opt/apkenv/bionic/", APKENV_PREFIX "/lib/" APKENV_TARGET "/bionic/",
// Also allow local directory during development #ifdef APKENV_LOCAL_BIONIC_PATH
"./libs/", APKENV_LOCAL_BIONIC_PATH,
};
#endif #endif
};


int add_sopath(const char *path) int add_sopath(const char *path)
{ {
Expand Down Expand Up @@ -1755,7 +1748,7 @@ static int nullify_closed_stdio (void)
void wrap_function(void *sym_addr, char *sym_name, int is_thumb, soinfo *si) void wrap_function(void *sym_addr, char *sym_name, int is_thumb, soinfo *si)
{ {
void *hook = NULL; void *hook = NULL;
#ifdef LATEHOOKS #ifdef APKENV_LATEHOOKS
if((hook = get_hooked_symbol(sym_name, 0)) != NULL) if((hook = get_hooked_symbol(sym_name, 0)) != NULL)
{ {
// if we have a hook redirect the call to that by overwriting // if we have a hook redirect the call to that by overwriting
Expand Down Expand Up @@ -1788,7 +1781,7 @@ void wrap_function(void *sym_addr, char *sym_name, int is_thumb, soinfo *si)
} }
} }
else else
#endif /* LATEHOOKS */ #endif /* APKENV_LATEHOOKS */
// TODO: this will fail if the first 2 instructions do something pc related // TODO: this will fail if the first 2 instructions do something pc related
// (this DOES NOT happen very often) // (this DOES NOT happen very often)
if(sym_addr && !is_thumb) if(sym_addr && !is_thumb)
Expand Down
162 changes: 42 additions & 120 deletions makefile
Original file line number Original file line Diff line number Diff line change
@@ -1,141 +1,63 @@
TARGET := apkenv


# Android Gingerbread linker # Default target, make sure this is always first
LINKER_SOURCES=$(wildcard linker/*.c) all: $(TARGET) modules


# Compatibility wrappers and hooks # Build configuration
COMPAT_SOURCES=$(wildcard compat/*.c) include config.mk


# Library for getting files out of .apk files SOURCES := $(TARGET).c
APKLIB_SOURCES=$(wildcard apklib/*.c) SOURCES += $(wildcard linker/*.c)
SOURCES += $(wildcard compat/*.c)
SOURCES += $(wildcard apklib/*.c)
SOURCES += $(wildcard jni/*.c)
SOURCES += $(wildcard imagelib/*.c)
SOURCES += $(wildcard debug/*.c)
SOURCES += $(wildcard debug/wrappers/*.c)


# Our own JNI environment implementation # Platform-specific targets and configuration
JNIENV_SOURCES=$(wildcard jni/*.c) PLATFORM_INSTALL_TARGETS :=
include platform/$(PLATFORM).mk


# Support modules for specific applications OBJS := $(patsubst %.c,%.o,$(SOURCES))
MODULES_SOURCES=$(wildcard modules/*.c)

# JPEG and PNG loaders
IMAGELIB_SOURCES=$(wildcard imagelib/*.c)

# segfault catch
DEBUG_SOURCES=$(wildcard debug/*.c)

# debug wrappers
WRAPPER_SOURCES=$(wildcard debug/wrappers/*.c)

TARGET = apkenv

# we need objdump for getting a disassembly of the debug-wrappers
OBJDUMP ?= objdump

# enable latehooks
LATEHOOKS ?= 1

ifeq ($(LATEHOOKS),1)
CFLAGS += -DLATEHOOKS
endif

DESTDIR ?= /
PREFIX ?= /opt/$(TARGET)/
BIONIC_LIBS = $(wildcard libs/*.so)

SOURCES += $(TARGET).c
SOURCES += $(LINKER_SOURCES)
SOURCES += $(COMPAT_SOURCES)
SOURCES += $(APKLIB_SOURCES)
SOURCES += $(JNIENV_SOURCES)
SOURCES += $(IMAGELIB_SOURCES)
SOURCES += $(DEBUG_SOURCES)
SOURCES += $(WRAPPER_SOURCES)

PANDORA ?= 0
ifeq ($(PANDORA),1)
SOURCES += platform/pandora.c
else
SOURCES += platform/maemo.c
endif


OBJS = $(patsubst %.c,%.o,$(SOURCES)) # Support modules for specific applications
MODULES = $(patsubst modules/%.c,%.apkenv.so,$(MODULES_SOURCES)) MODULES_SOURCES := $(wildcard modules/*.c)

MODULES := $(patsubst modules/%.c,%.apkenv.so,$(MODULES_SOURCES))
LDFLAGS = -fPIC -ldl -lz -lSDL -lSDL_mixer -pthread -lpng -ljpeg

ifeq ($(PANDORA),1)
CFLAGS += -DPANDORA
LDFLAGS += -lrt
endif

# Selection of OpenGL ES version support (if any) to include
CFLAGS += -DAPKENV_GLES
LDFLAGS += -lGLES_CM
CFLAGS += -DAPKENV_GLES2
LDFLAGS += -lGLESv2 -lEGL

FREMANTLE ?= 0
ifeq ($(FREMANTLE),1)
CFLAGS += -DFREMANTLE
LDFLAGS += -lSDL_gles
endif


DEBUG ?= 0 modules: $(MODULES)
ifeq ($(DEBUG),1)
CFLAGS += -g -Wall -DLINKER_DEBUG=1 -DAPKENV_DEBUG -Wformat=0
else
CFLAGS += -O2 -DLINKER_DEBUG=0
endif


all: $(TARGET) $(MODULES) $(TARGET): $(OBJS)
$(SILENTMSG) -e "\tLINK\t$@"
$(SILENTCMD)$(CC) $(LDFLAGS) $(OBJS) -o $@


debug/wrappers/%_thumb.o: debug/wrappers/%_thumb.c debug/wrappers/%_thumb.o: debug/wrappers/%_thumb.c
@echo -e "\tCC (TH)\t$@" $(SILENTMSG) -e "\tCC (TH)\t$@"
@$(CC) -mthumb -O0 -c -o $@ $< $(SILENTCMD)$(CC) -mthumb -O0 -c -o $@ $<


debug/wrappers/%_arm.o: debug/wrappers/%_arm.c debug/wrappers/%_arm.o: debug/wrappers/%_arm.c
@echo -e "\tCC\t$@" $(SILENTMSG) -e "\tCC\t$@"
@$(CC) -marm -O0 -c -o $@ $< $(SILENTCMD)$(CC) -marm -O0 -c -o $@ $<


%.o: %.c %.o: %.c
@echo -e "\tCC\t$@" $(SILENTMSG) -e "\tCC\t$@"
@$(CC) $(CFLAGS) -c -o $@ $< $(SILENTCMD)$(CC) $(CFLAGS) -c -o $@ $<

$(TARGET): $(OBJS)
@echo -e "\tLINK\t$@"
@$(CC) $(LDFLAGS) $(OBJS) -o $@


%.apkenv.so: modules/%.c %.apkenv.so: modules/%.c
@echo -e "\tMOD\t$@" $(SILENTMSG) -e "\tMOD\t$@"
@$(CC) -fPIC -shared $(CFLAGS) -o $@ $< $(SILENTCMD)$(CC) -fPIC -shared $(CFLAGS) -o $@ $<


strip: install: $(TARGET) $(MODULES) $(PLATFORM_INSTALL_TARGETS)
@echo -e "\tSTRIP" $(SILENTMSG) -e "\tINSTALL\t$(TARGET)"
@strip $(TARGET) $(MODULES) $(SILENTCMD)mkdir -p $(DESTDIR)$(PREFIX)/bin

$(SILENTCMD)install -m755 $(TARGET) $(DESTDIR)$(PREFIX)/bin
install: $(TARGET) $(MODULES) $(SILENTMSG) -e "\tINSTALL\tMODULES"
@echo -e "\tMKDIR" $(SILENTCMD)mkdir -p $(DESTDIR)$(PREFIX)/lib/$(TARGET)/modules
@mkdir -p $(DESTDIR)$(PREFIX)/{modules,bionic} $(SILENTCMD)install -m644 $(MODULES) $(DESTDIR)$(PREFIX)/lib/$(TARGET)/modules
@mkdir -p $(DESTDIR)/usr/bin
@echo -e "\tINSTALL\t$(TARGET)"
@install -m755 $(TARGET) $(DESTDIR)/usr/bin
@echo -e "\tINSTALL\tMODULES"
@install -m644 $(MODULES) $(DESTDIR)$(PREFIX)/modules
ifneq ($(PANDORA),1)
@echo -e "\tINSTALL\tBIONIC"
@install -m644 $(BIONIC_LIBS) $(DESTDIR)$(PREFIX)/bionic
ifneq ($(FREMANTLE),1)
@echo -e "\tINSTALL\tHarmattan Resource Policy"
@install -d -m755 $(DESTDIR)/usr/share/policy/etc/syspart.conf.d
@install -m644 $(TARGET).conf $(DESTDIR)/usr/share/policy/etc/syspart.conf.d
endif
else
@echo -e "\tINSTALL\tlibs"
@mkdir -p $(DESTDIR)$(PREFIX)/system/lib
@install -m644 libs/pandora/system/lib/*.so $(DESTDIR)$(PREFIX)/system/lib/
endif


clean: clean:
@echo -e "\tCLEAN" $(SILENTMSG) -e "\tCLEAN"
@rm -rf $(TARGET) $(OBJS) $(MODULES) $(SILENTCMD)rm -rf $(TARGET) $(OBJS) $(MODULES)


.DEFAULT: all .DEFAULT: all
.PHONY: strip install clean .PHONY: all modules install clean

Loading

0 comments on commit 4312a92

Please sign in to comment.