wannesm / dtaidistance

Time series distances: Dynamic Time Warping (fast DTW implementation in C)
Other
1.08k stars 184 forks source link

sed: can't read s/^typedef when using make float #186

Closed tommedema closed 1 year ago

tommedema commented 1 year ago

Recently I started getting this on an ARM machine:

git clone https://github.com/wannesm/dtaidistance.git && cd dtaidistance
cd dtaidistance/jinja && make float

It errors out:

Generating: dtw_cc_omp.pyx
Changed: dtaidistancec_globals.jinja.pxd
python3 generate.py --seqt=float dtaidistancec_globals.pxd
Generating: dtaidistancec_globals.pxd
Changed: dtw_cc.jinja.pxd
python3 generate.py --seqt=float dtw_cc.pxd
Generating: dtw_cc.pxd
cp dtw_cc.pyx ../
cp dtw_cc_omp.pyx ../
cp dtaidistancec_globals.pxd ../
cp dtw_cc.pxd ../
Changed: ed_cc.jinja.pyx
python3 generate.py --seqt=float ed_cc.pyx
Generating: ed_cc.pyx
cp ed_cc.pyx ../
sed -i '' 's/^typedef .* seq_t;$/typedef double seq_t;/g' ../lib/DTAIDistanceC/DTAIDistanceC/dd_globals.h
sed: can't read s/^typedef .* seq_t;$/typedef double seq_t;/g: No such file or directory
make: *** [Makefile:27: generate] Error 2
tommedema commented 1 year ago

This is because the sed command has different syntax on MacOS vs Unix.

On MacOS the -i '' seems to be required where on Unix it should not be present for the command to work.

See also https://unix.stackexchange.com/questions/13711/differences-between-sed-on-mac-osx-and-other-standard-sed.

tommedema commented 1 year ago

I went ahead and changed -i '' to -i in the makefile, which resolves the issue.

Seems like there are two options to make this cross-OS compatible:

  1. use ed instead of sed
  2. use this hack: sed -i.bak 's/foo/bar/' file && rm file.bak
wannesm commented 1 year ago

I did indeed only consider macos for this. Thanks for the notification and suggestions. I added a few lines to the makefile to detect the OS to solve it. At one point I should look into adding autoconf or something similar to deal with all the platform dependent constraints :-)

wannesm commented 1 year ago

I removed the sed command and included changing this one line in the Python script that generates all the files. This way there is no platform dependent code anymore.