diff --git a/core/Dynamic.carp b/core/Dynamic.carp index e62b214ab..ff72b7efd 100644 --- a/core/Dynamic.carp +++ b/core/Dynamic.carp @@ -95,10 +95,10 @@ integers [`imod`](#imod).") ;; The following functions are not put into a module for now: (defndynamic add-cflag [flag] - (eval (list 'Project.config "cflag" flag))) + (Project.config "cflag" (cons flag (Project.get-config "cflag")))) (defndynamic add-lib [lib] - (eval (list 'Project.config "libflag" lib))) + (Project.config "libflag" (cons lib (Project.get-config "libflag")))) (defndynamic pkg-config [pkg flags] (Dynamic.String.concat (Dynamic.append diff --git a/core/Project.carp b/core/Project.carp index 8c465d14a..978089b39 100644 --- a/core/Project.carp +++ b/core/Project.carp @@ -13,3 +13,13 @@ Example usage: `(save-docs Int Float String)`") (defmacro save-docs [:rest modules] (eval (list 'save-docs-ex (list quote (collect-into modules array)) []))) + +(defmodule Project + (hidden append-flag) + (defndynamic append-flag [flag-set flag] + (Project.config flag-set (cons flag (Project.get-config flag-set)))) + + (defmacro append-cflag [flag] (Project.append-flag "cflag" flag)) + (defmacro append-libflag [flag] (Project.append-flag "libflag" flag)) + (defmacro append-pkgflag [flag] (Project.append-flag "pkgconfigflag" flag)) +) diff --git a/core/SDL_mixer.carp b/core/SDL_mixer.carp index cf139c9f8..d519e3ef6 100644 --- a/core/SDL_mixer.carp +++ b/core/SDL_mixer.carp @@ -1,6 +1,8 @@ (system-include "SDL2/SDL_mixer.h") (add-pkg "SDL2_mixer") -(Project.config "cflag" "-Wno-incompatible-pointer-types-discards-qualifiers") +(Project.config "cflag" + (cons "-Wno-incompatible-pointer-types-discards-qualifiers" + (Project.get-config "cflag"))) (register-type Mix_Chunk) (register-type Mix_Music) diff --git a/core/SDL_ttf.carp b/core/SDL_ttf.carp index dc46b2388..0ef1439af 100644 --- a/core/SDL_ttf.carp +++ b/core/SDL_ttf.carp @@ -1,6 +1,8 @@ (system-include "SDL2/SDL_ttf.h") (add-pkg "SDL2_ttf") -(Project.config "cflag" "-Wno-incompatible-pointer-types-discards-qualifiers") +(Project.config "cflag" + (cons "-Wno-incompatible-pointer-types-discards-qualifiers" + (Project.get-config "cflag"))) (register-type TTF_Font) diff --git a/scripts/carp.sh b/scripts/carp.sh index 6e90cf4a9..dcedc1f1c 100755 --- a/scripts/carp.sh +++ b/scripts/carp.sh @@ -10,4 +10,6 @@ then CARP="$CARP $BUILD_OPTS --" fi export CARP_DIR=`pwd` -$CARP $CARP_OPTS "$@" +# TODO: Temporary band-aid to make different versions of clang run tests OK when supported flag sets differ +EVAL='(Project.config "cflag" (cons "-Wno-unknown-warning-option" (Project.get-config "cflag")))' +$CARP --eval-preload "\'$EVAL\'" $CARP_OPTS "$@" diff --git a/src/Obj.hs b/src/Obj.hs index 1372fbfa6..9eba9e0de 100644 --- a/src/Obj.hs +++ b/src/Obj.hs @@ -218,6 +218,10 @@ isBool :: XObj -> Bool isBool (XObj (Bol _) _ _) = True isBool _ = False +isStr :: XObj -> Bool +isStr (XObj (Str _) _ _) = True +isStr _ = False + isExternalFunction :: XObj -> Bool isExternalFunction (XObj (Lst (XObj (External _) _ _ : _)) _ _) = True isExternalFunction _ = False diff --git a/src/ProjectConfig.hs b/src/ProjectConfig.hs index 473c4c811..ebeff9efd 100644 --- a/src/ProjectConfig.hs +++ b/src/ProjectConfig.hs @@ -1,9 +1,17 @@ -- | Defines a frontend for manipulating Project level data. module ProjectConfig (projectKeyMap) where +import Data.Either (rights) import Info import qualified Map import Obj + ( XObj(XObj), + Obj(Str, Lst, Bol), + unwrapStringXObj, + wrapString, + wrapList, + wrapArray, + isStr ) import Project import Util @@ -46,24 +54,15 @@ projectGetPreproc proj = -- | Get the project's C compiler flags. projectGetCFlags :: ProjectGetter projectGetCFlags proj = - let fs = projectPreproc proj + let fs = projectCFlags proj in wrapList (map wrapString fs) -- | Set the project's C compiler flags --- --- NOTE: This retains existing behavior in which one can only add one flag at --- a time and the flags are append only. A slightly more functional interface --- would take a list of flags as arguments; e.g. to add *one* flag: --- --- (Project.config "cflags" (cons "-my-flag" (Project.get-config "cflags"))) --- --- or to wipe the flags whole-cloth (e.g. for a different target) --- --- (Project.config "cflags" ("-my" "-new" "-flags")) --- --- likewise for flag removal etc. projectSetCFlags :: ProjectSetter -projectSetCFlags proj (XObj (Str f) _ _) = Right (proj {projectCFlags = addIfNotPresent f (projectCFlags proj)}) +projectSetCFlags proj (XObj (Lst flags) _ _) = + if not $ all isStr flags + then Left "can't use a non-string as a C compiler flag" + else Right proj {projectCFlags = rights $ map unwrapStringXObj flags} projectSetCFlags _ _ = Left "can't use a non-string as a C compiler flag" -- | Get the project's C compiler library flags. @@ -73,20 +72,11 @@ projectGetLibFlags proj = in wrapList (map wrapString ls) -- | Set the project's C compiler library flags --- --- NOTE: This retains existing behavior in which one can only add one flag at --- a time and the flags are append only. A slightly more functional interface --- would take a list of flags as arguments; e.g. to add *one* flag: --- --- (Project.config "libflags" (cons "-lmylib" (Project.get-config "libflags"))) --- --- or to wipe the flags whole-cloth (e.g. for a different target) --- --- (Project.config "libflags" ("-lmy" "-lnew" "-llibflags")) --- --- likewise for flag removal etc. projectSetLibFlags :: ProjectSetter -projectSetLibFlags proj (XObj (Str flag) _ _) = Right (proj {projectLibFlags = addIfNotPresent flag (projectLibFlags proj)}) +projectSetLibFlags proj (XObj (Lst flags) _ _) = + if not $ all isStr flags + then Left "can't use a non-string as a C compiler library flag" + else Right proj {projectLibFlags = rights $ map unwrapStringXObj flags} projectSetLibFlags _ _ = Left "can't use non-string as library flag" -- | Get the pkg-config flags for the project. @@ -96,21 +86,11 @@ projectGetPkgConfigFlags proj = in wrapArray (map wrapString fs) -- | Set the project's pkg-config flags --- --- NOTE: This retains existing behavior in which one can only add one flag at --- a time and the flags are append only. A slightly more functional interface --- would take a list of flags as arguments; e.g. to add *one* flag: --- --- (Project.config "pkgconfigflags" (cons "-lmylib" (Project.get-config --- "pkgconfigflags"))) --- --- or to wipe the flags whole-cloth (e.g. for a different target) --- --- (Project.config "pkgconfigflags" ("-lmy" "-lnew" "-llibflags")) --- --- likewise for flag removal etc. projectSetPkgConfigFlags :: ProjectSetter -projectSetPkgConfigFlags proj (XObj (Str flag) _ _) = Right (proj {projectPkgConfigFlags = addIfNotPresent flag (projectPkgConfigFlags proj)}) +projectSetPkgConfigFlags proj (XObj (Lst flags) _ _) = + if not $ all isStr flags + then Left "can't use a non-string as a C compiler library flag" + else Right proj {projectPkgConfigFlags = rights $ map unwrapStringXObj flags} projectSetPkgConfigFlags _ _ = Left "can't use non-string as pkg-config flag" projectGetEchoC :: ProjectGetter