Skip to content

Commit

Permalink
use arch names for binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Jan 3, 2025
1 parent d48d00c commit 773fc8c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
28 changes: 13 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ include cross.mk

# Daniel's target
all:
make TARGET=w libui_x86_64_win.a -j`nproc`
make TARGET=l libui_x86_64_gtk.so -j`nproc`
make ARCH=x86_64-w64-mingw32 libui_x86_64-w64-mingw32.a -j`nproc`
make ARCH=x86_64-linux-gnu libui_gtk3_x86_64-linux-gnu.so -j`nproc`
make ARCH=aarch64-linux-gnu libui_gtk3_aarch64-linux-gnu.so -j`nproc`
darling shell make TARGET=m libui_x86_64.dylib -j`nproc`

LIBUI_COMMON := $(patsubst %.c,%.o,$(wildcard common/*.c))
Expand All @@ -18,7 +19,7 @@ LIBUI_WIN := $(patsubst %.cpp,%.o,$(wildcard windows/*.cpp))
LIBUI_WIN := $(filter-out OLD_,$(LIBUI_WIN))

O_FILES := $(LIBUI_COMMON) $(LIBUI_WIN)
O_FILES := $(O_FILES:.o=.$(TARGET).o)
O_FILES := $(call convert_target,$(O_FILES))

# Yes, lots of libs required
LIBS := -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc
Expand All @@ -27,8 +28,8 @@ LIBS += -lstdc++ -lgcc -lpthread -lssp -lurlmon -luuid
CFLAGS += -Iwindows -fvisibility=hidden -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -Wno-unused-parameter -Wno-switch -D_UI_STATIC -Dlibui_EXPORTS
CXXFLAGS += -std=c++11 -Wnon-virtual-dtor

libui_x86_64_win.a: $(O_FILES)
x86_64-w64-mingw32-ar rsc libui_x86_64_win.a $(O_FILES)
libui_$(ARCH).a: $(O_FILES)
$(AR) rsc libui_$(ARCH).a $(O_FILES)

endif # ------------------------------

Expand All @@ -41,21 +42,18 @@ LIBUI_UNIX := $(filter-out %image.o,$(LIBUI_UNIX))
LIBUI_UNIX += extras/image/image.o

O_FILES := $(LIBUI_COMMON) $(LIBUI_UNIX)
O_FILES := $(O_FILES:.o=.$(TARGET).o)
O_FILES := $(call convert_target,$(O_FILES))

CFLAGS += $(shell pkg-config --cflags gtk+-3.0) -fPIC
LDFLAGS += $(shell pkg-config --libs gtk+-3.0)

libui_x86_64_gtk.so: $(O_FILES)
$(CC) -shared $(O_FILES) $(LDFLAGS) -o libui_x86_64_gtk.so
libui_gtk3_$(ARCH).so: $(O_FILES)
$(CC) -shared $(O_FILES) $(LDFLAGS) -o libui_gtk3_$(ARCH).so

ARCH := $(shell uname -m)
install: libui_x86_64_gtk.so
sudo rm -rf /usr/local/lib/$(ARCH)-linux-gnu/libui.so
sudo cp libui_x86_64_gtk.so /usr/local/lib/$(ARCH)-linux-gnu/libui.so
sudo rm -rf /usr/lib/libui.so
sudo cp libui_x86_64_gtk.so /usr/lib/libui.so
sudo cp include/ui.h /usr/include/ui.h
install: libui_gtk3_$(ARCH).so
cp -rf libui_gtk3_$(ARCH).so /usr/lib/$(ARCH)/libui.so
cp -rf include/ui.h /usr/include/$(ARCH)/ui.h

ex.out: libui.so example/main.o
$(CC) $(CFLAGS) example/main.o -L. -lui $(LDFLAGS) -o ex.out
Expand All @@ -69,7 +67,7 @@ LIBUI_DARWIN := $(patsubst %.m,%.o,$(wildcard darwin/*.m))
LIBUI_DARWIN := $(filter-out %OLD_table.o,$(LIBUI_DARWIN))

O_FILES := $(LIBUI_COMMON) $(LIBUI_DARWIN)
O_FILES := $(O_FILES:.o=.$(TARGET).o)
O_FILES := $(call convert_target,$(O_FILES))

LDFLAGS := -framework Foundation -framework Appkit -framework CoreText -framework CoreGraphics -Wl,-undefined,dynamic_lookup

Expand Down
59 changes: 35 additions & 24 deletions cross.mk
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
# Cross-compilation stubs for GNU make
# w: Windows
# l: Linux
# m: Mac
help:
@echo "valid values for TARGET: w, l, m"
_all: all

# Autoselect ARCH based on one letter TARGET
# ARCH will also be autoselected from TARGET if farther down
ifndef TARGET
$(warning TARGET not defined, assuming Linux)
TARGET := l
ifneq ($(findstring linux,$(ARCH)),)
TARGET := l
endif
ifneq ($(findstring mingw,$(ARCH)),)
TARGET := w
endif
ifndef TARGET
$(warning TARGET not defined, assuming Linux)
TARGET := l
endif
endif

ARCH := x86_64

ifeq ($(TARGET),w)
MINGW := $(ARCH)-w64-mingw32
CC := $(MINGW)-gcc
CPP := $(MINGW)-c++
CXX := $(MINGW)-c++
GPP := $(MINGW)-g++
ARCH ?= x86_64-w64-mingw32
LIB_DIR := /usr/$(ARCH)-w64-mingw32/lib
INC_DIR := /usr/$(ARCH)-w64-mingw32/include

LIBWPD_A := /usr/$(ARCH)-w64-mingw32/lib/libwpd.a
LIBLUA_A := /usr/$(ARCH)-w64-mingw32/lib/liblua.a
LIBUI_DLL := /usr/$(ARCH)-w64-mingw32/lib/libui_win64.dll
LIBUI_A := /usr/$(ARCH)-w64-mingw32/lib/libui.a
LIBWPD_A := /usr/$(ARCH)/lib/libwpd.a
LIBLUA_A := /usr/$(ARCH)/lib/liblua.a
LIBUI_DLL := /usr/$(ARCH)/lib/libui_win64.dll
LIBUI_A := /usr/$(ARCH)/lib/libui.a

WIN_LINK_ESSENTIALS += -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc -lssp -lurlmon -luuid -lws2_32

%.res: %.rc
$(MINGW)-windres $< -O coff -o $@
$(ARCH)-windres $< -O coff -o $@
endif

ifeq ($(TARGET),l)
ARCH ?= x86_64-linux-gnu
LIB_DIR := /usr/lib
INC_DIR := /usr/include

Expand All @@ -43,22 +44,32 @@ linuxdeploy --appdir=AppDir --executable=$1.out -d assets/$1.desktop -i assets/$
appimagetool AppDir
endef

linuxdeploy:
echo "Download from https://github.com/linuxdeploy/linuxdeploy/releases/"

endif

CC := $(ARCH)-gcc
CPP := $(ARCH)-c++
CXX := $(ARCH)-c++
GPP := $(ARCH)-g++
PKG_CONFIG := $(ARCH)-pkg-config
AR := $(ARCH)-ar

# Convert object list to $(TARGET).o
# eg: x.o a.o -> x.w.o a.w.o if $(TARGET) is w
define convert_target
$(patsubst %.o,%.$(TARGET).o,$1)
$(patsubst %.o,%.$(ARCH).o,$1)
endef

%.$(TARGET).o: %.c
%.$(ARCH).o: %.c
$(CC) -MMD -c $< $(CFLAGS) -o $@

%.$(TARGET).o: %.cpp
%.$(ARCH).o: %.cpp
$(CXX) -MMD -c $< $(CFLAGS) -o $@

%.$(TARGET).o: %.cxx
%.$(ARCH).o: %.cxx
$(CXX) -MMD -c $< $(CXXFLAGS) $(CFLAGS) -o $@

%.$(TARGET).o: %.S
%.$(ARCH).o: %.S
$(CC) -c $< $(CFLAGS) -o $@

0 comments on commit 773fc8c

Please sign in to comment.