replace wtih new build system

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@615 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-07 16:52:34 +00:00
parent bfdb585dcf
commit ca054c70dd
24 changed files with 218 additions and 250 deletions

View File

@@ -8,11 +8,11 @@ project(
include(CheckIncludeFiles)
option(OPENGL "Compile OpenGL widget or not" ON)
option(BUILD_OPENGL "Compile OpenGL widget or not" ON)
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
option(VULKAN "Compile Vulkan widget or not" OFF)
option(BUILD_VULKAN "Compile Vulkan widget or not" OFF)
else()
option(VULKAN "Compile Vulkan widget or not" ON)
option(BUILD_VULKAN "Compile Vulkan widget or not" ON)
endif()
option(CLASSIC "Use classic theme" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
@@ -26,11 +26,11 @@ file(
src/*.c src/cursor/*.c src/icon/*.c src/text.c src/widget/*.c src/math/*.c src/font/*.c src/dialog/*.c src/abstract/*.c external/*.c
)
if(NOT OPENGL)
if(NOT BUILD_OPENGL)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/opengl.c")
endif()
if(NOT VULKAN)
if(NOT BUILD_VULKAN)
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/widget/vulkan.c")
endif()
@@ -142,7 +142,7 @@ else()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND LIBRARIES dl)
endif()
if(VULKAN)
if(BUILD_VULKAN)
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
list(APPEND INCLUDE_DIRS /usr/pkg/include)
else()
@@ -174,7 +174,7 @@ target_link_libraries(
${LIBRARIES}
)
if(VULKAN)
if(BUILD_VULKAN)
check_include_files(vulkan/vk_enum_string_helper.h HAS_VK_ENUM_STRING_HELPER)
if(HAS_VK_ENUM_STRING_HELPER)
target_compile_definitions(

View File

@@ -1,103 +0,0 @@
# $Id$
PREFIX = /usr/local
VERBOSE =
USE_STB_IMAGE = 1
USE_STB_TRUETYPE = 0
USE_FREETYPE2 = 1
USE_FDLIBM = 0
CC = $(GCC)gcc
WARN = -Wall -Wextra -Wno-implicit-fallthrough -Wno-sign-compare
CFLAGS = -Iinclude
LDFLAGS =
LIBS =
ifeq ($(DEBUG),1)
CFLAGS += -g
else
CFLAGS += -O2
endif
L_CFLAGS = $(DEPINC) $(CFLAGS) -fPIC -D_MILSKO
L_LDFLAGS = $(LDFLAGS)
L_LIBS = $(LIBS)
L_OBJS = src/core.o src/default.o src/lowlevel.o src/error.o src/unicode.o src/color.o src/string.o src/text.o src/draw.o
L_OBJS += external/stb_ds.o external/stb_image.o external/stb_truetype.o
L_OBJS += src/widget/window.o src/widget/button.o src/widget/frame.o src/widget/menu.o src/widget/submenu.o src/widget/image.o src/widget/scrollbar.o src/widget/checkbox.o src/widget/label.o src/widget/entry.o src/widget/numberentry.o src/widget/viewport.o src/widget/listbox.o src/widget/progressbar.o src/widget/radiobox.o
L_OBJS += src/dialog/filechooser.o src/dialog/colorpicker.o src/dialog/messagebox.o
L_OBJS += src/abstract/directory.o src/abstract/time.o
L_OBJS += src/cursor/hidden.o src/cursor/default.o src/cursor/cross.o src/cursor/text.o
L_OBJS += src/icon/warning.o src/icon/note.o src/icon/info.o src/icon/news.o src/icon/error.o src/icon/file.o src/icon/directory.o src/icon/back.o src/icon/forward.o src/icon/up.o src/icon/down.o src/icon/left.o src/icon/right.o src/icon/computer.o src/icon/search.o
L_OBJS += src/font/font.o src/font/boldfont.o src/font/ttf.o src/font/boldttf.o
E_CFLAGS = $(CFLAGS)
E_LDFLAGS = $(LDFLAGS) -Lsrc -Wl,-rpath,./src
E_LIBS = $(LIBS) -lMw
EXAMPLES = examples/basic/example$(EXEC) examples/basic/rotate$(EXEC) examples/basic/image$(EXEC) examples/basic/scrollbar$(EXEC) examples/basic/checkbox$(EXEC) examples/basic/radiobox$(EXEC) examples/basic/messagebox$(EXEC) examples/basic/viewport$(EXEC) examples/basic/listbox$(EXEC) examples/basic/progressbar$(EXEC) examples/basic/colorpicker$(EXEC)
include mk/platform.mk
include mk/flags.mk
include mk/stb.mk
include mk/freetype2.mk
include mk/opengl.mk
include mk/vulkan.mk
.PHONY: all install format clean lib examples
all: lib examples
lib: src/$(LIB)Mw$(SO)
examples: $(EXAMPLES)
install: lib
mkdir -p $(PREFIX)/lib
mkdir -p $(PREFIX)/bin
mkdir -p $(PREFIX)/include
for i in src; do \
cp $$i/*.so $(PREFIX)/lib/ ; \
cp $$i/*.a $(PREFIX)/lib/ ; \
cp $$i/*.dll $(PREFIX)/bin/ ; \
done ; true
cp -rf include/Mw $(PREFIX)/include/
format:
@echo clang-format
clang-format --verbose -i `find src include examples tools "(" -name "*.c" -or -name "*.h" ")" -and -not -name "stb_*.h" -and -not -name "ttf.c" -and -not -name "boldttf.c" -and -not -name "font.c" -and -not -name "boldfont.c"`
@echo perltidy
perltidy -b -bext='/' --paren-tightness=2 `find tools -name "*.pl"`
clean:
rm -f */*.dll */*.so */*.lib */*.a */*.o */*/*.o external/*/src/*.o examples/*.exe examples/*/*.exe $(EXAMPLES)
$(VERBOSE).SILENT:
src/$(LIB)Mw$(SO): $(L_OBJS)
@echo LD $@
$(CC) $(L_LDFLAGS) $(SHARED) -o $@ $^ $(L_LIBS)
examples/gldemos/%$(EXEC): examples/gldemos/%.o src/$(LIB)Mw$(SO)
@echo LD $@
$(CC) $(E_LDFLAGS) -o $@ $< $(E_LIBS) $(GL)
examples/%$(EXEC): examples/%.o src/$(LIB)Mw$(SO)
@echo LD $@
$(CC) $(E_LDFLAGS) -o $@ $< $(E_LIBS)
src/%.o: src/%.c
@echo CC $@
$(CC) $(L_CFLAGS) $(WARN) -c -o $@ $<
external/%.o: external/%.c
@echo CC $@
$(CC) $(L_CFLAGS) -c -o $@ $<
examples/%.o: examples/%.c
@echo CC $@
$(CC) $(E_CFLAGS) $(WARN) -c -o $@ $<

82
Makefile.m4 Normal file
View File

@@ -0,0 +1,82 @@
dnl $Id$
include(m4/toplevel/rules.m4)dnl
dnl
new_object([src/*.c])dnl
dnl
new_object([src/icon/*.c])dnl
new_object([src/font/*.c])dnl
new_object([src/cursor/*.c])dnl
dnl
new_object([src/widget/button.c])dnl
new_object([src/widget/checkbox.c])dnl
new_object([src/widget/entry.c])dnl
new_object([src/widget/frame.c])dnl
new_object([src/widget/image.c])dnl
new_object([src/widget/label.c])dnl
new_object([src/widget/listbox.c])dnl
new_object([src/widget/menu.c])dnl
new_object([src/widget/numberentry.c])dnl
new_object([src/widget/progressbar.c])dnl
new_object([src/widget/radiobox.c])dnl
new_object([src/widget/scrollbar.c])dnl
new_object([src/widget/submenu.c])dnl
new_object([src/widget/viewport.c])dnl
new_object([src/widget/window.c])dnl
dnl
new_object([src/dialog/*.c])dnl
dnl
new_object([src/abstract/*.c])dnl
dnl
new_object([external/*.c])dnl
dnl
ifdef([target],[],[define([target],esyscmd([uname -s | xargs printf '%s']))])dnl
syscmd([test -f ]cf/target.m4)dnl
ifelse(sysval,[0],[include(cf/target.m4)],[errprint([M4 for your target (]cf/target.m4[) was not found, please make one
])m4exit(1)])dnl
dnl
include(m4/toplevel/options.m4)dnl
dnl
new_example([examples/basic/example])dnl
new_example([examples/basic/rotate])dnl
new_example([examples/basic/image])dnl
new_example([examples/basic/scrollbar])dnl
new_example([examples/basic/checkbox])dnl
new_example([examples/basic/radiobox])dnl
new_example([examples/basic/messagebox])dnl
new_example([examples/basic/viewport])dnl
new_example([examples/basic/listbox])dnl
new_example([examples/basic/progressbar])dnl
new_example([examples/basic/colorpicker])dnl
dnl
CC = cc
CFLAGS = cflags
LDFLAGS = ldflags
INCDIR = incdir
LIBDIR = libdir
LIBS = libs
MATH = math
SHARED = shared_flag
.PHONY: all clean distclean lib examples install
all: lib examples
pushdef([library])dnl
define([library],[src/library_prefix[]Mw[]library_suffix])dnl
lib: library
library: library_targets
$(CC) $(LDFLAGS) $(LIBDIR) $(SHARED) -o library library_targets $(LIBS)
print_library_targets()dnl
examples: examples_targets
print_examples_targets()dnl
popdef([library])dnl
distclean: clean
rm -f Makefile
clean:
rm -f examples_targets */*.o */*/*.o */*/*/*.o

3
cf/Darwin.m4 Normal file
View File

@@ -0,0 +1,3 @@
dnl $Id$
define([library_suffix],[.dylib])dnl
define([shared_flag],[-dynamiclib])dnl

4
cf/NetBSD.m4 Normal file
View File

@@ -0,0 +1,4 @@
dnl $Id$
add_incdir([-I/usr/X11R7/include -I/usr/pkg/include])dnl
add_libdir([-L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib])dnl
define([use_x11])dnl

7
cf/Windows.m4 Normal file
View File

@@ -0,0 +1,7 @@
dnl $Id$
define([executable_suffix],[.exe])dnl
define([library_prefix],[])dnl
define([library_suffix],[.dll])dnl
add_ldflag([-Wl,--out-implib,src/libMw.a -static-libgcc])dnl
define([math],[])dnl
define([use_gdi])dnl

8
configure vendored Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
FLAGS="-Duse_freetype2 -Duse_stb_image -Dbuild_opengl -Dbuild_vulkan"
if ! m4 $FLAGS Makefile.m4 > Makefile; then
echo "(M4 exited with non-zero status)"
rm -f Makefile
exit 1
fi

14
m4/options/backend.m4 Normal file
View File

@@ -0,0 +1,14 @@
dnl $Id$
ifdef([use_x11],[add_cflag([-DUSE_X11])dnl
add_lib([-lX11 -lXrender -lXcursor])dnl
new_object([src/backend/x11.c])dnl
define([gl_lib],[-lGL -lGLU])])dnl
dnl
ifdef([use_gdi],[add_cflag([-DUSE_GDI])dnl
add_lib([-lgdi32])dnl
new_object([src/backend/gdi.c])dnl
define([gl_lib],[-lopengl32 -lglu32])])dnl
dnl
ifdef([use_darwin],[add_cflag([-DUSE_DARWIN -DSTBI_NO_THREAD_LOCALS])dnl
new_object([src/backend/mac/*.c])dnl
define([gl_lib],[])])dnl

9
m4/options/opengl.m4 Normal file
View File

@@ -0,0 +1,9 @@
dnl $Id$
ifdef([build_opengl],[new_object([src/widget/opengl.c])dnl
new_example([examples/gldemos/boing],[],[],[gl_lib])dnl
new_example([examples/gldemos/clock],[],[],[gl_lib])dnl
new_example([examples/gldemos/cube],[],[],[gl_lib])dnl
new_example([examples/gldemos/gears],[],[],[gl_lib])dnl
new_example([examples/gldemos/triangle],[],[],[gl_lib])dnl
new_example([examples/gldemos/tripaint],[],[],[gl_lib])dnl
])dnl

4
m4/options/vulkan.m4 Normal file
View File

@@ -0,0 +1,4 @@
dnl $Id$
ifdef([build_vulkan],[new_object([src/widget/vulkan.c])dnl
new_example([examples/vkdemos/vulkan])dnl
])dnl

17
m4/toplevel/options.m4 Normal file
View File

@@ -0,0 +1,17 @@
dnl $Id$
include(m4/options/backend.m4)dnl
include(m4/options/opengl.m4)dnl
include(m4/options/vulkan.m4)dnl
dnl
ifdef([use_stb_image],[add_cflag([-DUSE_STB_IMAGE])],[new_object([external/libz/src/*.c])dnl
new_object([external/libjpeg/src/*.c])dnl
new_object([external/libpng/src/*.c])dnl
add_cflag([-Iexternal/libz/include])dnl
add_cflag([-Iexternal/libjpeg/include])dnl
add_cflag([-Iexternal/libpng/include])])dnl
dnl
ifdef([use_stb_truetype],[add_cflag([-DUSE_STB_TRUETYPE])])dnl
dnl
ifdef([use_freetype2],[add_cflag([-DUSE_FREETYPE2])dnl
ifdef([cross_build],[],[add_cflag(esyscmd([pkg-config --cflags freetype2 | xargs printf '%s ']))dnl
add_lib(esyscmd([pkg-config --libs freetype2 | xargs printf '%s ']))])])dnl

51
m4/toplevel/rules.m4 Normal file
View File

@@ -0,0 +1,51 @@
dnl $Id$
changequote([,])dnl
include(m4/util/quote.m4)dnl
include(m4/util/arg.m4)dnl
include(m4/util/foreach.m4)dnl
include(m4/util/comma.m4)dnl
include(m4/util/default.m4)dnl
dnl
default_define([cc],[gcc])dnl
default_define([cflags],[-D_MILSKO])dnl
default_define([incdir],[-I include])dnl
default_define([ldflags],[])dnl
default_define([libdir],[])dnl
default_define([libs],[])dnl
default_define([math],[-lm])dnl
default_define([shared_flag],[-shared])dnl
dnl
define([object_suffix],[.o])dnl
define([library_prefix],[lib])dnl
define([library_suffix],[.so])dnl
define([executable_suffix],[])dnl
dnl
define([library_targets],[])dnl
define([library_objects],[])dnl
define([new_object],[pushdef([source])define([source],patsubst(patsubst(patsubst(esyscmd([ls -d $1]),[\..+$],object_suffix),[
],[ ]),[ $],[]))define([library_targets],ifelse(library_targets,[],[source],[library_targets source]))popdef([source])])dnl
define([print_library_targets],[foreach(x,space_to_comma(library_targets),[pushdef([source])define([source],[patsubst(x,[\]object_suffix[$],[.c])])dnl
x: source
$(CC) -c -fPIC $(INCDIR) $(CFLAGS) -o x source
popdef([source])])])dnl
dnl
define([examples_targets],[])dnl
define([new_example],[define($1[]_cflag,[$2])dnl
define($1[]_ldflag,[$3])dnl
define($1[]_lib,[$4])dnl
define([examples_targets],ifelse(examples_targets,[],[$1[]executable_suffix],[examples_targets $1[]executable_suffix]))])dnl
define([print_examples_targets],[foreach(x,space_to_comma(examples_targets),[pushdef(base)dnl
define([base],patsubst(x,[\..+$],[]))dnl
x: base[]object_suffix library
$(CC) -L src -Wl,-R./src $(LIBDIR) indir(base[]_ldflag) -o x base[]object_suffix -lMw $(MATH) indir(base[]_lib)
base[]object_suffix: base.c
$(CC) -c $(INCDIR) -o base[]object_suffix indir(base[]_cflag) base.c
popdef([base])])])dnl
dnl
define([add_incdir],[define([incdir],quote(incdir) [$*])])dnl
define([add_cflag],[define([cflags],quote(cflags) [$*])])dnl
define([add_libdir],[define([libdir],quote(libdir) [$*])])dnl
define([add_ldflag],[define([ldflags],quote(ldflags) [$*])])dnl
define([add_lib],[define([libs],quote(libs) [$*])])dnl
dnl

2
m4/util/arg.m4 Normal file
View File

@@ -0,0 +1,2 @@
dnl $Id$
define([arg1],[$1])dnl

3
m4/util/comma.m4 Normal file
View File

@@ -0,0 +1,3 @@
dnl $Id$
define([space_to_comma],[_space_to_comma(patsubst([$*],[ ],[,]))])dnl
define([_space_to_comma],[ifelse([$#],[0],[],[$#],[1],[$1],[$1[,]_space_to_comma(shift($@))])])dnl

2
m4/util/default.m4 Normal file
View File

@@ -0,0 +1,2 @@
dnl $Id$
define([default_define],[ifdef([$1],[],[define([$1],[$2])])])dnl

3
m4/util/foreach.m4 Normal file
View File

@@ -0,0 +1,3 @@
dnl $Id$
define([foreach],[pushdef([$1])_foreach($@)popdef([$1])])dnl
define([_foreach],[ifelse(quote($2),[],[],[define([$1],[arg1($2)])$3[]_foreach([$1],[shift($2)],[$3])])])dnl

2
m4/util/quote.m4 Normal file
View File

@@ -0,0 +1,2 @@
dnl $Id$
define([quote],[ifelse([$#],[0],[],[[$*]])])dnl

View File

@@ -1,42 +0,0 @@
# $Id$
# Standard gcc accepts this but we have to override this for Apple's gcc.
SHARED = -shared
ifeq ($(UNIX),1)
L_CFLAGS += -DUSE_X11
L_OBJS += src/backend/x11.o
L_LIBS += -lm -lX11 -lXrender -lXcursor
GL = -lGL -lGLU
E_LIBS += -lm
LIB = lib
SO = .so
EXEC =
endif
ifeq ($(WINDOWS),1)
L_CFLAGS += -DUSE_GDI
L_LDFLAGS += -Wl,--out-implib,src/libMw.a -static-libgcc
L_OBJS += src/backend/gdi.o
L_LIBS += -lgdi32
GL = -lopengl32 -lglu32
LIB =
SO = .dll
EXEC = .exe
endif
ifeq ($(DARWIN),1)
L_CFLAGS += -DSTBI_NO_THREAD_LOCALS -DUSE_DARWIN
L_OBJS += src/backend/mac/mac.o src/backend/mac/carbon.o
LIB = lib
SO = .dylib
EXEC =
SHARED = -dynamiclib
endif

View File

@@ -1,10 +0,0 @@
# $Id$
ifeq ($(USE_FREETYPE2),1)
L_CFLAGS += -DUSE_FREETYPE2
ifneq ($(CROSS),1)
L_CFLAGS += $(shell pkg-config --cflags freetype2)
L_LIBS += $(shell pkg-config --libs freetype2)
endif
endif

View File

@@ -1,2 +0,0 @@
# $Id$
L_OBJS += src/math/default.o src/math/math.o src/math/mmx.o

View File

@@ -1,7 +0,0 @@
# $Id$
ifeq ($(OPENGL),1)
L_OBJS += src/widget/opengl.o
EXAMPLES += examples/gldemos/clock$(EXEC) examples/gldemos/triangle$(EXEC) examples/gldemos/gears$(EXEC) examples/gldemos/boing$(EXEC) examples/gldemos/cube$(EXEC) examples/gldemos/tripaint$(EXEC)
endif

View File

@@ -1,51 +0,0 @@
# $Id$
ifeq ($(TARGET),)
TARGET = $(shell uname -s)
endif
ifneq ($(TARGET),$(shell uname -s))
CROSS = 1
endif
FOUND_PLATFORM = 0
ifeq ($(TARGET),NetBSD)
CFLAGS += -I/usr/X11R7/include -I/usr/pkg/include
LDFLAGS += -L/usr/X11R7/lib -L/usr/pkg/lib -Wl,-R/usr/X11R7/lib -Wl,-R/usr/pkg/lib
UNIX = 1
OPENGL = 1
VULKAN = 1
FOUND_PLATFORM = 1
endif
ifeq ($(TARGET),Linux)
L_LIBS += -ldl
UNIX = 1
OPENGL = 1
VULKAN = 1
FOUND_PLATFORM = 1
endif
ifeq ($(TARGET),Windows)
WINDOWS = 1
OPENGL = 1
VULKAN = 1
FOUND_PLATFORM = 1
endif
ifeq ($(TARGET),SunOS)
UNIX = 1
L_LIBS += -lsocket -lnsl
OPENGL = 1
FOUND_PLATFORM = 1
endif
ifeq ($(TARGET),Darwin)
DARWIN = 1
L_LIBS += -framework Carbon
FOUND_PLATFORM = 1
endif
ifeq ($(FOUND_PLATFORM),0)
$(error Add your platform definition)
endif

View File

@@ -1,11 +0,0 @@
# $Id$
ifeq ($(USE_STB_IMAGE),1)
L_CFLAGS += -DUSE_STB_IMAGE
else
include external/deps.mk
endif
ifeq ($(USE_STB_TRUETYPE),1)
L_CFLAGS += -DUSE_STB_TRUETYPE
endif

View File

@@ -1,17 +0,0 @@
# $Id$
ifeq ($(TARGET),NetBSD)
VULKAN_NO_STRING_HELPER = 1
endif
ifeq ($(VULKAN_NO_STRING_HELPER),1)
VK_STRING_HELPER_DEFINE =
else
VK_STRING_HELPER_DEFINE = -DHAS_VK_ENUM_STRING_HELPER
endif
CFLAGS += $(VK_STRING_HELPER_DEFINE)
ifeq ($(VULKAN),1)
L_OBJS += src/widget/vulkan.o
EXAMPLES += examples/vkdemos/vulkan$(EXEC)
endif