#!/usr/bin/env make
#
# IOCCC 2013 winning entry - cable3

################################################################################
#
# IOCCC winning entry code may not work on your system.  What was liked/allowed
# and worked in the past may no longer be liked/allowed or compile/run today.
#
# Bug fixes, corrections and typo fixes are VERY WELCOME.  If you see a problem,
# first check this URL for a list of known bugs and (mis)features of IOCCC entries:
#
#	https://www.ioccc.org/bugs.html
#
# GitHub pull requests are welcome!  Please see the above URL for details.
#
################################################################################
#
# This file is Copyright (c) 2023,2026 by Landon Curt Noll.  All Rights Reserved.
# You are free to share and adapt this file under the terms of this license:
#
#	Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
#
# For more information, see: https://creativecommons.org/licenses/by-sa/4.0/


#############################
# shell used by this Makefile
#############################
#
SHELL= bash

#######################
# common tool locations
#######################
#
include ../var.mk

# Common C compiler warnings to silence
#
CSILENCE= -Wno-bitwise-op-parentheses -Wno-bool-operation \
	  -Wno-conditional-type-mismatch -Wno-error \
	  -Wno-implicit-function-declaration -Wno-implicit-int \
	  -Wno-incompatible-pointer-types -Wno-logical-not-parentheses \
	  -Wno-logical-op-parentheses -Wno-parentheses \
	  -Wno-shift-op-parentheses -Wno-sign-compare -Wno-unsequenced \
	  -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-return-type \
	  -Wno-pointer-type-mismatch -Wno-int-conversion -Wno-unused-value \
	  -Wno-int-in-bool-context -Wno-sequence-point -Wno-strict-aliasing

# Attempt to silence unknown warning option
#
CUNKNOWN= -Wno-unknown-warning-option

# Common C compiler warning flags
#
CWARN= -Wall -Wextra ${CSILENCE} ${CUNKNOWN}

# Compiler standard
#
CSTD= -std=gnu11

# Compiler bit architecture
#
ARCH=

# Defines that are needed to compile
#
CDEFINE= -DKB='(kb=read(H(8),r+1190,1))&&H(7)'

# Include files that are needed to compile
#
CINCLUDE= `${SDL1_CONFIG} --cflags`

# Optimization
#
OPT= -O3

# Default flags for ANSI C compilation
#
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}

# Libraries needed to build
#
LDFLAGS= `${SDL1_CONFIG} --libs`

# C compiler to use
#
CC= cc

# Compiler add-ons or replacements for clang only
#
ifeq "$(findstring $(CLANG),${CC})" "$(CLANG)"
#
CSILENCE+= -Wno-cast-align -Wno-comma -Wno-dollar-in-identifier-extension \
	   -Wno-implicit-int-conversion -Wno-missing-prototypes \
	   -Wno-missing-variable-declarations -Wno-padded -Wno-pedantic \
	   -Wno-poison-system-directories -Wno-shadow -Wno-sign-conversion \
	   -Wno-strict-prototypes -Wno-shorten-64-to-32 \
	   -Wno-cast-function-type-strict -Wno-reserved-identifier \
	   -Wno-reserved-macro-identifier -Wno-unsafe-buffer-usage
#
CWARN+= -Weverything
#
endif

# Specific add-ons or replacements for gcc only
#
ifeq "$(findstring $(GCC),${CC})" "$(GCC)"
#
#CSILENCE+=
#
#CWARN+=
#
endif


##############################
# Special Makefile variables for this entry
##############################
#
ENTRY= cable3
PROG= ${ENTRY}
#
OBJ= ${PROG}.o
DATA= bios fd.img cable3.sh sc-ioccc.terminal screenshot_autocad.png \
	screenshot_flightsim4.png screenshot_lotus123.png screenshot_qbasic.png \
	screenshot_simcity.png screenshot_win3.png
TARGET= ${PROG}
#
ALT_OBJ= ${PROG}.alt.o
ALT_TARGET= ${PROG}.alt


#################
# build the entry
#################
#
all: data ${TARGET}
	@${TRUE}

.PHONY: all alt data everything clean clobber

${PROG}: ${PROG}.c
	${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}

# alternative executable
#
alt: data ${ALT_TARGET}
	@${TRUE}

${PROG}.alt: ${PROG}.alt.c
	@echo "NOTE: Lack of the kbhit() function will prevent compiling $@"
	${CC} ${CFLAGS} -UKB --include curses.h $< -o $@ ${LDFLAGS} -lcurses

# data files
#
data: ${DATA}
	@${TRUE}

# both all and alt
#
everything: all alt
	@${TRUE}


###############
# utility rules
###############
#
clean:
	${RM} -f ${OBJ} ${ALT_OBJ}

clobber: clean
	${RM} -f ${TARGET} ${ALT_TARGET}
	${RM} -rf *.dSYM


######################################
# optional include of 1337 hacker rulz
######################################

-include ../1337.mk
