Skip to content

Commit

Permalink
Improve build system
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Nov 28, 2024
1 parent a877cd6 commit 7ef03cb
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 79 deletions.
58 changes: 27 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
LIBUI_COMMON := $(patsubst %.c,%.o,$(wildcard common/*.c))
LIBUI_COMMON := $(filter-out %OLD_table.o,$(LIBUI_COMMON))
all:
make TARGET=w libui_win64.a -j`nproc`
make TARGET=l libui.so -j`nproc`
darling shell TARGET=m libui.dylib -j`nproc`

CFLAGS := -I. -Iinclude/ -g
include cross.mk

all:
echo "see Makefile"
LIBUI_COMMON := $(patsubst %.c,%.o,$(wildcard common/*.c))
LIBUI_COMMON := $(filter-out %OLD_table.o,$(LIBUI_COMMON))

ide/demo.h: ide/test.lua
cd ide && xxd -i test.lua > demo.h
ide/test.c: ide/demo.h
CFLAGS := -I. -Iinclude/ -g -Isubprojects/cmocka-1.1.5/include

ifeq ($(TARGET),w) # ++++++++++++++++++++++++++
LIBUI_COMMON += extras/favicon/win.o extras/scroll.o extras/win_init.o
include win.mk

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)

# Yes, lots of libs required
LIBS := -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lmsimg32 -lcomdlg32 -ld2d1 -ldwrite -lole32 -loleaut32 -loleacc
LIBS += -lstdc++ -lgcc -lpthread -lssp -lurlmon -luuid

CFLAGS += -Iwindows -fvisibility=hidden -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++11 -Wno-unused-parameter -Wno-switch -D_UI_STATIC -Dlibui_EXPORTS

libui_win64.a: $(O_FILES)
x86_64-w64-mingw32-ar rsc libui_win64.a $(O_FILES)

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

ifeq ($(TARGET),l) # ++++++++++++++++++++++++++
Expand Down Expand Up @@ -48,7 +63,7 @@ endif # ------------------------------------
ifeq ($(TARGET),m) # ++++++++++++++++++++++++++
LIBUI_COMMON += extras/favicon/darwin.o

LIBUI_DARWIN := $(patsubst %.m,%.o,$(wildcard $(LIBUI)/darwin/*.m))
LIBUI_DARWIN := $(patsubst %.m,%.o,$(wildcard darwin/*.m))
LIBUI_DARWIN := $(filter-out %OLD_table.o,$(LIBUI_DARWIN))

O_FILES := $(LIBUI_COMMON) $(LIBUI_DARWIN)
Expand All @@ -59,31 +74,12 @@ LDFLAGS := -framework Foundation -framework Appkit -framework CoreText -framewor
libui.dylib: $(O_FILES)
$(CC) -shared $(O_FILES) $(LDFLAGS) -o libui.dylib

define COMPILE
$(2).out: $(1) libui.dylib
$(CC) $(CFLAGS) $(1) -L. -lui -o $(2).out
endef

install: libui.dylib
cp libui.dylib /usr/local/lib
cp ui.h /usr/local/include

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

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

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

%.$(TARGET).o: %.cpp
$(CPP) -c $< $(CFLAGS) -o $@

clean:
make TARGET=l clean_
make TARGET=w clean_
make TARGET=m clean_

clean_:
$(RM) $(O_FILES) *.o *.exe *.out *.res *.so *.a build *.dylib example/*.out ide/*.o *.res *.dll
$(RM) `find windows unix darwin test examples -regex ".*\.\(o\|d\)"`
$(RM) *.o *.exe *.out *.so *.a build *.dylib example/*.out ide/*.o *.dll
$(RM) `find windows unix darwin test examples -regex ".*\.\(o\|d\|res\)"`
58 changes: 58 additions & 0 deletions cross.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Cross-compilation stubs for GNU make
# w: Windows
# l: Linux
# m: Mac
help:
@echo "valid values for TARGET: w, l, m"

ifndef TARGET
$(warning TARGET not defined, assuming Linux)
TARGET := l
endif

ARCH := x86_64

ifeq ($(TARGET),w)
MINGW := x86_64-w64-mingw32
CC := $(MINGW)-gcc
CPP := $(MINGW)-c++
AR := $(MINGW)-ar

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

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 $@
endif

ifeq ($(TARGET),l)
# Create appimages
# TODO: Link to linuxdeploy and appimagetool
define create_appimage
linuxdeploy --appdir=AppDir --executable=$1.out -d assets/$1.desktop -i assets/$1.png
appimagetool AppDir
endef

endif

# 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)
endef

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

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

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

%.$(TARGET).o: %.m
$(CC) -c $< $(CFLAGS) -o $@
12 changes: 12 additions & 0 deletions examples.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ide/demo.h: ide/test.lua
cd ide && xxd -i test.lua > demo.h
ide/test.c: ide/demo.h

TESTER_FILES := $(addprefix test/,drawtests.w.o images.w.o main.w.o menus.w.o page1.w.o page2.w.o page3.w.o page4.w.o page5.w.o page6.w.o page7.w.o page7a.w.o page7b.w.o page7c.w.o page11.w.o page12.w.o page13.w.o page14.w.o page15.w.o page16.w.o page17.w.o spaced.w.o)

tester.exe: $(TESTER_FILES) test/resources.res libui_win64.a
$(CC) -static $(TESTER_FILES) libui_win64.a test/resources.res $(LIBS) -o tester.exe

UNIT_FILES := $(patsubst %.c,%.$(TARGET).o,$(wildcard test/unit/*.c)) subprojects/cmocka-1.1.5/src/cmocka.w.o
unit.exe: $(UNIT_FILES) test/unit/resources.res libui_win64.a
$(CC) -static $(UNIT_FILES) libui_win64.a test/unit/resources.res $(LIBS) -o unit.exe
48 changes: 0 additions & 48 deletions win.mk

This file was deleted.

0 comments on commit 7ef03cb

Please sign in to comment.