mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-11 07:00:58 +08:00
Merge pull request #90 from alexcpatel/makefile-compile-objects
Makefile: compile objects individually, then link
This commit is contained in:
commit
dc13ee01d3
7
.github/workflows/build.yml
vendored
7
.github/workflows/build.yml
vendored
@ -19,8 +19,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Run the Makefile.
|
- name: Run the Makefile.
|
||||||
run: |
|
run: |
|
||||||
cd build
|
make all
|
||||||
make
|
|
||||||
- name: Run tests.
|
- name: Run tests.
|
||||||
run: |
|
run: |
|
||||||
python3 tests/tests.py
|
python3 tests/tests.py
|
||||||
@ -32,7 +31,6 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Run build batch script.
|
- name: Run build batch script.
|
||||||
run: |
|
run: |
|
||||||
cd build
|
|
||||||
cmd /c build.bat
|
cmd /c build.bat
|
||||||
- name: Run tests.
|
- name: Run tests.
|
||||||
run: |
|
run: |
|
||||||
@ -45,8 +43,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Run the Makefile.
|
- name: Run the Makefile.
|
||||||
run: |
|
run: |
|
||||||
cd build
|
make all
|
||||||
make
|
|
||||||
- name: Run tests.
|
- name: Run tests.
|
||||||
run: |
|
run: |
|
||||||
python3 tests/tests.py
|
python3 tests/tests.py
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,8 +2,9 @@
|
|||||||
# PocketLang ignore list
|
# PocketLang ignore list
|
||||||
.vs/
|
.vs/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
build/
|
||||||
|
|
||||||
# It's a convinent batch scrpit to run pyton script
|
# It's a convinent batch script to run pyton script
|
||||||
# changing directory and run another script.
|
# changing directory and run another script.
|
||||||
# Which are compile wasm and generate pages.
|
# Which are compile wasm and generate pages.
|
||||||
docs/build.bat
|
docs/build.bat
|
||||||
|
59
Makefile
Normal file
59
Makefile
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
|
||||||
|
# ## Copyright (c) 2020-2021 Thakee Nathees
|
||||||
|
# ## Distributed Under The MIT License
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -fPIC -Wno-int-to-pointer-cast
|
||||||
|
DEBUG_CFLAGS = -D DEBUG -g3 -Og
|
||||||
|
RELEASE_CFLAGS = -g -O3
|
||||||
|
LDFLAGS = -lm
|
||||||
|
|
||||||
|
TARGET_EXEC = pocket
|
||||||
|
BUILD_DIR = ./build
|
||||||
|
|
||||||
|
SRC_DIRS = ./src ./cli
|
||||||
|
INC_DIRS = ./src/include
|
||||||
|
|
||||||
|
SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name *.c)
|
||||||
|
OBJS := $(SRCS:.c=.o)
|
||||||
|
DEPS := $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||||||
|
DEP_FLAGS = -MMD -MP
|
||||||
|
CC_FLAGS = $(INC_FLAGS) $(DEP_FLAGS) $(CFLAGS)
|
||||||
|
|
||||||
|
DEBUG_DIR = $(BUILD_DIR)/debug
|
||||||
|
DEBUG_TARGET = $(DEBUG_DIR)/$(TARGET_EXEC)
|
||||||
|
DEBUG_OBJS := $(addprefix $(DEBUG_DIR)/, $(OBJS))
|
||||||
|
|
||||||
|
RELEASE_DIR = $(BUILD_DIR)/release
|
||||||
|
RELEASE_TARGET = $(RELEASE_DIR)/$(TARGET_EXEC)
|
||||||
|
RELEASE_OBJS := $(addprefix $(RELEASE_DIR)/, $(OBJS))
|
||||||
|
|
||||||
|
.PHONY: debug release all clean
|
||||||
|
|
||||||
|
# default; target if run as `make`
|
||||||
|
debug: $(DEBUG_TARGET)
|
||||||
|
|
||||||
|
$(DEBUG_TARGET): $(DEBUG_OBJS)
|
||||||
|
$(CC) $^ -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
$(DEBUG_DIR)/%.o: %.c
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) $(CC_FLAGS) $(DEBUG_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
release: $(RELEASE_TARGET)
|
||||||
|
|
||||||
|
$(RELEASE_TARGET): $(RELEASE_OBJS)
|
||||||
|
$(CC) $^ -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
|
$(RELEASE_DIR)/%.o: %.c
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) $(CC_FLAGS) $(RELEASE_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
all: debug release
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(BUILD_DIR)
|
||||||
|
|
||||||
|
-include $(DEPS)
|
@ -95,11 +95,11 @@ set root_dir=..\..\..\
|
|||||||
|
|
||||||
if "%debug_build%"=="false" (
|
if "%debug_build%"=="false" (
|
||||||
set cflags=%cflags% -O2 -MD
|
set cflags=%cflags% -O2 -MD
|
||||||
set target_dir=release\
|
set target_dir=build\release\
|
||||||
) else (
|
) else (
|
||||||
set cflags=%cflags% -MDd -ZI
|
set cflags=%cflags% -MDd -ZI
|
||||||
set addnl_cdefines=%addnl_cdefines% /DDEBUG
|
set addnl_cdefines=%addnl_cdefines% /DDEBUG
|
||||||
set target_dir=debug\
|
set target_dir=build\debug\
|
||||||
)
|
)
|
||||||
|
|
||||||
if "%shared_lib%"=="true" (
|
if "%shared_lib%"=="true" (
|
5
build/.gitignore
vendored
5
build/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
*
|
|
||||||
!.gitignore
|
|
||||||
!SConstruct
|
|
||||||
!build.bat
|
|
||||||
!Makefile
|
|
@ -1,22 +0,0 @@
|
|||||||
|
|
||||||
## Copyright (c) 2020-2021 Thakee Nathees
|
|
||||||
## Distributed Under The MIT License
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
CFLAGS = -lm -fPIC -Wno-int-to-pointer-cast
|
|
||||||
INCLUDE_DIR = -I../src/include
|
|
||||||
SOURCES = ../cli/*.c ../src/*.c
|
|
||||||
|
|
||||||
all: debug
|
|
||||||
|
|
||||||
debug:
|
|
||||||
@mkdir -p debug/
|
|
||||||
$(CC) -o debug/pocket $(SOURCES) $(INCLUDE_DIR) $(CFLAGS) -D DEBUG -g3 -Og
|
|
||||||
|
|
||||||
release:
|
|
||||||
@mkdir -p release/
|
|
||||||
$(CC) -o release/pocket $(SOURCES) $(INCLUDE_DIR) $(CFLAGS) -g -O3
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf debug/
|
|
||||||
rm -rf release/
|
|
Loading…
Reference in New Issue
Block a user