From 87d53e5e7465842932b6e57686c0db198646cade Mon Sep 17 00:00:00 2001 From: maxcodehack Date: Wed, 6 Apr 2022 15:24:16 +0000 Subject: [PATCH] c/c++ samples refactoring git-svn-id: svn://kolibrios.org@9758 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/sdk/samples/cpp_hello/Makefile | 20 +++++++----------- contrib/sdk/samples/cpp_hello/hello.cpp | 11 +++------- .../hello/{Makefile.shared => Makefile} | 21 +++++++++---------- contrib/sdk/samples/hello/Makefile.static | 18 +++++++--------- contrib/sdk/samples/hello/hello.c | 11 ++++------ 5 files changed, 33 insertions(+), 48 deletions(-) rename contrib/sdk/samples/hello/{Makefile.shared => Makefile} (60%) mode change 100644 => 100755 diff --git a/contrib/sdk/samples/cpp_hello/Makefile b/contrib/sdk/samples/cpp_hello/Makefile index cb00100833..ab23095dc0 100755 --- a/contrib/sdk/samples/cpp_hello/Makefile +++ b/contrib/sdk/samples/cpp_hello/Makefile @@ -3,25 +3,21 @@ LD = kos32-ld SDK_DIR = $(abspath ../..) -LDFLAGS = -static -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds --image-base 0 - -CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -Wno-pointer-arith +CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -Wno-pointer-arith +LDFLAGS = -static -S -Tapp-dynamic.lds --image-base 0 INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I $(SDK_DIR)/sources/libstdc++-v3/include -LIBPATH = -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib +LIBPATH = -L $(SDK_DIR)/lib -SOURCES = hello.cpp \ - $(NULL) - -OBJECTS = $(patsubst %.cpp, %.o, $(SOURCES)) +SOURCES = hello.cpp +OBJECTS = $(patsubst %.cpp, %.o, $(SOURCES)) default: hello hello: $(OBJECTS) Makefile - $(LD) $(LDFLAGS) $(LIBPATH) --subsystem console -o hello.kex $(OBJECTS) -lstdc++ -lsupc++ -lgcc -lc.dll - strip -s hello.kex -o hello.kex - objcopy hello.kex -O binary - rm *.o + $(LD) $(LDFLAGS) $(LIBPATH) --subsystem console -o hello $(OBJECTS) -lstdc++ -lsupc++ -lgcc -lc.dll + strip -s hello -o hello + objcopy hello -O binary %.o : %.cpp Makefile $(SOURCES) $(CC) $(CFLAGS) $(INCLUDES) -o $@ $< diff --git a/contrib/sdk/samples/cpp_hello/hello.cpp b/contrib/sdk/samples/cpp_hello/hello.cpp index c684499184..a8c068c6d5 100755 --- a/contrib/sdk/samples/cpp_hello/hello.cpp +++ b/contrib/sdk/samples/cpp_hello/hello.cpp @@ -1,21 +1,16 @@ -// for 'cout' #include - -// for 'console.obj' functions -#include +#include // to load console.obj using namespace std; -int main() -{ - // load console.obj +int main() { load_console(); con_set_title("C++ Console.obj example"); - cout << "Press any key...\n"; con_getch(); cout << "Hello, KolibriOS!\n"; con_set_title("Hello"); + return 0; } diff --git a/contrib/sdk/samples/hello/Makefile.shared b/contrib/sdk/samples/hello/Makefile old mode 100644 new mode 100755 similarity index 60% rename from contrib/sdk/samples/hello/Makefile.shared rename to contrib/sdk/samples/hello/Makefile index 397c6f6ca2..05f65d0b9b --- a/contrib/sdk/samples/hello/Makefile.shared +++ b/contrib/sdk/samples/hello/Makefile @@ -1,26 +1,25 @@ +# dynamic linking + CC = kos32-gcc LD = kos32-ld -SDK_DIR:= $(abspath ../..) - -LDFLAGS = -static -S -Tapp-dynamic.lds --image-base 0 +SDK_DIR = $(abspath ../..) CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 +LDFLAGS = -static -S -Tapp-dynamic.lds --image-base 0 -INCLUDES= -I $(SDK_DIR)/sources/newlib/libc/include -LIBPATH:= -L $(SDK_DIR)/lib - -SOURCES = hello.c \ - $(NULL) - +INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include +LIBPATH = -L $(SDK_DIR)/lib +SOURCES = hello.c OBJECTS = $(patsubst %.c, %.o, $(SOURCES)) default: hello -hello: $(OBJECTS) Makefile.shared +hello: $(OBJECTS) Makefile $(LD) $(LDFLAGS) $(LIBPATH) -o hello $(OBJECTS) -lgcc -lc.dll + strip -s hello -o hello objcopy hello -O binary -%.o : %.c Makefile.shared $(SOURCES) +%.o : %.c Makefile $(SOURCES) $(CC) $(CFLAGS) $(INCLUDES) -o $@ $< diff --git a/contrib/sdk/samples/hello/Makefile.static b/contrib/sdk/samples/hello/Makefile.static index 5cda48b478..fb888568b2 100644 --- a/contrib/sdk/samples/hello/Makefile.static +++ b/contrib/sdk/samples/hello/Makefile.static @@ -1,25 +1,23 @@ +# static linking + CC = kos32-gcc LD = kos32-ld -SDK_DIR:= $(abspath ../..) - -LDFLAGS = -static -Tapp-static.lds +SDK_DIR = $(abspath ../..) CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 +LDFLAGS = -static -Tapp-static.lds -INCLUDES= -I $(SDK_DIR)/sources/newlib/libc/include -LIBPATH:= -L $(SDK_DIR)/lib - -SOURCES = hello.c \ - $(NULL) - +INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include +LIBPATH = -L $(SDK_DIR)/lib +SOURCES = hello.c OBJECTS = $(patsubst %.c, %.o, $(SOURCES)) default: hello hello: $(OBJECTS) Makefile.static - $(LD) $(LDFLAGS) $(LIBPATH) -Map hello.map -o hello $(OBJECTS) -lc -lgcc -lc + $(LD) $(LDFLAGS) $(LIBPATH) -o hello $(OBJECTS) -lc -lgcc -lc objcopy hello -O binary %.o : %.c Makefile.static $(SOURCES) diff --git a/contrib/sdk/samples/hello/hello.c b/contrib/sdk/samples/hello/hello.c index 7f2278e618..f5d62d7b99 100644 --- a/contrib/sdk/samples/hello/hello.c +++ b/contrib/sdk/samples/hello/hello.c @@ -1,9 +1,6 @@ #include -int main(int argc, char *argv[]) -{ - - printf("Hello, world!\n"); - - return 0; -}; +int main() { + printf("Hello, world!\n"); + return 0; +}