From 7e1cb86da7f717bc47a69fbc6f52684e4da8dbb6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 22 Jun 2019 21:21:57 +0200 Subject: [PATCH] LibHTML: Make it possible to build LibHTML on the host. - "make" builds the normal Serenity libhtml.a - "make -f Makefile.host" builds a test program for the host machine. --- AK/Traits.h | 2 +- AK/kstdio.h | 1 + Kernel/kstdio.h | 4 +++ LibCore/CEventLoop.cpp | 20 +++++++-------- LibCore/CFile.cpp | 1 + LibCore/CIODevice.cpp | 1 + LibCore/CLock.h | 14 +++++++++++ LibCore/CObject.cpp | 1 + LibHTML/Makefile | 47 +++--------------------------------- LibHTML/Makefile.host | 20 +++++++++++++++ LibHTML/Makefile.shared | 45 ++++++++++++++++++++++++++++++++++ LibHTML/Parser/CSSParser.cpp | 1 - 12 files changed, 101 insertions(+), 56 deletions(-) create mode 100644 LibHTML/Makefile.host create mode 100644 LibHTML/Makefile.shared diff --git a/AK/Traits.h b/AK/Traits.h index c147fa3cbd3..f0ecb9ae2df 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -31,7 +31,7 @@ template struct Traits { static unsigned hash(const T* p) { - return int_hash((dword)p); + return int_hash((unsigned)(__PTRDIFF_TYPE__)p); } static void dump(const T* p) { kprintf("%p", p); } }; diff --git a/AK/kstdio.h b/AK/kstdio.h index 42cc39235e9..57a64acb7fb 100644 --- a/AK/kstdio.h +++ b/AK/kstdio.h @@ -5,4 +5,5 @@ #else #include #define kprintf printf +#define dbgprintf printf #endif diff --git a/Kernel/kstdio.h b/Kernel/kstdio.h index 00509e320cc..bca2bfc6242 100644 --- a/Kernel/kstdio.h +++ b/Kernel/kstdio.h @@ -9,3 +9,7 @@ int ksprintf(char* buf, const char* fmt, ...); #ifndef USERLAND # define printf dbgprintf #endif + +#ifndef __serenity__ +#define dbgprintf printf +#endif diff --git a/LibCore/CEventLoop.cpp b/LibCore/CEventLoop.cpp index 3bfe98893fa..e38c2b2154b 100644 --- a/LibCore/CEventLoop.cpp +++ b/LibCore/CEventLoop.cpp @@ -1,19 +1,19 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //#define CEVENTLOOP_DEBUG //#define DEFERRED_INVOKE_DEBUG diff --git a/LibCore/CFile.cpp b/LibCore/CFile.cpp index 335f54009ab..09d209d4b44 100644 --- a/LibCore/CFile.cpp +++ b/LibCore/CFile.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/LibCore/CIODevice.cpp b/LibCore/CIODevice.cpp index ff46374d2dd..6e6c3076ec4 100644 --- a/LibCore/CIODevice.cpp +++ b/LibCore/CIODevice.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/LibCore/CLock.h b/LibCore/CLock.h index 02ab53fa827..add591037f1 100644 --- a/LibCore/CLock.h +++ b/LibCore/CLock.h @@ -1,5 +1,7 @@ #pragma once +#ifdef __serenity__ + #include #include #include @@ -109,3 +111,15 @@ private: T m_resource; CLock m_lock; }; + +#else + +class CLock { +public: + CLock() { } + ~CLock() { } +}; + +#define LOCKER(x) + +#endif diff --git a/LibCore/CObject.cpp b/LibCore/CObject.cpp index a5ea5e6977d..bbee4501dd8 100644 --- a/LibCore/CObject.cpp +++ b/LibCore/CObject.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/LibHTML/Makefile b/LibHTML/Makefile index bc3890a4987..fc58fe9cb66 100644 --- a/LibHTML/Makefile +++ b/LibHTML/Makefile @@ -1,58 +1,17 @@ include ../Makefile.common -LIBHTML_OBJS = \ - DOM/Node.o \ - DOM/ParentNode.o \ - DOM/Element.o \ - DOM/Document.o \ - DOM/Text.o \ - CSS/Selector.o \ - CSS/StyleSheet.o \ - CSS/StyleRule.o \ - CSS/StyleDeclaration.o \ - CSS/StyleValue.o \ - CSS/DefaultStyleSheetSource.o \ - Parser/HTMLParser.o \ - Parser/CSSParser.o \ - Layout/LayoutNode.o \ - Layout/LayoutText.o \ - Layout/LayoutBlock.o \ - Layout/LayoutInline.o \ - Layout/LayoutDocument.o \ - Layout/LayoutStyle.o \ - Frame.o \ - Dump.o - -GENERATED_SOURCES = \ - CSS/DefaultStyleSheetSource.cpp - -TEST_OBJS = test.o -TEST_PROGRAM = tho - -OBJS = $(LIBHTML_OBJS) $(TEST_OBJS) - LIBRARY = libhtml.a -DEFINES += -DUSERLAND -all: $(LIBRARY) $(TEST_PROGRAM) +all: $(LIBRARY) tho -CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSource.sh - @echo "GENERATE $@"; Scripts/GenerateStyleSheetSource.sh default_stylesheet_source $< > $@ +include Makefile.shared -$(TEST_PROGRAM): $(TEST_OBJS) $(LIBRARY) +tho: $(TEST_OBJS) $(LIBRARY) $(LD) -o $@ $(LDFLAGS) -L. $(TEST_OBJS) -lhtml -lgui -lcore -lc $(LIBRARY): $(LIBHTML_OBJS) @echo "LIB $@"; $(AR) rcs $@ $(LIBHTML_OBJS) -.cpp.o: - @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< - --include $(OBJS:%.o=%.d) - -clean: - @echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES) - install: $(LIBRARY) mkdir -p ../Root/usr/include/LibHTML # Copy headers diff --git a/LibHTML/Makefile.host b/LibHTML/Makefile.host new file mode 100644 index 00000000000..45e1616dd12 --- /dev/null +++ b/LibHTML/Makefile.host @@ -0,0 +1,20 @@ +all: tho + +CXXFLAGS = -W -Wall -O -g -I. -I../ -std=c++17 + +EXTRA_OBJS = \ + ../AK/StringImpl.o \ + ../AK/String.o \ + ../AK/StringBuilder.o \ + ../AK/StringView.o \ + ../LibCore/CEventLoop.o \ + ../LibCore/CObject.o \ + ../LibCore/CEvent.o \ + ../LibCore/CIODevice.o \ + ../LibCore/CFile.o + +include Makefile.shared + +tho: $(OBJS) + $(CXX) -o $@ $(LDFLAGS) $(OBJS) + diff --git a/LibHTML/Makefile.shared b/LibHTML/Makefile.shared new file mode 100644 index 00000000000..89340faef79 --- /dev/null +++ b/LibHTML/Makefile.shared @@ -0,0 +1,45 @@ +LIBHTML_OBJS = \ + DOM/Node.o \ + DOM/ParentNode.o \ + DOM/Element.o \ + DOM/Document.o \ + DOM/Text.o \ + CSS/Selector.o \ + CSS/StyleSheet.o \ + CSS/StyleRule.o \ + CSS/StyleDeclaration.o \ + CSS/StyleValue.o \ + CSS/DefaultStyleSheetSource.o \ + Parser/HTMLParser.o \ + Parser/CSSParser.o \ + Layout/LayoutNode.o \ + Layout/LayoutText.o \ + Layout/LayoutBlock.o \ + Layout/LayoutInline.o \ + Layout/LayoutDocument.o \ + Layout/LayoutStyle.o \ + Frame.o \ + Dump.o + +GENERATED_SOURCES = \ + CSS/DefaultStyleSheetSource.cpp + +TEST_OBJS = test.o +TEST_PROGRAM = tho + +OBJS = $(EXTRA_OBJS) $(LIBHTML_OBJS) $(TEST_OBJS) + +LIBRARY = libhtml.a +DEFINES += -DUSERLAND + +CSS/DefaultStyleSheetSource.cpp: CSS/Default.css Scripts/GenerateStyleSheetSource.sh + @echo "GENERATE $@"; Scripts/GenerateStyleSheetSource.sh default_stylesheet_source $< > $@ + +.cpp.o: + @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< + +-include $(OBJS:%.o=%.d) + +clean: + @echo "CLEAN"; rm -f $(TEST_PROGRAM) $(LIBRARY) $(OBJS) *.d $(GENERATED_SOURCES) + diff --git a/LibHTML/Parser/CSSParser.cpp b/LibHTML/Parser/CSSParser.cpp index 4a01727f3ac..b55e50e6423 100644 --- a/LibHTML/Parser/CSSParser.cpp +++ b/LibHTML/Parser/CSSParser.cpp @@ -80,7 +80,6 @@ NonnullRefPtr parse_css(const String& css) auto parse_declaration = [&] { consume_whitespace(); - }; auto parse_declarations = [&] {