summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLevent Kaya <levent@dev>2025-11-04 12:42:25 +0300
committerLevent Kaya <levent@dev>2025-11-04 12:42:25 +0300
commit9fe39a2c099f8c4c4f0782716142404e6aad6080 (patch)
tree66590bfdca5dd3fb08589c56d0d1c6bb447590c8
parent2ce38cae044750a10127e07080168dccc1fe3534 (diff)
[build] cmake to makefile conversion
-rw-r--r--CMakeLists.txt35
-rw-r--r--Makefile59
2 files changed, 59 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index 4519e1d..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-cmake_minimum_required(VERSION 3.11)
-
-project(fbglExamples C)
-
-add_custom_target(run-examples)
-
-set(FBGL_HEADER "fbgl.h")
-set(EXAMPLES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/examples")
-
-# find freetype2
-find_package(PkgConfig REQUIRED)
-pkg_check_modules(FREETYPE2 REQUIRED freetype2)
-include_directories(${FREETYPE2_INCLUDE_DIRS})
-
-function(add_example NAME)
- add_executable("${NAME}" "${EXAMPLES_DIR}/${NAME}.c" "${FBGL_HEADER}")
- target_compile_features("${NAME}" PRIVATE c_std_99)
- target_compile_options("${NAME}" PRIVATE -Wall -Wextra -Wpedantic)
- target_include_directories("${NAME}" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
- target_link_libraries("${NAME}" PRIVATE ${FREETYPE2_LIBRARIES} m)
- add_custom_target("run_${NAME}" COMMAND "${NAME}" VERBATIM)
- add_dependencies("run_${NAME}" "${NAME}")
- add_dependencies(run-examples "run_${NAME}")
-endfunction()
-
-add_example(line)
-add_example(rectangle)
-add_example(red)
-add_example(texture)
-add_example(framebuf_info)
-add_example(text)
-add_example(texture_show_fps)
-add_example(circle)
-add_example(player)
-add_example(ray_casting)
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..7861b84
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,59 @@
+# Makefile for fbglExamples
+
+# Project settings
+PROJECT = fbglExamples
+FBGL_HEADER = fbgl.h
+EXAMPLES_DIR = examples
+
+# Compiler settings
+CC = gcc
+CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -I. -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE
+LDFLAGS = -lm
+
+# Find freetype2 using pkg-config
+FREETYPE2_CFLAGS = $(shell pkg-config --cflags freetype2)
+FREETYPE2_LIBS = $(shell pkg-config --libs freetype2)
+
+# Combine flags
+CFLAGS += $(FREETYPE2_CFLAGS)
+LDFLAGS += $(FREETYPE2_LIBS)
+
+# Example programs
+EXAMPLES = line rectangle red texture framebuf_info text texture_show_fps circle player ray_casting
+
+# Targets
+EXAMPLE_BINS = $(EXAMPLES)
+RUN_TARGETS = $(addprefix run_, $(EXAMPLES))
+
+# Default target
+.PHONY: all
+all: $(EXAMPLE_BINS)
+
+# Build each example
+$(EXAMPLE_BINS): %: $(EXAMPLES_DIR)/%.c $(FBGL_HEADER)
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+
+# Run individual examples
+.PHONY: $(RUN_TARGETS)
+$(RUN_TARGETS): run_%: %
+ ./$<
+
+# Run all examples
+.PHONY: run-examples
+run-examples: $(RUN_TARGETS)
+
+# Clean build artifacts
+.PHONY: clean
+clean:
+ rm -f $(EXAMPLE_BINS)
+
+# Help target
+.PHONY: help
+help:
+ @echo "Available targets:"
+ @echo " all - Build all examples (default)"
+ @echo " run-examples - Run all examples"
+ @echo " run_<name> - Run specific example (e.g., make run_line)"
+ @echo " clean - Remove built executables"
+ @echo ""
+ @echo "Examples: $(EXAMPLES)" \ No newline at end of file