-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from punixcorn/_free
Makefile changes, Github workflow updated
- Loading branch information
Showing
14 changed files
with
185 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v3 | ||
- name: make | ||
run: make make_check | ||
run: make workflow-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ a.out | |
peda-session-main.txt | ||
*/**/*.h.gch | ||
*/*.h.gch | ||
lib/ | ||
static_lib/ | ||
lib/* | ||
static_lib/* | ||
build/* | ||
shared_lib/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,69 @@ | ||
FLAGS= -std=c11 -ggdb -w | ||
# source files from include/ | ||
c_include_source_files := $(shell find include/* -name "*.c") | ||
c_include_header_files := $(shell find include/* -name "*.h") | ||
# source files from src/ | ||
c_source_files := $(shell find src/* -name "*.c") | ||
c_header_files := $(shell find src/* -name "*.h") | ||
# shared so files | ||
#shared_libs = $(shell find shared_lib/* -name "*.so") | ||
# Compile flags | ||
FLAGS= -std=c11 -ggdb -w -nostdlib | ||
# input args to main ( set at runtime ) | ||
args= | ||
|
||
|
||
# uses shared files | ||
shared: lib src/main.c | ||
@./scripts/check_bin.sh | ||
@./scripts/check_lib.sh | ||
gcc $(FLAGS) -nostdlib lib/* include/src/_lib.c src/main.c -o bin/main | ||
@# adding _lib.c because undefined refernce to _start(); | ||
# make all so files and build main binary with it | ||
bootstrap_shared_lib: | ||
@mkdir -p build shared_lib | ||
@echo -e "[\e[42m Building so files... \e[0m]" | ||
@$(foreach file ,$(c_include_source_files),gcc -shared $(file) -o $(patsubst include/src/%.c, shared_lib/%.so, $(file)) && ) true | ||
@echo -e "\e[32m[+]\e[0m Done." | ||
|
||
static: static_lib/* src/main.c | ||
make static_lib | ||
@./scripts/check_bin.sh | ||
gcc -static -w -nostdlib $(FLAGS) src/main.c static_lib/no_libc.a -o bin/main | ||
.PHONY: shared_lib | ||
shared_lib: bootstrap_shared_lib $(c_include_source_files) $(c_source_files) $(c_header_files) | ||
@echo -e "\e[32m[+]\e[0m Linking File..." | ||
gcc ${FLAGS} $(shell find shared_lib/* -name "*.so") include/src/_lib.c ${c_source_files} -o build/main | ||
@echo -e "\e[32m[+]\e[0m Done." | ||
|
||
# uses .c files | ||
main: include/**/* src/main.c | ||
@./scripts/check_bin.sh | ||
gcc $(FLAGS) -nostdlib include/src/* src/* -o bin/main | ||
|
||
# runs every check | ||
make_check: | ||
@echo "==============================================" | ||
make main | ||
.PHONY: static_lib | ||
static_lib: $(c_include_source_files) $(c_include_header_files) $(c_source_files) $(c_include_files) | ||
@mkdir -p build/ | ||
@echo -e "[\e[42m Building Static lib... \e[0m]" | ||
cd static_lib && make | ||
@echo -e "\e[32m[+]\e[0m Linking File..." | ||
gcc -nostdlib -L. ./src/main.c -l:./static_lib/no_libc.a -o build/main | ||
@echo -e "\e[32m[+]\e[0m Done." | ||
|
||
# creates a static lib | ||
static_lib_: | ||
cd static_lib && make all | ||
|
||
test: | ||
@echo -e "\e[43m[ TESTING BUILDS \e[0m]" | ||
@echo -e "\e[33m[#]\e[0m TESTING : LINKING C FILES" | ||
make all | ||
@echo -e "\e[33m[#]\e[0m TESTING : CREATING SO LIBS" | ||
make shared_lib | ||
@echo -e "\e[33m[#]\e[0m TESTING : CREATING STATIC LIBS" | ||
make static_lib | ||
@echo -e "\e[32m[+]\e[0m Done." | ||
|
||
workflow-test: | ||
@echo -e "\e[43m[ TESTING WORKFLOW BUILD \e[0m]" | ||
@echo -e "\e[33m[#]\e[0m TESTING : LINKING C FILES" | ||
make all | ||
|
||
# uses .c files | ||
.PHONY: all | ||
all: $(c_include_source_files) $(c_include_header_files) $(c_source_files) $(c_include_files) | ||
@echo -e "[\e[42m Building Binary file... \e[0m]" | ||
@mkdir -p build/ | ||
gcc $(FLAGS) ${c_include_source_files} ${c_source_files} -o build/main | ||
@echo -e "\e[32m[+]\e[0m Done." | ||
|
||
.PHONY: run | ||
run: | ||
@echo "==============================================" | ||
@./bin/main $(args) | ||
@./build/main $(args) | ||
@echo "==============================================" | ||
make clean | ||
|
||
clean: | ||
@echo "Cleaning..." | ||
@touch bin/t lib/a | ||
@rm bin/* 2>/dev/null | ||
@rm lib/* 2>/dev/null | ||
@echo "Done" | ||
rm -rf build/* 2>/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
#ifndef __STACK_CHK_FAIL__ | ||
#define __STACK_CHK_FAIL__ | ||
int __stack_chk_fail(void); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
files=$(ls lib/) | ||
files=$(/bin/ls lib/) | ||
|
||
if [ -z "$files" ];then | ||
./scripts/shared.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
c_include_source_files := $(shell find include/* -name "*.c") | ||
c_include_header_files := $(shell find include/* -name "*.h") | ||
c_source_files := $(shell find src/* -name "*.c") | ||
c_header_files := $(shell find src/* -name "*.h") | ||
|
||
shared_libs = $(shell find shared_lib/* -name "*.so") | ||
|
||
shared_libs_output_files := $(patsubst include/src/%.c, shared_lib/%.so, $(c_include_source_files)) | ||
FLAGS= -std=c11 -ggdb -w -nostdlib -nostartfiles | ||
args= | ||
|
||
koo: | ||
@echo $(shared_libs_output_files) | ||
|
||
loop: | ||
$(foreach file ,$(c_include_source_files),gcc -shared $(file) -o $(patsubst include/src/%.c, shared_lib/%.so, $(file)) && ) true | ||
echo: | ||
|
||
@echo $(output_shared_object_files_name:_=lib_) | ||
@echo ${c_include_source_files} | ||
@echo ${c_include_header_files} | ||
@echo ${c_source_files} | ||
@echo ${c_header_files} | ||
@echo ${shared_libs} | ||
|
||
|
||
# uses shared files | ||
shared: src/main.c | ||
@mkdir -p build lib | ||
@./scripts/check_lib.sh | ||
gcc $(FLAGS) -nostdlib lib/* include/src/_lib.c src/main.c -o build/main | ||
@# adding _lib.c because undefined refernce to _start(); | ||
|
||
shared_2: $(c_include_source_files) $(c_source_files) $(shared_libs) | ||
@mkdir -p build shared_lib | ||
@$(foreach file ,$(c_include_source_files),gcc -shared $(file) -o $(patsubst include/src/%.c, shared_lib/%.so, $(file)) && ) true | ||
gcc ${FLAGS} ${shared_libs} include/src/_lib.c ${c_source_files} -o build/main | ||
|
||
|
||
static: static_lib/* src/main.c | ||
make static_lib | ||
@mkdir -p build/ | ||
gcc -static -w -nostdlib $(FLAGS) src/main.c static_lib/no_libc.a -o build/main | ||
|
||
# uses .c files | ||
main: include/**/* src/main.c | ||
@mkdir -p build/ | ||
gcc $(FLAGS) -nostdlib include/src/* src/* -o build/main | ||
|
||
# runs every check | ||
make_check: | ||
$(info "==============================================") | ||
make main | ||
|
||
# creates a static lib | ||
static_lib_: | ||
cd static_lib && make all | ||
|
||
run: | ||
@echo "==============================================" | ||
@./build/main $(args) | ||
@echo "==============================================" | ||
make clean | ||
|
||
clean: | ||
@echo "Cleaning..." | ||
@rm -rf build/ 2>/dev/null | ||
@rm -rf lib/ 2>/dev/null | ||
@echo "Done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,8 @@ int main() { | |
_println("Memory not freeed"); | ||
} | ||
|
||
int i = 0; | ||
_scanf("%d", &i); | ||
_printf("%d is i", i); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.