Retro68/prepare-headers.sh

148 lines
3.0 KiB
Bash
Raw Normal View History

IN=$1
OUT=$2
# Make Mac OS X's tr and sed not complain that the files are not UTF-8
export LANG=en
2015-09-12 22:42:07 +00:00
for file in $(cd $IN; ls *.h); do
2016-06-15 20:41:47 +00:00
# Filter by file names.
# Some CIncludes packages include the MPW standard library.
# Header files from that standard library would overwrite
# newlib header files and stop things from working.
case $file in
# Apple/MPW standard library internals
*Def.h|FSpio.h)
USE=false
;;
2016-06-15 20:41:47 +00:00
# whitelist all uppercase headers
[A-Z]*.h)
USE=true
;;
# whitelist OpenTransport
cred.h|dlpi.h|miioccom.h|mistream.h|modnames.h)
USE=true
;;
# whitelist OpenTransport (continued)
strlog.h|stropts.h|strstat.h|tihdr.h)
USE=true
;;
# Non-standard floating point headers that don't conflict
ddrt.h|fp.h)
USE=true
;;
2016-06-15 20:41:47 +00:00
# veclib headers
v*.h)
USE=true
;;
2016-06-15 20:41:47 +00:00
# unsupported: intrinsics.h perf.h
# all other (lowercase) headers: conflict with GCC or newlib headers
*)
2016-06-15 20:41:47 +00:00
USE=false
;;
esac
2016-06-15 20:41:47 +00:00
if [ $USE = true ]; then
tr '\r' '\n' < $IN/$file > $OUT/$file
fi
done
2015-09-12 22:42:07 +00:00
############################# ConditionalMacros.h #############################
cat > $OUT/ConditionalMacros.h <<END_MARKER
#ifndef __CONDITIONALMACROS__WRAP__
#define __CONDITIONALMACROS__WRAP__
2015-08-30 23:17:52 +00:00
#if #cpu(powerpc)
#define TARGET_CPU_PPC 1
#define TARGET_OS_MAC 1
#define TARGET_RT_MAC_CFM 1
#define TARGET_RT_MAC_MACHO 0
#else
#define TARGET_CPU_68K 1
#define TARGET_OS_MAC 1
#define TARGET_RT_MAC_CFM 0
#define TARGET_RT_MAC_MACHO 0
2015-08-30 23:17:52 +00:00
#endif
#define PRAGMA_STRUCT_PACKPUSH 1
#define FUNCTION_PASCAL 1
2015-08-30 23:17:52 +00:00
#define TYPE_LONGLONG 1
#ifdef __cplusplus
#define TYPE_BOOL 1
#endif
END_MARKER
tr '\r' '\n' < $IN/ConditionalMacros.h | sed 's/__GNUC__/__GNUC_DISABLED__/g' >> $OUT/ConditionalMacros.h
cat >> $OUT/ConditionalMacros.h <<END_MARKER
#endif /* __CONDITIONALMACROS__WRAP__ */
END_MARKER
2015-09-12 22:42:07 +00:00
############################# fp.h #############################
if [ -r $IN/fp.h ]; then
cat > $OUT/fp.h <<END_MARKER
#ifndef __FP__WRAP__
#define __FP__WRAP__
#include "math.h"
#pragma push_macro("__MWERKS__")
#define __MWERKS__ 0x6666
#define __cmath__
short relation(double x, double y);
END_MARKER
tr '\r' '\n' < $IN/fp.h >> $OUT/fp.h
cat >> $OUT/fp.h <<END_MARKER
#pragma pop_macro("__MWERKS__")
#undef __cmath__
#endif /* __FP__WRAP__ */
END_MARKER
fi
############################# MixedMode.h #############################
tr '\r' '\n' < $IN/MixedMode.h | sed 's/Opaque\#\#name\#\#\*/Opaque\#\#name \*/g' > $OUT/MixedMode.h
############################# CGBase.h #############################
if [ -r $IN/CGBase.h ]; then
cat > $OUT/CGBase.h <<END_MARKER
#ifndef __CGBASE__WRAP__
#define __CGBASE__WRAP__
#include "math.h"
/* CGBase contains a hardcoded #ifdef that decides that stdint.h is available in MWERKS > 0x2300.
... otherwise, it contains an incompatible redefinition. */
#pragma push_macro("__MWERKS__")
#define __MWERKS__ 0x6666
END_MARKER
tr '\r' '\n' < $IN/CGBase.h >> $OUT/CGBase.h
cat >> $OUT/CGBase.h <<END_MARKER
#pragma pop_macro("__MWERKS__")
#endif /* __CGBASE__WRAP__ */
END_MARKER
fi