Makefile v0.2
authorken <ken@mihrtec.com>
Fri, 16 Dec 2016 05:36:19 +0000 (21:36 -0800)
committerken <ken@mihrtec.com>
Fri, 16 Dec 2016 05:36:19 +0000 (21:36 -0800)
Makefile
src/lexer.c
src/main.o [deleted file]

index d6689db..1bc47b8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,37 +5,55 @@
 ################################################################################
 # This makefile builds APC, the Asset Package Compiler for Henge, on the system.
 ################################################################################
-# Directories (can override with env vars)
-APC_ROOTDIR := $(if $(APC_ROOTDIR),$(APC_ROOTDIR),.)
-APC_SRCDIR  := $(if $(APC_SRCDIR),$(APC_SRCDIR),$(APC_ROOTDIR)/src)
+# Yacc
+YACC   := bison
+YFLAGS ?= -v -d -Wall
+YCMD    = $(YACC) $(YFLAGS) $<
+
+# Ragel
+RLC     ?= ragel
+RLFALGS ?= -C
+RLCMD    = $(RLC) $(RLFLAGS) -o $@ $<
+
+# C
+CC     ?= gcc
+CFLAGS ?= -Wall -Werror
+CCMD    = $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $<
+
+# Linker
+LD      ?= ld
+LDFLAGS ?= 
+LDLIBS  ?=
+LDCMD    = $(LD) $(LDFLAGS) $(LDLIBS) -o $@ $^
 
 # APC is built from Ragel, Bison and C source code only.
-ySRC  := $(shell find $(APC_SRCDIR) -type f -name '*.y')
-rlSRC := $(shell find $(APC_SRCDIR) -type f -name '*.rl')
-cSRC  := $(shell find $(APC_SRCDIR) -type f -name '*.c')
-
-# Specify the linker (allow env var override)
-LD    := $(if $(LD),$(LD),ld)
+ySRC  := $(shell find ./src -type f -name '*.y')
+rlSRC := $(shell find ./src -type f -name '*.rl')
+cSRC  := $(shell find ./src -type f -name '*.c')
 
 # Generated files from Yacc/Bison and Ragel
 hGEN  := $(ySRC:%.y=%.tab.h)
 cGEN  := $(strip $(ySRC:%.y=%.tab.c) $(rlSRC:%.rl=%.c))
 
+# Functions
+cGENDEP = $(if $(wildcard $1),$(subst src/,,$(filter-out $1 \ %:,$(shell $(CC) -MM -MG $1))),$(info fnf $1))
+ldFLAGS = $(strip $(LDFLAGS) $(LDLIBS) $(VA_ARGS))
+
 # Rules
-apc-d: $(patsubst %.c,%-d.o,$(cSRC) $(cGEN)) | $(hGEN)
-       $(LD) $(LDFLAGS) $(LDLIBS) $<
+apcSRC   := $(patsubst %.c,%.o,$(cSRC) $(cGEN))
+apc-dSRC := $(patsubst %.o,%-d.o,$(apcSRC))
+
+.SECONDEXPANSION:
+apc-d apc: $$($$@SRC) | $(hGEN)
+       $(strip $(LDCMD))
 
-apc: $(patsubst %.c,%.o,$(cSRC) $(cGEN)) | $(hGEN)
-       $(LD) $(LDFLAGS) $(LDLIBS) $<
+%-d.o: CFLAGS+= -Og -ggdb
+%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c)
+       $(strip $(CCMD))
 
 %.tab.h %.tab.c: %.y
-       bison -d $(YFLAGS) $<
-
-cFLAGS = $(strip $(CFLAGS) $(CPPFLAGS) $1 $2 $3 $4 $5 $6 $7 $8 $9)
-GENDEP = $(filter-out \ %:,$(shell $(CC) -MM -MG $1))
-.SECONDEXPANSION:
-%.o: %.c $$(call GENDEP,$$(dir $$@)%.c)
-       $(CC) $(call cFLAGS,-c,-o $@) $<
+       $(strip $(YCMD))
+       mv $(notdir $(<:%.y=%.tab.[ch])) $(dir $@)
 
-%-d.o: $$(call GENDEP,$$(dir $$@)%.c) $$(info [DEPS|$$@] $$(call GENDEP,$$(dir $$@)%.c)) 
-       $(CC) $(call cFLAGS,-c,-Og,-ggdb,-o $@) $<
+%.c: %.rl
+       $(strip $(RLCMD))
index b2bb535..1550db9 100644 (file)
@@ -28,7 +28,7 @@
 #include <dirent.h>
 
 /* Local */
-#include "src/parser.tab.h"
+#include "parser.tab.h"
 #ifndef DE_STACKSIZE
 #define DE_STACKSIZE 1024
 #endif
diff --git a/src/main.o b/src/main.o
deleted file mode 100644 (file)
index db32a98..0000000
Binary files a/src/main.o and /dev/null differ