ref: 8f553e89ce59944c085835b55e9d8f11283a5f63
parent: f2724df5662ed204e41660907ac49ead75f79f34
parent: 907ccfb28007b940577c0880e593dd396c2dea2f
author: Antonio Niño Díaz <[email protected]>
date: Tue Apr 25 09:29:09 EDT 2017
Merge pull request #176 from makefile-cleanup Cleanup Makefile Signed-off-by: Antonio Niño Díaz <[email protected]>
--- a/GNUmakefile
+++ /dev/null
@@ -1,6 +1,0 @@
-# GNU Make 3.x doesn't support the "!=" shell syntax, so here's an alternative
-
-PKG_CONFIG = pkg-config
-PNGFLAGS = $(shell ${PKG_CONFIG} --cflags libpng)
-
-include Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,25 +1,35 @@
-PKG_CONFIG = pkg-config
-WARNFLAGS = -Wall -Werror
-PNGFLAGS != ${PKG_CONFIG} --cflags libpng
-REALCFLAGS = ${CFLAGS} ${WARNFLAGS} ${PNGFLAGS} -Iinclude -g \
- -std=c99 -D_POSIX_C_SOURCE=200809L
+# User-defined variables
+Q := @
+PREFIX := /usr/local
+bindir := ${PREFIX}/bin
+mandir := ${PREFIX}/man
+STRIP := -s
+BINMODE := 555
+MANMODE := 444
+
+# Other variables
+
+PKG_CONFIG := pkg-config
+PNGCFLAGS := `${PKG_CONFIG} --static --cflags libpng`
+PNGLDFLAGS := `${PKG_CONFIG} --static --libs-only-L libpng`
+PNGLDLIBS := `${PKG_CONFIG} --static --libs-only-l libpng`
+
+WARNFLAGS := -Wall -Werror
+CFLAGS := ${WARNFLAGS} -g -std=c99 -D_POSIX_C_SOURCE=200809L -Iinclude
+
+YFLAGS :=
LFLAGS := --nounistd
YACC := yacc
-FLEX := flex
+LEX := flex
RM := rm -rf
-# User-defined variables
-PREFIX = /usr/local
-bindir = ${PREFIX}/bin
-mandir = ${PREFIX}/man
-Q = @
-STRIP = -s
-BINMODE = 555
-MANMODE = 444
+# Rules to build the RGBDS binaries
-rgbasm_obj = \
+all: rgbasm rgblink rgbfix rgbgfx
+
+rgbasm_obj := \
src/asm/asmy.o \
src/asm/charmap.o \
src/asm/fstack.o \
@@ -36,7 +46,10 @@
src/extern/strlcpy.o \
src/extern/strlcat.o
-rgblink_obj = \
+src/asm/asmy.h: src/asm/asmy.c
+src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
+
+rgblink_obj := \
src/link/assign.o \
src/link/lexer.o \
src/link/library.o \
@@ -50,18 +63,47 @@
src/link/symbol.o \
src/extern/err.o
-rgbfix_obj = \
+src/link/parser.h: src/link/parser.c
+src/link/lexer.o: src/link/parser.h
+
+rgbfix_obj := \
src/fix/main.o \
src/extern/err.o
-rgbgfx_obj = \
+rgbgfx_obj := \
src/gfx/gb.o \
src/gfx/main.o \
src/gfx/makepng.o \
src/extern/err.o
-all: rgbasm rgblink rgbfix rgbgfx
+rgbasm: ${rgbasm_obj}
+ $Q${CC} ${CFLAGS} -o $@ ${rgbasm_obj} -lm
+rgblink: ${rgblink_obj}
+ $Q${CC} ${CFLAGS} -o $@ ${rgblink_obj}
+
+rgbfix: ${rgbfix_obj}
+ $Q${CC} ${CFLAGS} -o $@ ${rgbfix_obj}
+
+rgbgfx: ${rgbgfx_obj}
+ $Q${CC} ${CFLAGS} ${PNGLDFLAGS} -o $@ ${rgbgfx_obj} ${PNGLDLIBS}
+
+# Rules to process files
+
+.y.c:
+ $Q${YACC} -d ${YFLAGS} -o $@ $<
+
+.l.o:
+ $Q${RM} $*.c
+ $Q${LEX} ${LFLAGS} -o $*.c $<
+ $Q${CC} ${CFLAGS} -c -o $@ $*.c
+ $Q${RM} $*.c
+
+.c.o:
+ $Q${CC} ${CFLAGS} ${PNGCFLAGS} -c -o $@ $<
+
+# Target used to remove all files generated by other Makefile targets.
+
clean:
$Q${RM} rgbds.7.html gbz80.7.html rgbds.5.html
$Q${RM} rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.1.html rgbasm.5.html
@@ -71,6 +113,8 @@
$Q${RM} src/asm/asmy.c src/asm/asmy.h
$Q${RM} src/link/lexer.c src/link/parser.c src/link/parser.h
+# Target used to install the binaries and man pages.
+
install: all
$Qmkdir -p ${DESTDIR}${bindir}
$Qinstall ${STRIP} -m ${BINMODE} rgbasm ${DESTDIR}${bindir}/rgbasm
@@ -88,63 +132,11 @@
$Qinstall -m ${MANMODE} src/link/rgblink.5 ${DESTDIR}${mandir}/man5/rgblink.5
$Qinstall -m ${MANMODE} src/gfx/rgbgfx.1 ${DESTDIR}${mandir}/man1/rgbgfx.1
-rgbasm: ${rgbasm_obj}
- $Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
-
-rgblink: ${rgblink_obj}
- $Q${CC} ${REALCFLAGS} -o $@ ${rgblink_obj}
-
-rgbfix: ${rgbfix_obj}
- $Q${CC} ${REALCFLAGS} -o $@ ${rgbfix_obj}
-
-rgbgfx: ${rgbgfx_obj}
- $Q${CC} ${REALCFLAGS} -o $@ ${rgbgfx_obj} `${PKG_CONFIG} --libs libpng`
-
-.y.c:
- $Q${YACC} -d ${YFLAGS} -o $@ $<
-
-.l.o:
- $Q${RM} $*.c
- $Q${FLEX} ${LFLAGS} -o $*.c $<
- $Q${CC} ${REALCFLAGS} -c -o $@ $*.c
- $Q${RM} $*.c
-
-.c.o:
- $Q${CC} ${REALCFLAGS} -c -o $@ $<
-
-src/asm/locallex.o src/asm/globlex.o src/asm/lexer.o: src/asm/asmy.h
-src/asm/asmy.h: src/asm/asmy.c
-
-src/link/lexer.o : src/link/parser.h
-src/link/parser.h : src/link/parser.c
-
-# Below is a target for the project maintainer to easily create win32 exes.
-# This is not for Windows users!
-# If you're building on Windows with Cygwin or Mingw, just follow the Unix
-# install instructions instead.
-mingw:
- $Q${RM} win32 win64
- $Qmkdir win32 win64
- $Qenv make clean
- $Qenv PKG_CONFIG_PATH=/usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
- make CC=i686-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
- $Qmv rgbasm win32/rgbasm.exe
- $Qmv rgblink win32/rgblink.exe
- $Qmv rgbfix win32/rgbfix.exe
- $Qmv rgbgfx win32/rgbgfx.exe
- $Qenv make clean
- $Qenv PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
- make CC=x86_64-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
- $Qmv rgbasm win64/rgbasm.exe
- $Qmv rgblink win64/rgblink.exe
- $Qmv rgbfix win64/rgbfix.exe
- $Qmv rgbgfx win64/rgbgfx.exe
- $Qenv make clean
-
-# Below is a target for the project maintainer to easily create web manuals.
+# Target for the project maintainer to easily create web manuals.
# It relies on mandoc: http://mdocml.bsd.lv
-MANDOC = -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=manual.css
+MANDOC := -Thtml -Ios=General -Oman=%N.%S.html -Ostyle=manual.css
+
wwwman:
$Qmandoc ${MANDOC} src/rgbds.7 > rgbds.7.html
$Qmandoc ${MANDOC} src/gbz80.7 > gbz80.7.html
@@ -155,3 +147,24 @@
$Qmandoc ${MANDOC} src/link/rgblink.1 > rgblink.1.html
$Qmandoc ${MANDOC} src/link/rgblink.5 > rgblink.5.html
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 > rgbgfx.1.html
+
+# Targets for the project maintainer to easily create Windows exes.
+# This is not for Windows users!
+# If you're building on Windows with Cygwin or Mingw, just follow the Unix
+# install instructions instead.
+
+mingw32:
+ $Qenv PKG_CONFIG_PATH=/usr/i686-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
+ make CC=i686-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
+ $Qmv rgbasm rgbasm.exe
+ $Qmv rgblink rgblink.exe
+ $Qmv rgbfix rgbfix.exe
+ $Qmv rgbgfx rgbgfx.exe
+
+mingw64:
+ $Qenv PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/ \
+ make CC=x86_64-w64-mingw32-gcc YACC=bison WARNFLAGS= -j
+ $Qmv rgbasm rgbasm.exe
+ $Qmv rgblink rgblink.exe
+ $Qmv rgbfix rgbfix.exe
+ $Qmv rgbgfx rgbgfx.exe