Browse Source

Update Makefile for web compilation

Some flags are only for the linker, not the compiler
raysan5 4 years ago
parent
commit
b63c2619e3
2 changed files with 33 additions and 29 deletions
  1. 32 27
      examples/Makefile
  2. 1 2
      src/Makefile

+ 32 - 27
examples/Makefile

@@ -25,7 +25,7 @@
 
 
 # Define required raylib variables
 # Define required raylib variables
 PROJECT_NAME       ?= raylib_examples
 PROJECT_NAME       ?= raylib_examples
-RAYLIB_VERSION     ?= 3.8.0
+RAYLIB_VERSION     ?= 4.0.0
 RAYLIB_PATH        ?= ..
 RAYLIB_PATH        ?= ..
 
 
 # Define default options
 # Define default options
@@ -185,6 +185,12 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
         MAKE = mingw32-make
         MAKE = mingw32-make
     endif
     endif
 endif
 endif
+ifeq ($(PLATFORM),PLATFORM_ANDROID)
+    MAKE = mingw32-make
+endif
+ifeq ($(PLATFORM),PLATFORM_WEB)
+    MAKE = mingw32-make
+endif
 
 
 # Define compiler flags:
 # Define compiler flags:
 #  -O1                  defines optimization level
 #  -O1                  defines optimization level
@@ -229,32 +235,6 @@ endif
 ifeq ($(PLATFORM),PLATFORM_DRM)
 ifeq ($(PLATFORM),PLATFORM_DRM)
     CFLAGS += -std=gnu99 -DEGL_NO_X11
     CFLAGS += -std=gnu99 -DEGL_NO_X11
 endif
 endif
-ifeq ($(PLATFORM),PLATFORM_WEB)
-    # -Os                        # size optimization
-    # -O2                        # optimization level 2, if used, also set --memory-init-file 0
-    # -s USE_GLFW=3              # Use glfw3 library (context/input management)
-    # -s ALLOW_MEMORY_GROWTH=1   # to allow memory resizing -> WARNING: Audio buffers could FAIL!
-    # -s TOTAL_MEMORY=16777216   # to specify heap memory size (default = 16MB)
-    # -s USE_PTHREADS=1          # multithreading support
-    # -s WASM=0                  # disable Web Assembly, emitted by default
-    # -s ASYNCIFY                # lets synchronous C/C++ code interact with asynchronous JS
-    # -s FORCE_FILESYSTEM=1      # force filesystem to load/save files data
-    # -s ASSERTIONS=1            # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
-    # --profiling                # include information for code profiling
-    # --memory-init-file 0       # to avoid an external memory initialization code file (.mem)
-    # --preload-file resources   # specify a resources folder for data compilation
-    # --source-map-base          # allow debugging in browser with source map
-    CFLAGS += -s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --preload-file $(dir $<)resources@resources
-
-    # NOTE: Simple raylib examples are compiled to be interpreter with asyncify, that way,
-    # we can compile same code for ALL platforms with no change required, but, working on bigger
-    # projects, code needs to be refactored to avoid a blocking while() loop, moving Update and Draw
-    # logic to a self contained function: UpdateDrawFrame(), check core_basic_window_web.c for reference.
-
-    # Define a custom shell .html and output extension
-    CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
-    EXT = .html
-endif
 
 
 # Define include paths for required headers
 # Define include paths for required headers
 # NOTE: Some external/extras libraries could be required (stb, physac, easings...)
 # NOTE: Some external/extras libraries could be required (stb, physac, easings...)
@@ -303,7 +283,32 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
         LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)
         LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)
     endif
     endif
 endif
 endif
+ifeq ($(PLATFORM),PLATFORM_WEB)
+    # -Os                        # size optimization
+    # -O2                        # optimization level 2, if used, also set --memory-init-file 0
+    # -s USE_GLFW=3              # Use glfw3 library (context/input management)
+    # -s ALLOW_MEMORY_GROWTH=1   # to allow memory resizing -> WARNING: Audio buffers could FAIL!
+    # -s TOTAL_MEMORY=16777216   # to specify heap memory size (default = 16MB) (67108864 = 64MB)
+    # -s USE_PTHREADS=1          # multithreading support
+    # -s WASM=0                  # disable Web Assembly, emitted by default
+    # -s ASYNCIFY                # lets synchronous C/C++ code interact with asynchronous JS
+    # -s FORCE_FILESYSTEM=1      # force filesystem to load/save files data
+    # -s ASSERTIONS=1            # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
+    # --profiling                # include information for code profiling
+    # --memory-init-file 0       # to avoid an external memory initialization code file (.mem)
+    # --preload-file resources   # specify a resources folder for data compilation
+    # --source-map-base          # allow debugging in browser with source map
+    LDFLAGS += -s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --preload-file $(dir $<)resources@resources
+
+    # NOTE: Simple raylib examples are compiled to be interpreter with asyncify, that way,
+    # we can compile same code for ALL platforms with no change required, but, working on bigger
+    # projects, code needs to be refactored to avoid a blocking while() loop, moving Update and Draw
+    # logic to a self contained function: UpdateDrawFrame(), check core_basic_window_web.c for reference.
 
 
+    # Define a custom shell .html and output extension
+    LDFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
+    EXT = .html
+endif
 ifeq ($(PLATFORM),PLATFORM_RPI)
 ifeq ($(PLATFORM),PLATFORM_RPI)
     LDFLAGS += -L/opt/vc/lib
     LDFLAGS += -L/opt/vc/lib
 endif
 endif

+ 1 - 2
src/Makefile

@@ -309,7 +309,7 @@ endif
 ifeq ($(PLATFORM),PLATFORM_WEB)
 ifeq ($(PLATFORM),PLATFORM_WEB)
     # -Os                        # size optimization
     # -Os                        # size optimization
     # -O2                        # optimization level 2, if used, also set --memory-init-file 0
     # -O2                        # optimization level 2, if used, also set --memory-init-file 0
-    # -s USE_GLFW=3              # Use glfw3 library (context/input management)
+    # -s USE_GLFW=3              # Use glfw3 library (context/input management) -> Only for linker!
     # -s ALLOW_MEMORY_GROWTH=1   # to allow memory resizing -> WARNING: Audio buffers could FAIL!
     # -s ALLOW_MEMORY_GROWTH=1   # to allow memory resizing -> WARNING: Audio buffers could FAIL!
     # -s TOTAL_MEMORY=16777216   # to specify heap memory size (default = 16MB)
     # -s TOTAL_MEMORY=16777216   # to specify heap memory size (default = 16MB)
     # -s USE_PTHREADS=1          # multithreading support
     # -s USE_PTHREADS=1          # multithreading support
@@ -318,7 +318,6 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
     # --profiling                # include information for code profiling
     # --profiling                # include information for code profiling
     # --memory-init-file 0       # to avoid an external memory initialization code file (.mem)
     # --memory-init-file 0       # to avoid an external memory initialization code file (.mem)
     # --preload-file resources   # specify a resources folder for data compilation
     # --preload-file resources   # specify a resources folder for data compilation
-    CFLAGS += -s USE_GLFW=3
     ifeq ($(RAYLIB_BUILD_MODE),DEBUG)
     ifeq ($(RAYLIB_BUILD_MODE),DEBUG)
         CFLAGS += -s ASSERTIONS=1 --profiling
         CFLAGS += -s ASSERTIONS=1 --profiling
     endif
     endif