summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authoradmin <contact@optics-design.com>2025-05-24 17:38:59 +0200
committeradmin <contact@optics-design.com>2025-05-24 17:38:59 +0200
commitf9e1e76011236f05d6e2c3b62e2ae2969c64f808 (patch)
tree0e790dc70598c414de9a9b9a9492b498b345ca39 /Makefile
parent337a53667a8f3327e30f69d3df589d7b5eb91b9d (diff)
Adjusted files for cross-compilation on Linux
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile93
1 files changed, 83 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index d192768..dc5f750 100644
--- a/Makefile
+++ b/Makefile
@@ -1,31 +1,104 @@
CC=gcc
+# Cross-compilation (only used on Linux)
+MINGW_CC=x86_64-w64-mingw32-gcc
+
#Base Directories
SRCDIR=src
BINDIR=bin
+BINDIR_WIN=bin/win
INCDIR=include
#Common flags
-CFLAGS=-I$(INCDIR) -O2 -march=native -flto #-ffast-math
+CFLAGS_BASE=-I$(INCDIR) -O2 -flto
+CFLAGS_NATIVE=$(CFLAGS_BASE) -march=native #-ffast-math
+CFLAGS_PORTABLE=$(CFLAGS_BASE) #-ffast-math (no -march=native for portability)
+
+# OS Detection
+ifeq ($(OS),Windows_NT)
+ # Windows host
+ EXE_EXT=.exe
+ MKDIR=mkdir
+ RM=del /Q
+ LDFLAGS=
+ TREE_CMD=powershell -Command "(Get-Item .).Name | Set-Content structure.txt; (tree /a /f | Select-Object -Skip 3) | Add-Content structure.txt"
+
+ # On Windows: compile Windows binaries without -march=native for portability
+ NATIVE_CC=$(CC)
+ NATIVE_CFLAGS=$(CFLAGS_PORTABLE)
+ NATIVE_LDFLAGS=$(LDFLAGS)
+ NATIVE_EXT=.exe
+else
+ # Linux host
+ EXE_EXT=
+ MKDIR=mkdir -p
+ RM=rm -f
+ LDFLAGS=-lm
+ TREE_CMD=basename $(PWD) > structure.txt; tree -a -F >> structure.txt 2>/dev/null || (find . -type f -name "*.c" -o -name "*.h" -o -name "Makefile" | sort >> structure.txt)
+
+ # On Linux: compile Linux binaries with -march=native for performance
+ NATIVE_CC=$(CC)
+ NATIVE_CFLAGS=$(CFLAGS_NATIVE)
+ NATIVE_LDFLAGS=$(LDFLAGS)
+ NATIVE_EXT=
+endif
+
#tolutils
-TOL_SRCS = $(wildcard $(SRCDIR)/*.c)
-TOL_EXES = $(patsubst $(SRCDIR)/%.c, $(BINDIR)/%.exe, $(TOL_SRCS))
+TOL_SRCS = $(wildcard $(SRCDIR)/*.c)
+TOL_EXES_NATIVE = $(patsubst $(SRCDIR)/%.c, $(BINDIR)/%$(NATIVE_EXT), $(TOL_SRCS))
+TOL_EXES_WIN = $(patsubst $(SRCDIR)/%.c, $(BINDIR_WIN)/%.exe, $(TOL_SRCS))
# Setup target
setup:
- mkdir -p $(BINDIR) $(INCDIR)
+ $(MKDIR) $(BINDIR) $(INCDIR)
+setup-cross:
+ $(MKDIR) $(BINDIR) $(BINDIR_WIN) $(INCDIR)
+
+# Default: build for current platform
all: setup tolsac structure
-tolsac: $(TOL_EXES)
-$(BINDIR)/%.exe: $(SRCDIR)/%.c
- $(CC) $< $(CFLAGS) -o $@
+# Build for current platform (native)
+tolsac: $(TOL_EXES_NATIVE)
+
+# Native compilation rule
+$(BINDIR)/%$(NATIVE_EXT): $(SRCDIR)/%.c
+ $(NATIVE_CC) $< $(NATIVE_CFLAGS) -o $@ $(NATIVE_LDFLAGS)
+
+# Cross-compilation targets (Linux host only)
+ifneq ($(OS),Windows_NT)
+tolsac-win: setup-cross $(TOL_EXES_WIN)
+tolsac-all: tolsac tolsac-win
+rebuild-win: clean tolsac-win
+rebuild-all: clean tolsac-all
+
+$(BINDIR_WIN)/%.exe: $(SRCDIR)/%.c
+ $(MINGW_CC) $< $(CFLAGS_PORTABLE) -o $@
+else
+# On Windows, provide helpful messages for cross-compilation targets
+tolsac-win:
+ @echo "Cross-compilation to Windows not needed on Windows host. Use 'make tolsac' instead."
+
+tolsac-all: tolsac
+ @echo "On Windows host: built Windows binaries (cross-compilation not applicable)."
+
+rebuild-win: rebuild
+ @echo "On Windows host: rebuilt Windows binaries."
+
+rebuild-all: rebuild
+ @echo "On Windows host: rebuilt Windows binaries."
+endif
clean:
- rm -f $(BINDIR)/*
- rm -f structure.txt
+ $(RM) $(BINDIR)/*
+ifneq ($(OS),Windows_NT)
+ $(RM) $(BINDIR_WIN)/*
+endif
+ $(RM) structure.txt
rebuild: clean all
# Generate project structure
structure:
- @powershell -Command "(Get-Item .).Name | Set-Content structure.txt; (tree /a /f | Select-Object -Skip 3) | Add-Content structure.txt"
+ @$(TREE_CMD)
+
+.PHONY: all setup setup-cross tolsac tolsac-win tolsac-all clean rebuild rebuild-win rebuild-all structure
Back to https://optics-design.com