forked from tsoding/crepl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
669 lines (600 loc) Β· 26.1 KB
/
Makefile
File metadata and controls
669 lines (600 loc) Β· 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# ============================================================================
# MalCREPL - Enhanced C REPL with Encryption and Network Features
# Flexible Makefile with Dynamic and Custom Build Options
# ============================================================================
# Compiler and base flags
CC = gcc
CFLAGS = -Wall -Wextra -Wno-unused-function -std=c11 -D_POSIX_C_SOURCE=200809L
TARGET = malcrepl
# Source files - check what exists
SOURCES = malcrepl.c
# Add optional sources if they exist
ifneq ($(wildcard enclib.c),)
SOURCES += enclib.c
endif
ifneq ($(wildcard netlib.c),)
SOURCES += netlib.c
endif
HEADERS = enclib.h netlib.h stb_c_lexer.h
OBJECTS = $(SOURCES:.c=.o)
# ============================================================================
# Architecture Detection
# ============================================================================
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
LIBDIR = /usr/lib/x86_64-linux-gnu
else ifeq ($(ARCH),aarch64)
LIBDIR = /usr/lib/aarch64-linux-gnu
else
LIBDIR = /usr/lib
endif
# ============================================================================
# Library Configuration
# ============================================================================
# Required libraries
LIBS_TCC = -ltcc
LIBS_FFI = -lffi
LIBS_CURL = -lcurl
LIBS_CRYPTO = -lcrypto
LIBS_SYSTEM = -lm -ldl -lpthread -lreadline
# Static library paths
LIBTCC_STATIC = $(LIBDIR)/libtcc.a
LIBFFI_STATIC = $(LIBDIR)/libffi.a
# Check if static libcurl is available system-wide
LIBCURL_STATIC_SYSTEM = /usr/local/lib/libcurl.a
LIBCURL_STATIC_LOCAL = ./build/curl-8.6.0/lib/.libs/libcurl.a
# Determine which libcurl to use for static builds
ifeq ($(wildcard $(LIBCURL_STATIC_SYSTEM)),)
LIBCURL_STATIC = $(LIBCURL_STATIC_LOCAL)
CURL_SOURCE = local
else
LIBCURL_STATIC = $(LIBCURL_STATIC_SYSTEM)
CURL_SOURCE = system
endif
# ============================================================================
# Build Configurations
# ============================================================================
# Dynamic linking (default) - smallest binary, needs .so files
LDFLAGS_DYNAMIC = $(LIBS_TCC) $(LIBS_FFI) $(LIBS_CURL) $(LIBS_CRYPTO) $(LIBS_SYSTEM)
# Hybrid static - TCC and FFI static, rest dynamic
LDFLAGS_HYBRID = -static-libgcc \
-Wl,-Bstatic $(LIBTCC_STATIC) $(LIBFFI_STATIC) \
-Wl,-Bdynamic $(LIBS_CURL) $(LIBS_CRYPTO) $(LIBS_SYSTEM)
# Semi-static - TCC, FFI, and system libs static, curl/openssl dynamic
# This avoids OpenSSL version conflicts
LDFLAGS_SEMI_STATIC = -Wl,-Bstatic \
$(LIBTCC_STATIC) $(LIBFFI_STATIC) \
-Wl,-Bdynamic \
$(LIBS_CURL) $(LIBS_CRYPTO) \
-static-libgcc \
$(LIBS_SYSTEM)
# Full static - everything embedded (portable)
# Note: Library order matters! OpenSSL before crypto, crypto before zstd
LDFLAGS_STATIC = -static \
-Wl,--start-group \
$(LIBTCC_STATIC) $(LIBFFI_STATIC) $(LIBCURL_STATIC) \
-lssl -lcrypto \
-lz -lzstd \
-lm -ldl -lpthread \
-Wl,--end-group
# Custom build - user can specify what to link statically
# Usage: make custom STATIC_LIBS="tcc ffi" DYNAMIC_LIBS="curl crypto"
STATIC_LIBS ?=
DYNAMIC_LIBS ?=
LDFLAGS_CUSTOM = $(call build_custom_ldflags)
# ============================================================================
# Build Targets
# ============================================================================
.DEFAULT_GOAL := help-quick
# Quick help (shows most common targets)
help-quick:
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo " MalCREPL - Enhanced C REPL Build System"
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo ""
@echo "π Quick Start:"
@echo " make setup - Install all dependencies"
@echo " make build - Build dynamic version (recommended)"
@echo " make static - Build fully static (for distribution)"
@echo ""
@echo "π¦ Common Targets:"
@echo " make build - Dynamic build (fast, needs libraries)"
@echo " make semi-static - Semi-static (recommended if static fails)"
@echo " make static - Full static build (portable, large)"
@echo " make hybrid - Hybrid static (balance of both)"
@echo " make custom - Custom build (see 'make help-custom')"
@echo ""
@echo "π οΈ Development:"
@echo " make debug - Build with debug symbols"
@echo " make release - Optimized release build"
@echo ""
@echo "π More Information:"
@echo " make help - Show all targets"
@echo " make help-custom - Show custom build options"
@echo " make info - Show build configuration"
@echo ""
# ============================================================================
# Main Build Targets
# ============================================================================
# Alias: 'all' points to 'build'
all: build
# Default: Dynamic build
build: check-deps-minimal $(HEADERS) $(TARGET)
@echo ""
@echo "β
Dynamic build complete!"
@echo " Binary: ./$(TARGET) (~30KB)"
@echo " Run: ./$(TARGET) <source.c>"
@echo " Dependencies: needs .so files installed"
@echo ""
# Build with dynamic linking
$(TARGET): $(SOURCES) $(HEADERS)
@echo "π¨ Building dynamic version..."
$(CC) $(CFLAGS) -o $(TARGET) $(SOURCES) $(LDFLAGS_DYNAMIC)
# Static build - fully standalone
# NOTE: May fail with OpenSSL version conflicts. Use 'make semi-static' instead.
static: check-deps-static $(HEADERS) ensure-static-curl $(TARGET)-static
@echo ""
@echo "β
Static build complete!"
@echo " Binary: ./$(TARGET)-static (~800KB)"
@echo " Portable: works without dependencies"
@echo " Run: ./$(TARGET)-static <source.c>"
@echo ""
@echo "β οΈ If you see OpenSSL errors, use: make semi-static"
@echo ""
$(TARGET)-static: $(SOURCES) $(HEADERS)
@echo "π¨ Building fully static version..."
$(CC) $(CFLAGS) -o $(TARGET)-static $(SOURCES) $(LDFLAGS_STATIC)
# Hybrid build - balance between size and portability
hybrid: check-deps-hybrid $(HEADERS) $(TARGET)-hybrid
@echo ""
@echo "β
Hybrid build complete!"
@echo " Binary: ./$(TARGET)-hybrid (~200KB)"
@echo " Portable: TCC/FFI embedded, needs system libs"
@echo " Run: ./$(TARGET)-hybrid <source.c>"
@echo ""
$(TARGET)-hybrid: $(SOURCES) $(HEADERS)
@echo "π¨ Building hybrid version..."
$(CC) $(CFLAGS) -o $(TARGET)-hybrid $(SOURCES) $(LDFLAGS_HYBRID)
# Semi-static build - avoids OpenSSL version conflicts
# Use this if full static build fails with OpenSSL errors
semi-static: check-deps-hybrid $(HEADERS) $(TARGET)-semi
@echo ""
@echo "β
Semi-static build complete!"
@echo " Binary: ./$(TARGET)-semi (~50KB)"
@echo " Portable: TCC/FFI embedded, needs curl/openssl"
@echo " Run: ./$(TARGET)-semi <source.c>"
@echo " Note: Best option if full static fails"
@echo ""
$(TARGET)-semi: $(SOURCES) $(HEADERS)
@echo "π¨ Building semi-static version (TCC/FFI static, curl/openssl dynamic)..."
$(CC) $(CFLAGS) -o $(TARGET)-semi $(SOURCES) $(LDFLAGS_SEMI_STATIC)
# ============================================================================
# Custom Build System
# ============================================================================
# Custom build - flexible static/dynamic mixing
# Examples:
# make custom STATIC_LIBS="tcc ffi" DYNAMIC_LIBS="curl crypto"
# make custom STATIC_LIBS="all"
# make custom DYNAMIC_LIBS="all"
custom: check-deps-custom $(HEADERS)
@echo "π¨ Building custom version..."
@echo " Static libs: $(or $(STATIC_LIBS),none)"
@echo " Dynamic libs: $(or $(DYNAMIC_LIBS),default)"
$(CC) $(CFLAGS) -o $(TARGET)-custom $(SOURCES) $(call build_custom_ldflags)
@echo ""
@echo "β
Custom build complete!"
@echo " Binary: ./$(TARGET)-custom"
@ldd ./$(TARGET)-custom 2>/dev/null || echo " (fully static)"
@ls -lh ./$(TARGET)-custom
@echo ""
# Function to build custom LDFLAGS
define build_custom_ldflags
$(strip \
$(if $(findstring all,$(STATIC_LIBS)), \
$(LDFLAGS_STATIC), \
$(if $(STATIC_LIBS),-Wl,-Bstatic,) \
$(foreach lib,$(STATIC_LIBS),$(call get_static_lib,$(lib))) \
$(if $(STATIC_LIBS),-Wl,-Bdynamic,) \
) \
$(if $(findstring all,$(DYNAMIC_LIBS)), \
$(LDFLAGS_DYNAMIC), \
$(foreach lib,$(DYNAMIC_LIBS),$(call get_dynamic_lib,$(lib))) \
) \
$(if $(or $(STATIC_LIBS),$(DYNAMIC_LIBS)),,$(LDFLAGS_DYNAMIC)) \
$(LIBS_SYSTEM) \
)
endef
# Helper functions for custom builds
get_static_lib = $(if $(filter tcc,$(1)),$(LIBTCC_STATIC)) \
$(if $(filter ffi,$(1)),$(LIBFFI_STATIC)) \
$(if $(filter curl,$(1)),$(LIBCURL_STATIC))
get_dynamic_lib = $(if $(filter tcc,$(1)),$(LIBS_TCC)) \
$(if $(filter ffi,$(1)),$(LIBS_FFI)) \
$(if $(filter curl,$(1)),$(LIBS_CURL)) \
$(if $(filter crypto,$(1)),$(LIBS_CRYPTO))
# ============================================================================
# Optimized Builds
# ============================================================================
# Optimized dynamic build
optimized: CFLAGS += -O3 -march=native -flto
optimized: build
# Debug build
debug: CFLAGS += -g -O0 -DDEBUG
debug: build
# Release build (optimized + stripped)
release: CFLAGS += -O3 -march=native -flto -DNDEBUG
release: build
@strip $(TARGET)
@echo "βοΈ Stripped $(TARGET)"
# Static release (optimized + stripped)
static-release: CFLAGS += -O3 -march=native -flto -DNDEBUG
static-release: static
@strip $(TARGET)-static
@echo "βοΈ Stripped $(TARGET)-static"
# ============================================================================
# Dependency Management
# ============================================================================
# Complete setup - installs everything
setup: install-deps
@echo ""
@echo "π Setup complete! You can now build with:"
@echo " make build # Dynamic build"
@echo " make static # Static build"
@echo ""
# Install all dependencies
install-deps:
@echo "π¦ Installing all dependencies..."
@echo ""
$(MAKE) install-system-deps
$(MAKE) build-static-curl
@echo ""
@echo "β
All dependencies installed!"
# Install system packages only
install-system-deps:
@echo "π¦ Installing system dependencies..."
sudo apt-get update
sudo apt-get install -y \
tcc \
libtcc-dev \
libffi-dev \
libcurl4-openssl-dev \
libreadline-dev \
libssl-dev \
libzstd-dev \
build-essential \
wget \
pkg-config
@echo "β
System dependencies installed"
# Build static libcurl (for static builds)
build-static-curl:
@echo "π¦ Building static libcurl..."
@if [ -f "$(LIBCURL_STATIC_SYSTEM)" ]; then \
echo "β
Static libcurl already installed at $(LIBCURL_STATIC_SYSTEM)"; \
else \
echo "π¨ Building libcurl from source..."; \
$(MAKE) build-curl-from-source; \
fi
# Force rebuild of libcurl (if you have OpenSSL version issues)
rebuild-curl:
@echo "π Forcing rebuild of libcurl..."
@rm -rf build/curl-8.6.0
@sudo rm -f /usr/local/lib/libcurl.a /usr/local/lib/libcurl.la
@sudo rm -f /usr/local/lib/pkgconfig/libcurl.pc
$(MAKE) build-curl-from-source
@echo "β
libcurl rebuilt successfully"
# Build curl from source
build-curl-from-source:
@echo "π₯ Downloading curl source..."
@mkdir -p build
@cd build && \
if [ ! -f curl-8.6.0.tar.gz ]; then \
wget -q https://curl.se/download/curl-8.6.0.tar.gz; \
fi
@echo "π¦ Extracting and configuring..."
@cd build && \
tar xzf curl-8.6.0.tar.gz
@cd build/curl-8.6.0 && \
./configure --disable-shared --enable-static \
--with-openssl \
--without-gnutls --without-nss \
--without-libpsl --without-librtmp --without-libidn2 \
--without-brotli --without-zstd --without-nghttp2 \
--disable-ldap --disable-rtsp --disable-proxy \
--disable-telnet --disable-tftp --disable-gopher \
--disable-dict --disable-imap --disable-pop3 \
--disable-smtp --disable-manual \
--prefix=/usr/local \
> /dev/null 2>&1
@echo "π¨ Compiling libcurl (this may take a few minutes)..."
@cd build/curl-8.6.0 && $(MAKE) -j4 > /dev/null 2>&1
@echo "π¦ Installing libcurl system-wide..."
@cd build/curl-8.6.0 && sudo $(MAKE) install > /dev/null 2>&1
@sudo ldconfig
@echo "β
Static libcurl installed at /usr/local/lib/libcurl.a"
# Build curl without SSL (for problematic static builds)
build-curl-nossl:
@echo "π₯ Building curl without SSL (for static builds)..."
@mkdir -p build
@cd build && \
if [ ! -f curl-8.6.0.tar.gz ]; then \
wget -q https://curl.se/download/curl-8.6.0.tar.gz; \
fi
@cd build && \
rm -rf curl-8.6.0 && \
tar xzf curl-8.6.0.tar.gz
@cd build/curl-8.6.0 && \
./configure --disable-shared --enable-static \
--without-ssl \
--without-gnutls --without-nss \
--without-libpsl --without-librtmp --without-libidn2 \
--without-brotli --without-zstd --without-nghttp2 \
--disable-ldap --disable-rtsp --disable-proxy \
--disable-telnet --disable-tftp --disable-gopher \
--disable-dict --disable-imap --disable-pop3 \
--disable-smtp --disable-manual \
--prefix=/usr/local \
> /dev/null 2>&1
@echo "π¨ Compiling libcurl without SSL..."
@cd build/curl-8.6.0 && $(MAKE) -j4 > /dev/null 2>&1
@echo "π¦ Installing libcurl system-wide..."
@cd build/curl-8.6.0 && sudo $(MAKE) install > /dev/null 2>&1
@sudo ldconfig
@echo "β
Static libcurl (no SSL) installed"
@echo "β οΈ Note: HTTP only, no HTTPS support"
# Download stb_c_lexer.h
stb_c_lexer.h:
@echo "π₯ Downloading stb_c_lexer.h..."
@wget -q https://raw.githubusercontent.com/nothings/stb/master/stb_c_lexer.h
@echo "β
stb_c_lexer.h downloaded"
# Ensure static curl is available
ensure-static-curl:
@if [ ! -f "$(LIBCURL_STATIC)" ]; then \
echo "β Static libcurl not found at $(LIBCURL_STATIC)"; \
echo " Run: make build-static-curl"; \
exit 1; \
fi
# ============================================================================
# Dependency Checking
# ============================================================================
# Minimal check for dynamic builds
check-deps-minimal:
@echo "π Checking dependencies for dynamic build..."
@command -v $(CC) >/dev/null 2>&1 || (echo "β gcc not found"; exit 1)
@command -v tcc >/dev/null 2>&1 || (echo "β tcc not found (run: make install-system-deps)"; exit 1)
@pkg-config --exists libffi || (echo "β libffi not found (run: make install-system-deps)"; exit 1)
@pkg-config --exists libcurl || (echo "β libcurl not found (run: make install-system-deps)"; exit 1)
@echo "β
All dependencies available for dynamic build"
# Check for hybrid build
check-deps-hybrid: check-deps-minimal
@[ -f "$(LIBTCC_STATIC)" ] || (echo "β $(LIBTCC_STATIC) not found"; exit 1)
@[ -f "$(LIBFFI_STATIC)" ] || (echo "β $(LIBFFI_STATIC) not found"; exit 1)
@echo "β
All dependencies available for hybrid build"
# Check for static build
check-deps-static: check-deps-hybrid
@if [ ! -f "$(LIBCURL_STATIC)" ]; then \
echo "β Static libcurl not found"; \
echo " Building from source (this will take a few minutes)..."; \
$(MAKE) build-static-curl; \
fi
@echo "β
All dependencies available for static build"
# Check for custom build
check-deps-custom:
@echo "π Checking dependencies for custom build..."
@if echo "$(STATIC_LIBS)" | grep -q "tcc\|all"; then \
[ -f "$(LIBTCC_STATIC)" ] || (echo "β $(LIBTCC_STATIC) not found"; exit 1); \
fi
@if echo "$(STATIC_LIBS)" | grep -q "ffi\|all"; then \
[ -f "$(LIBFFI_STATIC)" ] || (echo "β $(LIBFFI_STATIC) not found"; exit 1); \
fi
@if echo "$(STATIC_LIBS)" | grep -q "curl\|all"; then \
[ -f "$(LIBCURL_STATIC)" ] || (echo "β $(LIBCURL_STATIC) not found, building..."; $(MAKE) build-static-curl); \
fi
@echo "β
Dependencies checked"
# Full dependency report
check-deps:
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo " Dependency Status Report"
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo ""
@echo "π¦ System Tools:"
@command -v $(CC) >/dev/null 2>&1 && echo " β
gcc" || echo " β gcc"
@command -v tcc >/dev/null 2>&1 && echo " β
tcc" || echo " β tcc"
@command -v wget >/dev/null 2>&1 && echo " β
wget" || echo " β wget"
@command -v pkg-config >/dev/null 2>&1 && echo " β
pkg-config" || echo " β pkg-config"
@echo ""
@echo "π Development Libraries:"
@[ -f /usr/include/libtcc.h ] && echo " β
libtcc-dev" || echo " β libtcc-dev"
@pkg-config --exists libffi && echo " β
libffi-dev" || echo " β libffi-dev"
@pkg-config --exists libcurl && echo " β
libcurl-dev" || echo " β libcurl-dev"
@pkg-config --exists openssl && echo " β
libssl-dev" || echo " β libssl-dev"
@echo ""
@echo "π¦ Static Libraries:"
@[ -f "$(LIBTCC_STATIC)" ] && echo " β
$(LIBTCC_STATIC)" || echo " β libtcc.a not found"
@[ -f "$(LIBFFI_STATIC)" ] && echo " β
$(LIBFFI_STATIC)" || echo " β libffi.a not found"
@[ -f "$(LIBCURL_STATIC_SYSTEM)" ] && echo " β
/usr/local/lib/libcurl.a (system)" || \
([ -f "$(LIBCURL_STATIC_LOCAL)" ] && echo " β
./build/curl-8.6.0/lib/.libs/libcurl.a (local)" || \
echo " β libcurl.a not found (run: make build-static-curl)")
@echo ""
@echo "π Required Headers:"
@[ -f stb_c_lexer.h ] && echo " β
stb_c_lexer.h" || echo " π₯ stb_c_lexer.h (will download)"
@[ -f enclib.h ] && echo " β
enclib.h" || echo " β enclib.h (required!)"
@[ -f netlib.h ] && echo " β
netlib.h" || echo " β netlib.h (required!)"
@echo ""
@echo "To install missing dependencies:"
@echo " make install-system-deps # Install system packages"
@echo " make build-static-curl # Build static libcurl"
@echo " make setup # Install everything"
@echo ""
# ============================================================================
# Utility Targets
# ============================================================================
# Clean build artifacts
clean:
@echo "π§Ή Cleaning build artifacts..."
@rm -f stb_c_lexer.h
@rm -f $(TARGET) $(TARGET)-static $(TARGET)-semi $(TARGET)-hybrid $(TARGET)-custom
@rm -f $(OBJECTS)
@rm -f *.o
@echo "β
Cleaned"
# Deep clean (including downloaded files)
distclean: clean
@echo "π§Ή Deep cleaning..."
@rm -rf build
@rm -f stb_c_lexer.h
@echo "β
Deep cleaned"
# Install to system
install: build
@echo "π¦ Installing to /usr/local/bin..."
@sudo install -m 755 $(TARGET) /usr/local/bin/
@echo "β
Installed: /usr/local/bin/$(TARGET)"
# Install static version
install-static: static
@echo "π¦ Installing static version to /usr/local/bin..."
@sudo install -m 755 $(TARGET)-static /usr/local/bin/$(TARGET)
@echo "β
Installed: /usr/local/bin/$(TARGET) (static)"
# Uninstall from system
uninstall:
@echo "ποΈ Uninstalling from /usr/local/bin..."
@sudo rm -f /usr/local/bin/$(TARGET)
@echo "β
Uninstalled"
# ============================================================================
# Information and Help
# ============================================================================
# Show build configuration
info:
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo " MalCREPL Build Configuration"
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo ""
@echo "π§ Compiler:"
@echo " CC: $(CC)"
@echo " CFLAGS: $(CFLAGS)"
@echo " Architecture: $(ARCH)"
@echo ""
@echo "π¦ Library Paths:"
@echo " LIBDIR: $(LIBDIR)"
@echo " TCC static: $(LIBTCC_STATIC)"
@echo " FFI static: $(LIBFFI_STATIC)"
@echo " CURL static: $(LIBCURL_STATIC) ($(CURL_SOURCE))"
@echo ""
@echo "π Linking Options:"
@echo " Dynamic: $(LDFLAGS_DYNAMIC)"
@echo ""
@echo "π Build Targets:"
@echo " build: Dynamic build (~30KB)"
@echo " static: Full static (~800KB)"
@echo " hybrid: Hybrid static (~200KB)"
@echo " custom: Custom (see help-custom)"
@echo ""
# Comprehensive help
help:
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo " MalCREPL - Complete Build System Help"
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo ""
@echo "π Setup & Installation:"
@echo " make setup - Complete setup (recommended)"
@echo " make install-system-deps - Install system packages only"
@echo " make build-static-curl - Build static libcurl"
@echo " make check-deps - Check all dependencies"
@echo ""
@echo "π¨ Build Targets:"
@echo " make build - Dynamic build (default)"
@echo " make all - Same as 'make build'"
@echo " make semi-static - Semi-static (TCC/FFI static, rest dynamic)"
@echo " make static - Full static build"
@echo " make hybrid - Hybrid static build"
@echo " make custom - Custom build (see help-custom)"
@echo ""
@echo "β‘ Optimized Builds:"
@echo " make optimized - Optimized dynamic"
@echo " make release - Optimized + stripped dynamic"
@echo " make static-release - Optimized + stripped static"
@echo " make debug - Debug build with symbols"
@echo ""
@echo "π¦ Installation:"
@echo " sudo make install - Install dynamic version"
@echo " sudo make install-static - Install static version"
@echo " sudo make uninstall - Remove from system"
@echo ""
@echo "π§Ή Cleanup:"
@echo " make clean - Remove build artifacts"
@echo " make distclean - Deep clean (includes downloads)"
@echo ""
@echo "π Information:"
@echo " make info - Show build configuration"
@echo " make help - This help message"
@echo " make help-custom - Custom build help"
@echo ""
@echo "π‘ Quick Examples:"
@echo " make && ./malcrepl test.c # Build and run"
@echo " make static && ./malcrepl-static test.c # Static build"
@echo " make custom STATIC_LIBS=\"tcc ffi\" # Custom build"
@echo ""
# Custom build help
help-custom:
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo " Custom Build System - Flexible Static/Dynamic Linking"
@echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
@echo ""
@echo "π― Purpose:"
@echo " Create builds with specific libraries linked statically or"
@echo " dynamically. Useful for balancing portability and size."
@echo ""
@echo "π Syntax:"
@echo " make custom STATIC_LIBS=\"lib1 lib2\" DYNAMIC_LIBS=\"lib3 lib4\""
@echo ""
@echo "π¦ Available Libraries:"
@echo " tcc - TinyCC compiler library"
@echo " ffi - Foreign Function Interface"
@echo " curl - HTTP/HTTPS client library"
@echo " crypto - OpenSSL cryptography"
@echo " all - All libraries (for STATIC_LIBS or DYNAMIC_LIBS)"
@echo ""
@echo "π‘ Examples:"
@echo ""
@echo " # TCC and FFI static, others dynamic"
@echo " make custom STATIC_LIBS=\"tcc ffi\" DYNAMIC_LIBS=\"curl crypto\""
@echo ""
@echo " # Everything static (same as 'make static')"
@echo " make custom STATIC_LIBS=\"all\""
@echo ""
@echo " # Everything dynamic (same as 'make build')"
@echo " make custom DYNAMIC_LIBS=\"all\""
@echo ""
@echo " # Only TCC static, rest dynamic"
@echo " make custom STATIC_LIBS=\"tcc\" DYNAMIC_LIBS=\"ffi curl crypto\""
@echo ""
@echo " # Curl static, others dynamic (for portability)"
@echo " make custom STATIC_LIBS=\"curl\" DYNAMIC_LIBS=\"tcc ffi crypto\""
@echo ""
@echo "π Comparison:"
@echo " Configuration Size Portability Use Case"
@echo " βββββββββββββββββββββ ββββββ βββββββββββ βββββββββββββββββ"
@echo " all dynamic ~30KB Low Development"
@echo " tcc+ffi static ~200KB Medium Docker containers"
@echo " all static ~800KB High Distribution"
@echo " custom varies varies Specific needs"
@echo ""
@echo "π Check Results:"
@echo " ldd ./malcrepl-custom # See dynamic dependencies"
@echo " ls -lh ./malcrepl-custom # Check binary size"
@echo " file ./malcrepl-custom # Check binary type"
@echo ""
# ============================================================================
# Special Targets
# ============================================================================
.PHONY: all build static semi-static hybrid custom optimized debug release static-release \
setup install-deps install-system-deps build-static-curl rebuild-curl \
build-curl-from-source ensure-static-curl \
check-deps check-deps-minimal check-deps-hybrid check-deps-static check-deps-custom \
clean distclean \
install install-static uninstall \
info help help-quick help-custom \
stb_c_lexer.h
# Prevent make from deleting intermediate files
.SECONDARY:
# Silent mode for cleaner output
ifndef VERBOSE
.SILENT:
endif