git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@636 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-08 02:14:29 +00:00
parent 159e2781ce
commit c53ded6223
26 changed files with 340 additions and 234 deletions

View File

@@ -12,11 +12,11 @@ proc run {project_name} {
RunCommand "make distclean"
}
if { "$target" == "Linux" } {
RunCommand "./configure --enable-opengl --enable-vulkan --without-vulkan-string-helper"
RunCommand "./Makefile.pl --enable-opengl --enable-vulkan --without-vulkan-string-helper"
} elseif { "$target" == "Win32" } {
RunCommand "./configure --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows CC=i686-w64-mingw32-gcc"
RunCommand "./Makefile.pl --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows CC=i686-w64-mingw32-gcc"
} elseif { "$target" == "Win64" } {
RunCommand "./configure --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows CC=x86_64-w64-mingw32-gcc"
RunCommand "./Makefile.pl --enable-opengl --enable-stb-truetype --disable-freetype2 --cross --target=Windows CC=x86_64-w64-mingw32-gcc"
}
RunCommand "make clean"
RunCommand "make -j4"

View File

@@ -1,90 +0,0 @@
dnl $Id$
dnl
dnl This is toplevel Makefile.m4.
dnl
dnl Notes:
dnl 1. add_cflag/add_ldflag/add_libs only affects Milsko library
dnl 2. add_incdir/add_libdir affects globally
dnl
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 ]m4/ostype/target.m4)dnl
ifelse(sysval,[0],[include(m4/ostype/target.m4)],[errprint([M4 for your target (]m4/ostype/target.m4[) was not found, please make one
])m4exit(1)dnl
])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 src/*.dll src/*.so src/*.a

153
Makefile.pl Executable file
View File

@@ -0,0 +1,153 @@
#!/usr/bin/env perl
# $Id$
our $target = `uname -s`;
$target =~ s/\r?\n$//;
foreach my $l (@ARGV){
if($l =~ /^--.+$/){
}elsif($l =~ /^(.+)=(.+)$/){
$ENV{$1} = $2;
}
}
our $cc = defined($ENV{CC}) ? $ENV{CC} : "gcc";
our $incdir = "-I include";
our $cflags = "-fPIC -D_MILSKO";
our $libdir = "";
our $ldflags = "";
our $math = "-lm";
our $shared = "-shared";
our $backend = "";
our $library_prefix = "lib";
our $library_suffix = ".so";
our $object_suffix = ".o";
our $executable_suffix = "";
our @library_targets = ();
our @examples_targets = ();
our %examples_libs = ();
our $cross = 0;
require("./pl/utils.pl");
param_set("stb-image", 1);
param_set("stb-truetype", 0);
param_set("freetype2", 1);
param_set("opengl", 0);
param_set("vulkan", 0);
param_set("vulkan-string-helper", 1);
my %features = (
"stb-image" => "use stb_image instead of libjpeg/libpng",
"stb-truetype" => "use stb_truetype",
"freetype2" => "use FreeType2",
"opengl" => "build OpenGL widget",
"vulkan" => "build Vulkan widget",
"vulkan-string-helper" => "use Vulkan string helper"
);
my @features_keys = ("1stb-image", "1stb-truetype", "1freetype2", "1opengl", "1vulkan", "2vulkan-string-helper");
foreach my $l (@ARGV){
if($l =~ /^--(with|enable)-(.+)$/){
param_set($2, 1);
}elsif($l =~ /^--(without|disable)-(.+)$/){
param_set($2, 0);
}elsif($l =~ /^--target=(.+)$/){
$target = $1;
}elsif($l eq "--cross"){
$cross = 1;
}elsif(($l eq "-h") or ($l eq "--help")){
print("Milsko Toolkit Configuration Utility\n");
print("\n");
print("Usage: $0 [options]\n");
print("\n");
print("Options:\n");
print(" -h --help Display this help\n");
print(" --target=TARGET Specify target\n");
print(" --cross Indicate cross compilation\n");
print("\n");
print("Features:\n");
print(" --enable-FEATURE Use FEATURE\n");
print(" --with-FEATURE Use FEATURE\n");
print(" --disable-FEATURE Do not use FEATURE\n");
print(" --without-FEATURE Do not use FEATURE\n");
foreach my $l (@features_keys){
my $flag = ((substr($l, 0, 1) eq '1') ? (param_get(substr($l, 1)) ? "--disable-" : "--enable-") : (param_get(substr($l, 1)) ? "--without-" : "--with-")) . substr($l, 1);
my $do = param_get(substr($l, 1)) ? "Do not " : "";
my $feat = $features{substr($l, 1)};
if(not(param_get($l))){
$feat = uc(substr($feat, 0, 1)) . substr($feat, 1);
}
print(" $flag" . (" " x (32 - length($flag))) . "${do}${feat}\n");
}
exit(0);
}
}
if(-f "./pl/ostype/${target}.pl"){
require("./pl/ostype/${target}.pl");
}else{
print("Perl file (pl/ostype/${target}.pl) was not found for your target. Please add one.\n");
exit(1);
}
require("./pl/rules.pl");
print("Target: " . $target . "\n");
open(OUT, ">", "Makefile");
print(OUT "CC = ${cc}\n");
print(OUT "INCDIR = ${incdir}\n");
print(OUT "CFLAGS = ${cflags}\n");
print(OUT "LIBDIR = ${libdir}\n");
print(OUT "LDFLAGS = ${ldflags}\n");
print(OUT "LIBS = ${libs}\n");
print(OUT "MATH = ${math}\n");
print(OUT "SHARED = ${shared}\n");
print(OUT "\n");
print(OUT ".PHONY: all clean distclean lib examples\n");
print(OUT "\n");
print(OUT "all: lib examples\n");
print(OUT "\n");
print(OUT "lib: src/${library_prefix}Mw${library_suffix}\n");
print(OUT "\n");
print(OUT "src/${library_prefix}Mw${library_suffix}: " . join(" ", @library_targets) . "\n");
print(OUT " \$(CC) \$(SHARED) \$(LDFLAGS\) \$(LIBDIR) -o src/${library_prefix}Mw${library_suffix} " . join(" ", @library_targets) . " \$(LIBS)\n");
foreach my $l (@library_targets){
my $s = $l;
my $o = $object_suffix;
$o =~ s/\./\\\./g;
$s =~ s/$o$/.c/;
print(OUT "${l}: ${s}\n");
print(OUT " \$(CC) \$(CFLAGS\) \$\(INCDIR) -c -o ${l} ${s}\n");
}
print(OUT "\n");
print(OUT "\n");
print(OUT "examples: " . join(" ", @examples_targets) . "\n");
print(OUT "\n");
foreach my $l (@examples_targets){
my $libs = "";
my $s = $l;
my $o = $executable_suffix;
$o =~ s/\./\\\./g;
$s =~ s/$o$//;
if(defined($examples_libs{$l})){
$libs = $examples_libs{$l};
}
print(OUT "${l}: ${s}${object_suffix} src/${library_prefix}Mw${library_suffix}\n");
print(OUT " \$(CC) -L src -Wl,-R./src \$\(LIBDIR) -o ${l} ${s}${object_suffix} -lMw ${math} ${libs}\n");
print(OUT "${s}${object_suffix}: ${s}.c\n");
print(OUT " \$(CC) -c \$\(INCDIR) -o ${s}${object_suffix} ${s}.c -lMw ${math}\n");
}
print(OUT "\n");
print(OUT "clean:\n");
print(OUT " rm -f */*.o */*/*.o */*/*/*.o src/*.so src/*.dll src/*.a " . join(" ", @examples_targets) . "\n");
print(OUT "\n");
print(OUT "distclean: clean\n");
print(OUT " rm -f Makefile\n");
close(OUT);

View File

@@ -61,8 +61,8 @@ D. MinGW-w64/GCC/Clang
1) Determine if you need Vulkan and/or OpenGL.
2) Run `./configure'.
For help, run `./configure --help'.
2) Run `./Makefile.pl'.
For help, run `./Makefile.pl --help'.
3) Run `make'.

View File

@@ -1,17 +0,0 @@
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
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
dnl
ifdef([use_darwin],[add_cflag([-DUSE_DARWIN -DSTBI_NO_THREAD_LOCALS])dnl
new_object([src/backend/mac/*.c])dnl
define([gl_lib],[])dnl
])dnl

View File

@@ -1,2 +0,0 @@
dnl $Id$
ifdef([use_classic_theme],[add_cflag([-DMW_CLASSIC_THEME])])dnl

View File

@@ -1,9 +0,0 @@
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

View File

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

View File

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

View File

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

View File

@@ -1,4 +0,0 @@
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

View File

@@ -1,7 +0,0 @@
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

View File

@@ -1,20 +0,0 @@
dnl $Id$
include(m4/options/backend.m4)dnl
include(m4/options/opengl.m4)dnl
include(m4/options/vulkan.m4)dnl
include(m4/options/classic.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
dnl
ifdef([use_stb_truetype],[add_cflag([-DUSE_STB_TRUETYPE])])dnl
ifdef([use_freetype2],[add_cflag([-DUSE_FREETYPE2])dnl
ifdef([cross_build],[],[add_cflag(my_syscmd([pkg-config --cflags freetype2 | xargs printf '%s ']))dnl
add_lib(my_syscmd([pkg-config --libs freetype2 | xargs printf '%s ']))dnl
])dnl
])dnl

View File

@@ -1,52 +0,0 @@
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
include(m4/util/my_syscmd.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(my_syscmd([sh -c "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 $(CFLAGS) $(INCDIR) -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

View File

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

View File

@@ -1,3 +0,0 @@
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

View File

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

View File

@@ -1,3 +0,0 @@
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

View File

@@ -1,3 +0,0 @@
dnl $Id$
define([my_syscmd],[syscmd([$* > my_syscmd_out.out])dnl
include(my_syscmd_out.out)[]syscmd([sh -c "rm -f my_syscmd_out.out"])])dnl

View File

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

4
pl/ostype/Linux.pl Normal file
View File

@@ -0,0 +1,4 @@
# $Id$
use_backend("x11");
1;

6
pl/ostype/NetBSD.pl Normal file
View File

@@ -0,0 +1,6 @@
# $Id$
add_incdir("-I/usr/X11R7/include -I/usr/pkg/include");
add_libdir("-L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib -L/usr/pkg/lib -Wl,-R/usr/pkg/lib");
use_backend("x11");
1;

9
pl/ostype/Windows.pl Normal file
View File

@@ -0,0 +1,9 @@
# $Id$
$library_prefix = "";
$library_suffix = ".dll";
$executable_suffix = ".exe";
$math = "";
add_ldflags("-Wl,--out-implib,src/libMw.a -static-libgcc");
use_backend("gdi");
1;

92
pl/rules.pl Normal file
View File

@@ -0,0 +1,92 @@
# $Id$
new_object("src/*.c");
my $gl_libs = "";
if($backend eq "x11"){
add_cflags("-DUSE_X11");
new_object("src/backend/x11.c");
add_libs("-lX11 -lXrender -lXcursor");
$gl_libs = "-lGL -lGLU";
}elsif($backend eq "gdi"){
add_cflags("-DUSE_GDI");
new_object("src/backend/gdi.c");
add_libs("-lgdi32");
$gl_libs = "-lopengl32 -lglu32";
}
if(param_get("stb-image")){
add_cflags("-DUSE_STB_IMAGE");
}
if(param_get("stb-truetype")){
add_cflags("-DUSE_STB_TRUETYPE");
}
if(param_get("freetype2")){
add_cflags("-DUSE_FREETYPE2");
if(not($cross)){
add_cflags(`pkg-config --cflags freetype2`);
add_libs(`pkg-config --libs freetype2`);
}
}
new_object("src/icon/*.c");
new_object("src/font/*.c");
new_object("src/cursor/*.c");
new_object("src/widget/button.c");
new_object("src/widget/checkbox.c");
new_object("src/widget/entry.c");
new_object("src/widget/frame.c");
new_object("src/widget/image.c");
new_object("src/widget/label.c");
new_object("src/widget/listbox.c");
new_object("src/widget/menu.c");
new_object("src/widget/numberentry.c");
new_object("src/widget/progressbar.c");
new_object("src/widget/radiobox.c");
new_object("src/widget/scrollbar.c");
new_object("src/widget/submenu.c");
new_object("src/widget/viewport.c");
new_object("src/widget/window.c");
if(param_get("opengl")){
new_object("src/widget/opengl.c");
}
if(param_get("vulkan")){
new_object("src/widget/vulkan.c");
}
new_object("src/dialog/*.c");
new_object("src/abstract/*.c");
new_object("external/*.c");
new_example("examples/basic/example");
new_example("examples/basic/rotate");
new_example("examples/basic/image");
new_example("examples/basic/scrollbar");
new_example("examples/basic/checkbox");
new_example("examples/basic/radiobox");
new_example("examples/basic/messagebox");
new_example("examples/basic/viewport");
new_example("examples/basic/listbox");
new_example("examples/basic/progressbar");
new_example("examples/basic/colorpicker");
if(param_get("opengl")){
new_example("examples/gldemos/boing", $gl_libs);
new_example("examples/gldemos/clock", $gl_libs);
new_example("examples/gldemos/cube", $gl_libs);
new_example("examples/gldemos/gears", $gl_libs);
new_example("examples/gldemos/triangle", $gl_libs);
new_example("examples/gldemos/tripaint", $gl_libs);
}
if(param_get("vulkan")){
new_example("examples/vkdemos/vulkan");
}
1;

69
pl/utils.pl Normal file
View File

@@ -0,0 +1,69 @@
# $Id$
sub add_incdir {
my $input = $_[0];
$input =~ s/\r?\n/ /g;
$incdir = "${incdir} ${input}";
}
sub add_cflags {
my $input = $_[0];
$input =~ s/\r?\n/ /g;
$cflags = "${cflags} ${input}";
}
sub add_libdir {
my $input = $_[0];
$input =~ s/\r?\n/ /g;
$libdir = "${libdir} ${input}";
}
sub add_ldflags {
my $input = $_[0];
$input =~ s/\r?\n/ /g;
$ldflags = "${ldflags} ${input}";
}
sub add_libs {
my $input = $_[0];
$input =~ s/\r?\n/ /g;
$libs = "${libs} ${input}";
}
sub new_example {
if(@_ == 2){
$examples_libs{"$_[0]${executable_suffix}"} = $_[1];
}
push(@examples_targets, "${_[0]}${executable_suffix}");
}
sub new_object {
my @l = glob($_[0]);
foreach my $e (@l){
$e =~ s/\.c$/$object_suffix/;
push(@library_targets, $e);
}
}
sub use_backend {
$backend = $_[0];
}
our %params = ();
sub param_set {
$params{$_[0]} = $_[1];
}
sub param_get {
if(not(defined($params{$_[0]}))){
return 0;
}else{
return $params{$_[0]};
}
}
1;

View File

@@ -107,8 +107,8 @@ l("1) Run `wmake -f WatMakefile'.");
h("D. MinGW-w64/GCC/Clang");
l("1) Determine if you need Vulkan and/or OpenGL.");
l("");
l("2) Run `./configure'.");
l(" For help, run `./configure --help'.");
l("2) Run `./Makefile.pl'.");
l(" For help, run `./Makefile.pl --help'.");
l("");
l("3) Run `make'.");
l("");